From 75be73d63c43a60d0031905147b073e3664fddcb Mon Sep 17 00:00:00 2001 From: rhearmas <34490428+qu-ota@users.noreply.github.com> Date: Mon, 23 Dec 2019 20:21:37 -0500 Subject: [PATCH] i did a lot and i'm too lazy to comment each commit lol --- events/guildCreate.js | 2 -- events/guildDelete.js | 2 -- events/guildMemberAdd.js | 11 +--------- events/message.js | 30 ++-------------------------- modules/Logger.js | 3 --- modules/functions.js | 43 ++-------------------------------------- 6 files changed, 5 insertions(+), 86 deletions(-) diff --git a/events/guildCreate.js b/events/guildCreate.js index c133186..ec3c65e 100644 --- a/events/guildCreate.js +++ b/events/guildCreate.js @@ -1,5 +1,3 @@ -// This event executes when a new guild (server) is joined. - module.exports = (client, guild) => { client.logger.cmd(`[GUILD JOIN] ${guild.name} (${guild.id}) added the bot. Owner: ${guild.owner.user.tag} (${guild.owner.user.id})`); }; diff --git a/events/guildDelete.js b/events/guildDelete.js index b1f0fa8..7ad772e 100644 --- a/events/guildDelete.js +++ b/events/guildDelete.js @@ -1,5 +1,3 @@ -// This event executes when a new guild (server) is left. - module.exports = (client, guild) => { client.logger.cmd(`[GUILD LEAVE] ${guild.name} (${guild.id}) removed the bot.`); diff --git a/events/guildMemberAdd.js b/events/guildMemberAdd.js index 137ded7..f8ed52e 100644 --- a/events/guildMemberAdd.js +++ b/events/guildMemberAdd.js @@ -1,16 +1,7 @@ -// This event executes when a new member joins a server. Let's welcome them! - module.exports = (client, member) => { - // Load the guild's settings const settings = client.getSettings(member.guild); - - // If welcome is off, don't proceed (don't welcome the user) if (settings.welcomeEnabled !== "true") return; - - // Replace the placeholders in the welcome message with actual data + const welcomeMessage = settings.welcomeMessage.replace("{{user}}", member.user.tag); - - // Send the welcome message to the welcome channel - // There's a place for more configs here. member.guild.channels.find(c => c.name === settings.welcomeChannel).send(welcomeMessage).catch(console.error); }; diff --git a/events/message.js b/events/message.js index 67398a9..e86d4bc 100644 --- a/events/message.js +++ b/events/message.js @@ -1,70 +1,44 @@ -// The MESSAGE event runs anytime a message is received -// Note that due to the binding of client to every event, every event -// goes `client, other, args` when this function is run. - module.exports = async (client, message) => { - // It's good practice to ignore other bots. This also makes your bot ignore itself - // and not get into a spam loop (we call that "botception"). if (message.author.bot) return; - // Grab the settings for this server from Enmap. - // If there is no guild, get default conf (DMs) const settings = message.settings = client.getSettings(message.guild); - // Checks if the bot was mentioned, with no message after it, returns the prefix. const prefixMention = new RegExp(`^<@!?${client.user.id}>( |)$`); if (message.content.match(prefixMention)) { return message.reply(`My prefix on this guild is \`${settings.prefix}\``); } - // Also good practice to ignore any message that does not start with our prefix, - // which is set in the configuration file. if (message.content.indexOf(settings.prefix) !== 0) return; - // Here we separate our "command" name, and our "arguments" for the command. - // e.g. if we have the message "+say Is this the real life?" , we'll get the following: - // command = say - // args = ["Is", "this", "the", "real", "life?"] const args = message.content.slice(settings.prefix.length).trim().split(/ +/g); const command = args.shift().toLowerCase(); - // If the member on a guild is invisible or not cached, fetch them. if (message.guild && !message.member) await message.guild.fetchMember(message.author); - // Get the user or member's permission level from the elevation const level = client.permlevel(message); - // Check whether the command, or alias, exist in the collections defined - // in app.js. const cmd = client.commands.get(command) || client.commands.get(client.aliases.get(command)); - // using this const varName = thing OR otherthign; is a pretty efficient - // and clean way to grab one of 2 values! if (!cmd) return; - // Some commands may not be useable in DMs. This check prevents those commands from running - // and return a friendly error message. if (cmd && !message.guild && cmd.conf.guildOnly) return message.channel.send("This command is unavailable via private message. Please run this command in a guild."); if (level < client.levelCache[cmd.conf.permLevel]) { if (settings.systemNotice === "true") { return message.channel.send(`You do not have permission to use this command. - Your permission level is ${level} (${client.config.permLevels.find(l => l.level === level).name}) - This command requires level ${client.levelCache[cmd.conf.permLevel]} (${cmd.conf.permLevel})`); + Your permission level is **${level}** (${client.config.permLevels.find(l => l.level === level).name}) + This command requires level **${client.levelCache[cmd.conf.permLevel]}** (${cmd.conf.permLevel})`); } else { return; } } - // To simplify message arguments, the author's level is now put on level (not member so it is supported in DMs) - // The "level" command module argument will be deprecated in the future. message.author.permLevel = level; message.flags = []; while (args[0] && args[0][0] === "-") { message.flags.push(args.shift().slice(1)); } - // If the command exists, **AND** the user has permission, run it. client.logger.cmd(`[CMD] ${client.config.permLevels.find(l => l.level === level).name} ${message.author.username} (${message.author.id}) ran command ${cmd.help.name}`); cmd.run(client, message, args, level); }; diff --git a/modules/Logger.js b/modules/Logger.js index 2d832ed..1ebc065 100644 --- a/modules/Logger.js +++ b/modules/Logger.js @@ -1,6 +1,3 @@ -/* -Logger class for easy and aesthetically pleasing console logging -*/ const chalk = require("chalk"); const moment = require("moment"); diff --git a/modules/functions.js b/modules/functions.js index 7bc537b..eb07a3d 100644 --- a/modules/functions.js +++ b/modules/functions.js @@ -78,7 +78,7 @@ module.exports = (client) => { } }; - client.unloadCommand = async (commandName) => { + client.unloadCommand = async (commandName) => { let command; if (client.commands.has(commandName)) { command = client.commands.get(commandName); @@ -99,46 +99,7 @@ module.exports = (client) => { } } return false; - }; - - client.reloadCommand = async(commandName) => { - // step 1: unload the command - let command; - if (client.commands.has(commandName)) { - command = client.commands.get(commandName); - } else if (client.aliases.has(commandName)) { - command = client.commands.get(client.aliases.get(commandName)); - } - if (!command) return `The command \`${commandName}\` doesn\'t seem to exist, nor is it an alias. Try again!`; - - if (command.shutdown) { - await command.shutdown(client); - } - const mod = require.cache[require.resolve(`../commands/${command.help.category}/${commandName}.js`)]; - delete require.cache[require.resolve(`../commands/${command.help.category}/${commandName}.js`)]; - for (let i = 0; i < mod.parent.children.length; i++) { - if (mod.parent.children[i] === mod) { - mod.parent.children.splice(i, 1); - break; - } - } - return false; - - // step 2: load said command - try { - const props = require(`../commands/${command.help.category}/${command.Name}`); - if (props.init) { - props.init(client); - } - client.commands.set(props.help.name, props); - props.conf.aliases.forEach(alias => { - client.aliases.set(alias, props.help.name); - }); - return false; - } catch (e) { - return `Unable to load command ${commandName}: ${e}`; - } - } + }; Object.defineProperty(String.prototype, "toProperCase", { value: function() {