Converted multiple functions to ES6 syntax, moved from collections to maps for storing commands
This commit is contained in:
parent
1da0d24602
commit
02df085580
|
@ -1,14 +1,10 @@
|
|||
const misc = require("../utils/misc.js");
|
||||
|
||||
exports.run = async (message, args) => {
|
||||
if (args.length === 0) {
|
||||
return `🎲 The dice landed on ${misc.random(Array.from(Array(6).keys())) + 1}.`;
|
||||
if (args.length === 0 || !args[0].match(/^\d+$/)) {
|
||||
return `🎲 The dice landed on ${misc.random([...Array(6).keys()]) + 1}.`;
|
||||
} else {
|
||||
if (args[0].match(/^\d+$/)) {
|
||||
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}.`;
|
||||
}
|
||||
return `🎲 The dice landed on ${misc.random([...Array(parseInt(args[0])).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) => {
|
||||
const guild = (await database.guilds.find({ id: message.channel.guild.id }).exec())[0];
|
||||
const commands = Array.from(collections.commands.keys());
|
||||
const aliases = Array.from(collections.aliases.keys());
|
||||
if (args.length !== 0 && (commands.includes(args[0].toLowerCase()) || aliases.includes(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 commands = collections.commands;
|
||||
const aliases = collections.aliases;
|
||||
if (args.length !== 0 && (commands.has(args[0].toLowerCase()) || aliases.has(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 = {
|
||||
"embed": {
|
||||
"author": {
|
||||
"name": "esmBot Help",
|
||||
"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,
|
||||
"color": 16711680,
|
||||
"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"],
|
||||
soundboard: []
|
||||
};
|
||||
for (const command of commands) {
|
||||
for (const [command] of commands) {
|
||||
const category = collections.info.get(command).category;
|
||||
const description = collections.info.get(command).description;
|
||||
const params = collections.info.get(command).params;
|
||||
|
@ -48,7 +48,7 @@ exports.run = async (message, args) => {
|
|||
} else if (category === 2) {
|
||||
categories.moderation.push(`**${command}**${params ? ` ${params}` : ""} - ${description}`);
|
||||
} else if (category === 3) {
|
||||
const subCommands = Array.from(Object.keys(description));
|
||||
const subCommands = [...Object.keys(description)];
|
||||
for (const subCommand of subCommands) {
|
||||
categories.tags.push(`**tags${subCommand !== "default" ? ` ${subCommand}` : ""}**${params[subCommand] ? ` ${params[subCommand]}` : ""} - ${description[subCommand]}`);
|
||||
}
|
||||
|
@ -67,12 +67,12 @@ exports.run = async (message, args) => {
|
|||
}).filter((item) => {
|
||||
return item;
|
||||
});
|
||||
splitPages.forEach(page => {
|
||||
for (const page of splitPages) {
|
||||
pages.push({
|
||||
title: category.charAt(0).toUpperCase() + category.slice(1),
|
||||
page: page
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
const embeds = [];
|
||||
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 (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;
|
||||
await message.channel.purge(numberOfMessages);
|
||||
return `Successfully purged ${args[0]} messages.`;
|
||||
const number = await message.channel.purge(numberOfMessages);
|
||||
return `Successfully purged ${number - 1} messages.`;
|
||||
};
|
||||
|
||||
exports.aliases = ["prune"];
|
||||
|
|
|
@ -4,9 +4,9 @@ const collections = require("../utils/collections.js");
|
|||
exports.run = async (message) => {
|
||||
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.`);
|
||||
collections.commands.forEach(async (command) => {
|
||||
for (const command of collections.commands) {
|
||||
await handler.unload(command);
|
||||
});
|
||||
}
|
||||
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!`;
|
||||
var pageSize = 15;
|
||||
var embeds = [];
|
||||
var groups = Array.from(tags.keys()).map((item, index) => {
|
||||
return index % pageSize === 0 ? Array.from(tags.keys()).slice(index, index + pageSize) : null;
|
||||
var groups = [...tags.keys()].map((item, index) => {
|
||||
return index % pageSize === 0 ? [...tags.keys()].slice(index, index + pageSize) : null;
|
||||
}).filter((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!`;
|
||||
return paginator(message, embeds);
|
||||
case "random":
|
||||
return random(Array.from(tags))[1].content;
|
||||
return random([...tags])[1].content;
|
||||
default:
|
||||
if (!tags.has(args[0].toLowerCase())) return `${message.author.mention}, this tag doesn't exist!`;
|
||||
return tags.get(args[0].toLowerCase()).content;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const { Collection } = require("eris");
|
||||
//const { Collection } = require("eris");
|
||||
|
||||
exports.commands = new Collection();
|
||||
exports.aliases = new Collection();
|
||||
exports.info = new Collection();
|
||||
exports.commands = new Map();
|
||||
exports.aliases = new Map();
|
||||
exports.info = new Map();
|
|
@ -16,9 +16,9 @@ exports.load = async (command) => {
|
|||
params: props.params
|
||||
});
|
||||
if (props.aliases) {
|
||||
props.aliases.forEach(alias => {
|
||||
for (const alias of props.aliases) {
|
||||
collections.aliases.set(alias, command.split(".")[0]);
|
||||
});
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
|
|
@ -19,7 +19,7 @@ Default prefix is \`&\`.
|
|||
+ [**Image Editing**](#🖼️-image-editing)
|
||||
+ [**Soundboard**](#🔊-soundboard)
|
||||
`;
|
||||
const commands = Array.from(collections.commands.keys());
|
||||
const commands = collections.commands;
|
||||
const categories = {
|
||||
general: ["## 💻 General"],
|
||||
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)"],
|
||||
soundboard: ["## 🔊 Soundboard"]
|
||||
};
|
||||
for (const command of commands) {
|
||||
for (const [command] of commands) {
|
||||
const category = collections.info.get(command).category;
|
||||
const description = collections.info.get(command).description;
|
||||
const params = collections.info.get(command).params;
|
||||
|
@ -37,7 +37,7 @@ Default prefix is \`&\`.
|
|||
} else if (category === 2) {
|
||||
categories.moderation.push(`+ **${command}**${params ? ` ${params}` : ""} - ${description}`);
|
||||
} else if (category === 3) {
|
||||
const subCommands = Array.from(Object.keys(description));
|
||||
const subCommands = [...Object.keys(description)];
|
||||
for (const subCommand of subCommands) {
|
||||
categories.tags.push(`+ **tags${subCommand !== "default" ? ` ${subCommand}` : ""}**${params[subCommand] ? ` ${params[subCommand]}` : ""} - ${description[subCommand]}`);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue