From a86e11ed23a83bd292076f18cbe842ea5311267f Mon Sep 17 00:00:00 2001 From: Keanu Date: Thu, 13 Aug 2020 22:39:10 +0200 Subject: [PATCH] Added lsemotes command to util. --- src/commands/util.ts | 72 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/commands/util.ts diff --git a/src/commands/util.ts b/src/commands/util.ts new file mode 100644 index 0000000..b1e6f81 --- /dev/null +++ b/src/commands/util.ts @@ -0,0 +1,72 @@ +import { MessageEmbed } from "discord.js"; +import Command from '../core/command'; +import {CommonLibrary} from '../core/lib'; + +export default new Command({ + description: "", + endpoint: false, + usage: '', + async run($: CommonLibrary): Promise { + + }, + subcommands: { + lsemotes: new Command({ + description: "Lists all emotes the bot has in it's registry,", + 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 = "➡"; + 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); + msg.edit(embed); + }); + } + }) + } +}); \ No newline at end of file