From 57a4c9f52380056b4abfaedc4cd6d3197ed64e53 Mon Sep 17 00:00:00 2001 From: Lexi Date: Tue, 13 Oct 2020 22:11:26 +0200 Subject: [PATCH] Added WIP emote list. @WatDuhHekBro also fixed the paginate function in lib.ts. This had some inconsistencies. Aside from that, to reduce image size, docker now ignores node_modules. Co-authored-by: WatDuhHekBro --- .dockerignore | 1 + src/commands/util.ts | 68 ++++++++++++++------------------------------ src/core/lib.ts | 52 +++++++++++++++++---------------- 3 files changed, 50 insertions(+), 71 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +node_modules/ diff --git a/src/commands/util.ts b/src/commands/util.ts index b1e6f81..ed129dc 100644 --- a/src/commands/util.ts +++ b/src/commands/util.ts @@ -15,58 +15,34 @@ export default new Command({ endpoint: true, async run($: CommonLibrary): Promise { const nsfw: string | string[] = []; - const list = $.client.emojis.cache.filter(x => !nsfw.includes(x.guild.id), this) - .array(); - let page = 1; - const epg = 20; - let content = ""; - const left = "⬅", - right = "➡"; + const pages = $.client.emojis.cache.filter(x => !nsfw.includes(x.guild.id), this).array(); + // $.log(pages); var embed = new MessageEmbed() .setTitle("**Emoji list!**") .setColor("AQUA"); - let owo = list.slice((page - 1) * epg, page * epg); - owo.forEach(q => (content += q.toString() + " | " + q.name + "\n")); - embed.setDescription(content); - const msg = await $.channel.send({ - embed - }); - if (list.length < epg) return; - await msg.react("⬅"); - await msg.react("➡"); - const backwardsfilter = (reaction: { emoji: { name: string; }; }, user: { id: any; }) => reaction.emoji.name == left && user.id == $.message.author.id; - const forwardsfilter = (reaction: { emoji: { name: string; }; }, user: { id: any; }) => reaction.emoji.name == right && user.id == $.message.author.id; - const backwards = msg.createReactionCollector(backwardsfilter, { - time: 300000 - }); - const forwards = msg.createReactionCollector(forwardsfilter, { - time: 300000 - }); - backwards.on("collect", () => { - if (page < 2) return; - // @ts-ignore - msg.reactions.cache.find((uwu: { emoji: { name: string; }; }) => (uwu.emoji.name = "⬅")) - .users.remove($.message.author) - page--; - owo = list.slice((page - 1) * epg, page * epg); - content = ""; - owo.forEach(q => (content += q.toString() + " | " + q.name + "\n")); - embed.setDescription(content); - msg.edit(embed); - }); - forwards.on("collect", () => { - if (page > Math.ceil(list.length / epg)) return; - page++; - // @ts-ignore - msg.reactions.cache.find((uwu: { emoji: { name: string; }; }) => uwu.emoji.name == "➡") - .users.remove($.message.author) - owo = list.slice((page - 1) * epg, page * epg); - content = ""; - owo.forEach(q => (content += q.toString() + " | " + q.name + "\n")); - embed.setDescription(content); + const msg = await $.channel.send({embed}); + + $.paginate(msg, $.author.id, pages.length, page => { + embed.setDescription(`${pages[page]} | ${pages[page].name}`); msg.edit(embed); }); } + }), + emote: new Command({ + description: "Send the specified emote.", + run: "Please provide a command name.", + any: new Command({ + description: "The emote to send.", + usage: "", + async run($: CommonLibrary): Promise + { + const search = $.args[0].toLowerCase(); + const emote = $.client.emojis.cache.find(emote => emote.name.toLowerCase().includes(search)); + if (!emote) return $.channel.send("That's not a valid emote name!"); + $.message.delete(); + $.channel.send(`${emote}`); + } + }) }) } }); \ No newline at end of file diff --git a/src/core/lib.ts b/src/core/lib.ts index 81b960d..40dde69 100644 --- a/src/core/lib.ts +++ b/src/core/lib.ts @@ -166,31 +166,33 @@ $.paginate = async(message: Message, senderID: string, total: number, callback: callback(page); } const handle = (emote: string, reacterID: string) => { - if(reacterID === senderID) - { - switch(emote) - { - case '⬅️': turn(-1); break; - case '➡️': turn(1); break; - } - } - }; - - // Listen for reactions and call the handler. - await message.react('⬅️'); - await message.react('➡️'); - eventListeners.set(message.id, handle); - await message.awaitReactions((reaction, user) => { - // The reason this is inside the call is because it's possible to switch a user's permissions halfway and suddenly throw an error. - // This will dynamically adjust for that, switching modes depending on whether it currently has the "Manage Messages" permission. - const canDeleteEmotes = botHasPermission(message.guild, Permissions.FLAGS.MANAGE_MESSAGES); - handle(reaction.emoji.name, user.id); - - if(canDeleteEmotes) - reaction.users.remove(user); - - return false; - }, {time: duration}); + switch(emote) + { + case '⬅️': turn(-1); break; + case '➡️': turn(1); break; + } +}; + +// Listen for reactions and call the handler. +await message.react('⬅️'); +await message.react('➡️'); +eventListeners.set(message.id, handle); +await message.awaitReactions((reaction, user) => { + if(user.id === senderID) + { + // The reason this is inside the call is because it's possible to switch a user's permissions halfway and suddenly throw an error. + // This will dynamically adjust for that, switching modes depending on whether it currently has the "Manage Messages" permission. + const canDeleteEmotes = botHasPermission(message.guild, Permissions.FLAGS.MANAGE_MESSAGES); + handle(reaction.emoji.name, user.id); + + if(canDeleteEmotes) + reaction.users.remove(user); + } + + return false; +}, {time: duration}); + + $.log("removal") // When time's up, remove the bot's own reactions. eventListeners.delete(message.id);