From a99229733c365ba326337eae1d81d1c2f38793f5 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Sun, 2 Jan 2022 01:28:45 -0700 Subject: [PATCH] disable xp --- commands/leveling/ignorexp.js | 49 +++++++++++++++++++++++++++++++++++ commands/misc/ingorear.js | 2 +- events/messageCreate.js | 5 ++-- 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 commands/leveling/ignorexp.js diff --git a/commands/leveling/ignorexp.js b/commands/leveling/ignorexp.js new file mode 100644 index 0000000..28c173a --- /dev/null +++ b/commands/leveling/ignorexp.js @@ -0,0 +1,49 @@ +const Discord = require('discord.js'); + +const LXP = require('../../models/localxp'); +const GuildData = require('../../models/guild'); + +module.exports = { + name: "ignorexp", + aliases: ['xpignore', 'noxp'], + meta: { + category: 'Leveling', + description: "Stop XP from being gained in a specific channel.", + syntax: '`ignorexp [#channel|channelId]`', + extra: null, + guildOnly: true + }, + help: new Discord.MessageEmbed() + .setTitle("Help -> AR Ignoring") + .setDescription("Provide a channel (or don't to use the current channel) to be voided from auto-responses, that way the responses won't send in places you don't want them to.") + .addField("Syntax", "`[#channel|channelId]` - channel is optional."), + async execute(message, msg, args, cmd, prefix, mention, client) { + const tg = await GuildData.findOne({gid: message.guild.id}); + if ((!tg || !tg.staffrole || !tg.staffrole.length || !message.member.roles.cache.has(tg.staffrole)) && !message.member.permissions.has("ADMINISTRATOR")) {return message.channel.send("You must have the staff role or be an administrator in this server in order to edit XP settings.");} + + let txp = await LXP.findOne({gid: message.guild.id}); + if (!txp) {return message.channel.send("This server doesn't have XP enabled.");} + + let ch; + if (args[1]) { + ch = message.mentions.channels.first() || message.guild.channels.cache.get(args[1]); + if (!ch) {return message.channel.send("I couldn't find that channel. Please try again!");} + } else {ch = message.channel;} + ch = ch.id; + if (!txp.noGains) {txp.noGains = [];} + if (txp.noGains.includes(ch)) { + let ti = txp.noGains; + ti.splice(ti.indexOf(ch), 1); + txp.noGains = ti; + txp.markModified('noGains'); + txp.save(); + client.misc.cache.lxp.disabledChannels.set(message.guild.id, txp.noGains); + return message.channel.send("Got it. I'll start giving people XP here from now on."); + } else { + txp.noGains.push(ch); + txp.save(); + client.misc.cache.lxp.disabledChannels.set(message.guild.id, txp.noGains); + return message.channel.send("I'll stop giving people XP in this channel from now on."); + } + } +}; \ No newline at end of file diff --git a/commands/misc/ingorear.js b/commands/misc/ingorear.js index a9e854f..b8d4f30 100644 --- a/commands/misc/ingorear.js +++ b/commands/misc/ingorear.js @@ -19,7 +19,7 @@ module.exports = { .addField("Syntax", "`[#channel|channelId]` - channel is optional."), async execute(message, msg, args, cmd, prefix, mention, client) { const tg = await GuildData.findOne({gid: message.guild.id}); - if ((!tg || !tg.staffrole || !tg.staffrole.length || !message.member.roles.cache.has(tg.staffrole) && !message.member.permissions.has("ADMINISTRATOR"))) {return message.channel.send("You must have the staff role or be an administrator in this server in order to edit AR settings.");} + if ((!tg || !tg.staffrole || !tg.staffrole.length || !message.member.roles.cache.has(tg.staffrole)) && !message.member.permissions.has("ADMINISTRATOR")) {return message.channel.send("You must have the staff role or be an administrator in this server in order to edit AR settings.");} let tar = await AR.findOne({gid: message.guild.id}); if (!tar || !tar.triggers.length) {return message.channel.send("This server doesn't have any auto-responses. Try adding some first, then you can set some channels to be ignored.");} diff --git a/events/messageCreate.js b/events/messageCreate.js index 92686fa..f43f499 100644 --- a/events/messageCreate.js +++ b/events/messageCreate.js @@ -60,7 +60,7 @@ module.exports = async (client, message) => { } if (message.guild && client.misc.cache.lxp.enabled.includes(message.guild.id)) { - if (!client.misc.cache.lxp.disabledMessages.has(message.guild.id) || !client.misc.cache.lxp.disabledMessage.get(message.guild.id).includes(message.channel.id)) { + if (!client.misc.cache.lxp.disabledChannels.has(message.guild.id) || !client.misc.cache.lxp.disabledChannels.get(message.guild.id).includes(message.channel.id)) { if (!client.misc.cache.lxp.xp[message.guild.id]) {client.misc.cache.lxp.xp[message.guild.id] = {};} if (!client.misc.cache.lxp.xp[message.guild.id][message.author.id]) { LXP.findOne({gid: message.guild.id}).then(xp => { @@ -69,9 +69,10 @@ module.exports = async (client, message) => { level: xp.xp[message.author.id] ? xp.xp[message.author.id][1] : 1, lastXP: new Date().getTime() - 60000 }; + require('../util/lxp/gainxp')(client, message.member.id, message.channel); }); } - if (new Date().getTime() - client.misc.cache.lxp.xp[message.guild.id][message.author.id].lastXP > 60000) { + else if (new Date().getTime() - client.misc.cache.lxp.xp[message.guild.id][message.author.id].lastXP > 60000) { require('../util/lxp/gainxp')(client, message.member.id, message.channel); } }