Converted multiple functions to ES6 syntax, moved from collections to maps for storing commands
This commit is contained in:
		
							parent
							
								
									1da0d24602
								
							
						
					
					
						commit
						02df085580
					
				
					 8 changed files with 28 additions and 32 deletions
				
			
		| 
						 | 
					@ -1,14 +1,10 @@
 | 
				
			||||||
const misc = require("../utils/misc.js");
 | 
					const misc = require("../utils/misc.js");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.run = async (message, args) => {
 | 
					exports.run = async (message, args) => {
 | 
				
			||||||
  if (args.length === 0) {
 | 
					  if (args.length === 0 || !args[0].match(/^\d+$/)) {
 | 
				
			||||||
    return `🎲 The dice landed on ${misc.random(Array.from(Array(6).keys())) + 1}.`;
 | 
					    return `🎲 The dice landed on ${misc.random([...Array(6).keys()]) + 1}.`;
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
    if (args[0].match(/^\d+$/)) {
 | 
					    return `🎲 The dice landed on ${misc.random([...Array(parseInt(args[0])).keys()]) + 1}.`;
 | 
				
			||||||
      return `🎲 The dice landed on ${misc.random(Array.from(Array(parseInt(args[0])).keys())) + 1}.`;
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
      return `🎲 The dice landed on ${misc.random(Array.from(Array(6).keys())) + 1}.`;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,17 +7,17 @@ const tips = ["You can change the bot's prefix using the prefix command.", "Imag
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.run = async (message, args) => {
 | 
					exports.run = async (message, args) => {
 | 
				
			||||||
  const guild = (await database.guilds.find({ id: message.channel.guild.id }).exec())[0];
 | 
					  const guild = (await database.guilds.find({ id: message.channel.guild.id }).exec())[0];
 | 
				
			||||||
  const commands = Array.from(collections.commands.keys());
 | 
					  const commands = collections.commands;
 | 
				
			||||||
  const aliases = Array.from(collections.aliases.keys());
 | 
					  const aliases = collections.aliases;
 | 
				
			||||||
  if (args.length !== 0 && (commands.includes(args[0].toLowerCase()) || aliases.includes(args[0].toLowerCase()))) {
 | 
					  if (args.length !== 0 && (commands.has(args[0].toLowerCase()) || aliases.has(args[0].toLowerCase()))) {
 | 
				
			||||||
    const info = aliases.includes(args[0].toLowerCase()) ? collections.info.get(collections.aliases.get(args[0].toLowerCase())) : collections.info.get(args[0].toLowerCase());
 | 
					    const info = aliases.has(args[0].toLowerCase()) ? collections.info.get(collections.aliases.get(args[0].toLowerCase())) : collections.info.get(args[0].toLowerCase());
 | 
				
			||||||
    const embed = {
 | 
					    const embed = {
 | 
				
			||||||
      "embed": {
 | 
					      "embed": {
 | 
				
			||||||
        "author": {
 | 
					        "author": {
 | 
				
			||||||
          "name": "esmBot Help",
 | 
					          "name": "esmBot Help",
 | 
				
			||||||
          "icon_url": client.user.avatarURL
 | 
					          "icon_url": client.user.avatarURL
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        "title": `${guild.prefix}${aliases.includes(args[0].toLowerCase()) ? collections.aliases.get(args[0].toLowerCase()) : args[0].toLowerCase()}`,
 | 
					        "title": `${guild.prefix}${aliases.has(args[0].toLowerCase()) ? collections.aliases.get(args[0].toLowerCase()) : args[0].toLowerCase()}`,
 | 
				
			||||||
        "description": info.description,
 | 
					        "description": info.description,
 | 
				
			||||||
        "color": 16711680,
 | 
					        "color": 16711680,
 | 
				
			||||||
        "fields": [{
 | 
					        "fields": [{
 | 
				
			||||||
| 
						 | 
					@ -39,7 +39,7 @@ exports.run = async (message, args) => {
 | 
				
			||||||
      images: ["**These commands support the PNG, JPEG, WEBP, and GIF formats. (GIF support is experimental)**\n"],
 | 
					      images: ["**These commands support the PNG, JPEG, WEBP, and GIF formats. (GIF support is experimental)**\n"],
 | 
				
			||||||
      soundboard: []
 | 
					      soundboard: []
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    for (const command of commands) {
 | 
					    for (const [command] of commands) {
 | 
				
			||||||
      const category = collections.info.get(command).category;
 | 
					      const category = collections.info.get(command).category;
 | 
				
			||||||
      const description = collections.info.get(command).description;
 | 
					      const description = collections.info.get(command).description;
 | 
				
			||||||
      const params = collections.info.get(command).params;
 | 
					      const params = collections.info.get(command).params;
 | 
				
			||||||
| 
						 | 
					@ -48,7 +48,7 @@ exports.run = async (message, args) => {
 | 
				
			||||||
      } else if (category === 2) {
 | 
					      } else if (category === 2) {
 | 
				
			||||||
        categories.moderation.push(`**${command}**${params ? ` ${params}` : ""} - ${description}`);
 | 
					        categories.moderation.push(`**${command}**${params ? ` ${params}` : ""} - ${description}`);
 | 
				
			||||||
      } else if (category === 3) {
 | 
					      } else if (category === 3) {
 | 
				
			||||||
        const subCommands = Array.from(Object.keys(description));
 | 
					        const subCommands = [...Object.keys(description)];
 | 
				
			||||||
        for (const subCommand of subCommands) {
 | 
					        for (const subCommand of subCommands) {
 | 
				
			||||||
          categories.tags.push(`**tags${subCommand !== "default" ? ` ${subCommand}` : ""}**${params[subCommand] ? ` ${params[subCommand]}` : ""} - ${description[subCommand]}`);
 | 
					          categories.tags.push(`**tags${subCommand !== "default" ? ` ${subCommand}` : ""}**${params[subCommand] ? ` ${params[subCommand]}` : ""} - ${description[subCommand]}`);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -67,12 +67,12 @@ exports.run = async (message, args) => {
 | 
				
			||||||
      }).filter((item) => {
 | 
					      }).filter((item) => {
 | 
				
			||||||
        return item;
 | 
					        return item;
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
      splitPages.forEach(page => {
 | 
					      for (const page of splitPages) {
 | 
				
			||||||
        pages.push({
 | 
					        pages.push({
 | 
				
			||||||
          title: category.charAt(0).toUpperCase() + category.slice(1),
 | 
					          title: category.charAt(0).toUpperCase() + category.slice(1),
 | 
				
			||||||
          page: page
 | 
					          page: page
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
      });
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    const embeds = [];
 | 
					    const embeds = [];
 | 
				
			||||||
    for (const [i, value] of pages.entries()) {
 | 
					    for (const [i, value] of pages.entries()) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,8 +5,8 @@ exports.run = async (message, args) => {
 | 
				
			||||||
  if (!message.channel.guild.members.get(client.user.id).permission.has("manageMessages") && !message.channel.permissionsOf(client.user.id).has("manageMessages")) return `${message.author.mention}, I don't have the \`Manage Messages\` permission!`;
 | 
					  if (!message.channel.guild.members.get(client.user.id).permission.has("manageMessages") && !message.channel.permissionsOf(client.user.id).has("manageMessages")) return `${message.author.mention}, I don't have the \`Manage Messages\` permission!`;
 | 
				
			||||||
  if (args.length === 0 || !args[0].match(/^\d+$/)) return `${message.author.mention}, you need to provide the number of messages to purge!`;
 | 
					  if (args.length === 0 || !args[0].match(/^\d+$/)) return `${message.author.mention}, you need to provide the number of messages to purge!`;
 | 
				
			||||||
  const numberOfMessages = parseInt(args[0]) + 1;
 | 
					  const numberOfMessages = parseInt(args[0]) + 1;
 | 
				
			||||||
  await message.channel.purge(numberOfMessages);
 | 
					  const number = await message.channel.purge(numberOfMessages);
 | 
				
			||||||
  return `Successfully purged ${args[0]} messages.`;
 | 
					  return `Successfully purged ${number - 1} messages.`;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.aliases = ["prune"];
 | 
					exports.aliases = ["prune"];
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,9 +4,9 @@ const collections = require("../utils/collections.js");
 | 
				
			||||||
exports.run = async (message) => {
 | 
					exports.run = async (message) => {
 | 
				
			||||||
  if (message.author.id !== process.env.OWNER) return `${message.author.mention}, only the bot owner can restart me!`;
 | 
					  if (message.author.id !== process.env.OWNER) return `${message.author.mention}, only the bot owner can restart me!`;
 | 
				
			||||||
  await message.channel.createMessage(`${message.author.mention}, esmBot is restarting.`);
 | 
					  await message.channel.createMessage(`${message.author.mention}, esmBot is restarting.`);
 | 
				
			||||||
  collections.commands.forEach(async (command) => {
 | 
					  for (const command of collections.commands) {
 | 
				
			||||||
    await handler.unload(command);
 | 
					    await handler.unload(command);
 | 
				
			||||||
  });
 | 
					  }
 | 
				
			||||||
  process.exit(1);
 | 
					  process.exit(1);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -40,8 +40,8 @@ exports.run = async (message, args) => {
 | 
				
			||||||
      if (!message.channel.guild.members.get(client.user.id).permission.has("embedLinks") && !message.channel.permissionsOf(client.user.id).has("embedLinks")) return `${message.author.mention}, I don't have the \`Embed Links\` permission!`;
 | 
					      if (!message.channel.guild.members.get(client.user.id).permission.has("embedLinks") && !message.channel.permissionsOf(client.user.id).has("embedLinks")) return `${message.author.mention}, I don't have the \`Embed Links\` permission!`;
 | 
				
			||||||
      var pageSize = 15;
 | 
					      var pageSize = 15;
 | 
				
			||||||
      var embeds = [];
 | 
					      var embeds = [];
 | 
				
			||||||
      var groups = Array.from(tags.keys()).map((item, index) => {
 | 
					      var groups = [...tags.keys()].map((item, index) => {
 | 
				
			||||||
        return index % pageSize === 0 ? Array.from(tags.keys()).slice(index, index + pageSize) : null;
 | 
					        return index % pageSize === 0 ? [...tags.keys()].slice(index, index + pageSize) : null;
 | 
				
			||||||
      }).filter((item) => {
 | 
					      }).filter((item) => {
 | 
				
			||||||
        return item;
 | 
					        return item;
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
| 
						 | 
					@ -65,7 +65,7 @@ exports.run = async (message, args) => {
 | 
				
			||||||
      if (embeds.length === 0) return `${message.author.mention}, I couldn't find any tags!`;
 | 
					      if (embeds.length === 0) return `${message.author.mention}, I couldn't find any tags!`;
 | 
				
			||||||
      return paginator(message, embeds);
 | 
					      return paginator(message, embeds);
 | 
				
			||||||
    case "random":
 | 
					    case "random":
 | 
				
			||||||
      return random(Array.from(tags))[1].content;
 | 
					      return random([...tags])[1].content;
 | 
				
			||||||
    default:
 | 
					    default:
 | 
				
			||||||
      if (!tags.has(args[0].toLowerCase())) return `${message.author.mention}, this tag doesn't exist!`;
 | 
					      if (!tags.has(args[0].toLowerCase())) return `${message.author.mention}, this tag doesn't exist!`;
 | 
				
			||||||
      return tags.get(args[0].toLowerCase()).content;
 | 
					      return tags.get(args[0].toLowerCase()).content;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
const { Collection } = require("eris");
 | 
					//const { Collection } = require("eris");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.commands = new Collection();
 | 
					exports.commands = new Map();
 | 
				
			||||||
exports.aliases = new Collection();
 | 
					exports.aliases = new Map();
 | 
				
			||||||
exports.info = new Collection();
 | 
					exports.info = new Map();
 | 
				
			||||||
| 
						 | 
					@ -16,9 +16,9 @@ exports.load = async (command) => {
 | 
				
			||||||
    params: props.params
 | 
					    params: props.params
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
  if (props.aliases) {
 | 
					  if (props.aliases) {
 | 
				
			||||||
    props.aliases.forEach(alias => {
 | 
					    for (const alias of props.aliases) {
 | 
				
			||||||
      collections.aliases.set(alias, command.split(".")[0]);
 | 
					      collections.aliases.set(alias, command.split(".")[0]);
 | 
				
			||||||
    });
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  return false;
 | 
					  return false;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,7 +19,7 @@ Default prefix is \`&\`.
 | 
				
			||||||
+ [**Image Editing**](#🖼️-image-editing)
 | 
					+ [**Image Editing**](#🖼️-image-editing)
 | 
				
			||||||
+ [**Soundboard**](#🔊-soundboard)
 | 
					+ [**Soundboard**](#🔊-soundboard)
 | 
				
			||||||
`;
 | 
					`;
 | 
				
			||||||
  const commands = Array.from(collections.commands.keys());
 | 
					  const commands = collections.commands;
 | 
				
			||||||
  const categories = {
 | 
					  const categories = {
 | 
				
			||||||
    general: ["## 💻 General"],
 | 
					    general: ["## 💻 General"],
 | 
				
			||||||
    moderation: ["## 🔨 Moderation"],
 | 
					    moderation: ["## 🔨 Moderation"],
 | 
				
			||||||
| 
						 | 
					@ -28,7 +28,7 @@ Default prefix is \`&\`.
 | 
				
			||||||
    images: ["## 🖼️ Image Editing", "> These commands support the PNG, JPEG, WEBP, and GIF formats. (GIF support is currently experimental)"],
 | 
					    images: ["## 🖼️ Image Editing", "> These commands support the PNG, JPEG, WEBP, and GIF formats. (GIF support is currently experimental)"],
 | 
				
			||||||
    soundboard: ["## 🔊 Soundboard"]
 | 
					    soundboard: ["## 🔊 Soundboard"]
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
  for (const command of commands) {
 | 
					  for (const [command] of commands) {
 | 
				
			||||||
    const category = collections.info.get(command).category;
 | 
					    const category = collections.info.get(command).category;
 | 
				
			||||||
    const description = collections.info.get(command).description;
 | 
					    const description = collections.info.get(command).description;
 | 
				
			||||||
    const params = collections.info.get(command).params;
 | 
					    const params = collections.info.get(command).params;
 | 
				
			||||||
| 
						 | 
					@ -37,7 +37,7 @@ Default prefix is \`&\`.
 | 
				
			||||||
    } else if (category === 2) {
 | 
					    } else if (category === 2) {
 | 
				
			||||||
      categories.moderation.push(`+ **${command}**${params ? ` ${params}` : ""} - ${description}`);
 | 
					      categories.moderation.push(`+ **${command}**${params ? ` ${params}` : ""} - ${description}`);
 | 
				
			||||||
    } else if (category === 3) {
 | 
					    } else if (category === 3) {
 | 
				
			||||||
      const subCommands = Array.from(Object.keys(description));
 | 
					      const subCommands = [...Object.keys(description)];
 | 
				
			||||||
      for (const subCommand of subCommands) {
 | 
					      for (const subCommand of subCommands) {
 | 
				
			||||||
        categories.tags.push(`+ **tags${subCommand !== "default" ? ` ${subCommand}` : ""}**${params[subCommand] ? ` ${params[subCommand]}` : ""} - ${description[subCommand]}`);
 | 
					        categories.tags.push(`+ **tags${subCommand !== "default" ? ` ${subCommand}` : ""}**${params[subCommand] ? ` ${params[subCommand]}` : ""} - ${description[subCommand]}`);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue