From 2e6d41e76b77f77fd9dbb225cb9feee4b80f97fb Mon Sep 17 00:00:00 2001 From: ION606 Date: Fri, 13 May 2022 22:29:54 +0300 Subject: [PATCH] Changed the file structure to make the command reading process clearer and improve organization --- commands/{ => misc}/EC.js | 0 commands/{ => misc}/arrow.js | 0 commands/{ => misc}/commandhelp.js | 0 commands/{ => misc}/econ.js | 0 commands/{ => misc}/em.mp3 | Bin commands/{ => misc}/hello_world.js | 0 commands/{ => misc}/kareoke.js | 0 commands/{ => misc}/links.js | 0 commands/{ => misc}/playAudio.js | 0 commands/{ => misc}/postProfile.js | 0 commands/{ => misc}/quotes.js | 0 commands/{ => misc}/reactions.js | 0 commands/{ => misc}/scraper.js | 0 main.js | 51 ++++++++--------------------- 14 files changed, 13 insertions(+), 38 deletions(-) rename commands/{ => misc}/EC.js (100%) rename commands/{ => misc}/arrow.js (100%) rename commands/{ => misc}/commandhelp.js (100%) rename commands/{ => misc}/econ.js (100%) rename commands/{ => misc}/em.mp3 (100%) rename commands/{ => misc}/hello_world.js (100%) rename commands/{ => misc}/kareoke.js (100%) rename commands/{ => misc}/links.js (100%) rename commands/{ => misc}/playAudio.js (100%) rename commands/{ => misc}/postProfile.js (100%) rename commands/{ => misc}/quotes.js (100%) rename commands/{ => misc}/reactions.js (100%) rename commands/{ => misc}/scraper.js (100%) diff --git a/commands/EC.js b/commands/misc/EC.js similarity index 100% rename from commands/EC.js rename to commands/misc/EC.js diff --git a/commands/arrow.js b/commands/misc/arrow.js similarity index 100% rename from commands/arrow.js rename to commands/misc/arrow.js diff --git a/commands/commandhelp.js b/commands/misc/commandhelp.js similarity index 100% rename from commands/commandhelp.js rename to commands/misc/commandhelp.js diff --git a/commands/econ.js b/commands/misc/econ.js similarity index 100% rename from commands/econ.js rename to commands/misc/econ.js diff --git a/commands/em.mp3 b/commands/misc/em.mp3 similarity index 100% rename from commands/em.mp3 rename to commands/misc/em.mp3 diff --git a/commands/hello_world.js b/commands/misc/hello_world.js similarity index 100% rename from commands/hello_world.js rename to commands/misc/hello_world.js diff --git a/commands/kareoke.js b/commands/misc/kareoke.js similarity index 100% rename from commands/kareoke.js rename to commands/misc/kareoke.js diff --git a/commands/links.js b/commands/misc/links.js similarity index 100% rename from commands/links.js rename to commands/misc/links.js diff --git a/commands/playAudio.js b/commands/misc/playAudio.js similarity index 100% rename from commands/playAudio.js rename to commands/misc/playAudio.js diff --git a/commands/postProfile.js b/commands/misc/postProfile.js similarity index 100% rename from commands/postProfile.js rename to commands/misc/postProfile.js diff --git a/commands/quotes.js b/commands/misc/quotes.js similarity index 100% rename from commands/quotes.js rename to commands/misc/quotes.js diff --git a/commands/reactions.js b/commands/misc/reactions.js similarity index 100% rename from commands/reactions.js rename to commands/misc/reactions.js diff --git a/commands/scraper.js b/commands/misc/scraper.js similarity index 100% rename from commands/scraper.js rename to commands/misc/scraper.js diff --git a/main.js b/main.js index eb06404..af34231 100644 --- a/main.js +++ b/main.js @@ -44,39 +44,25 @@ bot.on("guildCreate", guild => { bot.commands = new Discord.Collection(); -bot.commNames = new Discord.Collection(); - -bot.econ = new Discord.Collection(); - -bot.anime = new Discord.Collection(); - const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js')); - -let i = 0; -for (const file of commandFiles) { - const command = require(`./commands/${file}`); - - bot.commands.set(command.name, command); - bot.commNames.set(i, [command.name, command.description]); - i ++; -} - -//Anime/manga section -const afiles = fs.readdirSync('./commands/anime').filter(file => file.endsWith('.js')); -for (const file of afiles) { - const command = require(`./commands/anime/${file}`); - bot.anime.set(command.name, command); -} +bot.commands = new Discord.Collection(); +fs.readdirSync('./commands') + .forEach(dir => { + fs.readdirSync(`./commands/${dir}`) + .filter(file => file.endsWith('.js')) + .forEach(file => { + const command = require(`./commands/${dir}/${file}`); + bot.commands.set(command.name, command); + }); + }); // const econFiles = fs.readdirSync('./commands/inventory').filter(file => file.endsWith('.js'));; // const currency = new Discord.Collection(); // const { Users } = require('./commands/currency/dbObjects.js'); // i++; -bot.commNames.set('length', i); - //XP Table section let xp_collection = new Map(); let items; @@ -122,21 +108,10 @@ bot.on('messageCreate', (message) => { //Check if the user has sufficient permission //Performes the command - //Anime uses if/else, all else uses switch (can't make a multi-case case) - if (command.indexOf('anime') != -1) { - console.log("Anime"); - bot.anime.get(command).execute(message, args); - switch(command) { - case 'top_anime': bot.anime.get('top_anime').execute(message, args); - } - } else if (command.indexOf('MANGA') != -1) { - console.log("Manga"); - //Do nothing for now - } else { - if(bot.commands.has(command)) { bot.commands.get(command).execute(message, args, Discord, Client, bot); } - else { bot.commands.get('ECON').execute(bot, message, args, command, Discord, mongouri, items, xp_collection); } - } + if(bot.commands.has(command)) { bot.commands.get(command).execute(message, args, Discord, Client, bot); } + + else { bot.commands.get('ECON').execute(bot, message, args, command, Discord, mongouri, items, xp_collection); } }) //Look into integrating MySQL into SelmerBot instead of SQLite