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 <watduhhekbro@gmail.com>
This commit is contained in:
Lexi 2020-10-13 22:11:26 +02:00
parent 4d1fdf3a97
commit 57a4c9f523
3 changed files with 50 additions and 71 deletions

1
.dockerignore Normal file
View File

@ -0,0 +1 @@
node_modules/

View File

@ -15,58 +15,34 @@ export default new Command({
endpoint: true, endpoint: true,
async run($: CommonLibrary): Promise<any> { async run($: CommonLibrary): Promise<any> {
const nsfw: string | string[] = []; const nsfw: string | string[] = [];
const list = $.client.emojis.cache.filter(x => !nsfw.includes(x.guild.id), this) const pages = $.client.emojis.cache.filter(x => !nsfw.includes(x.guild.id), this).array();
.array(); // $.log(pages);
let page = 1;
const epg = 20;
let content = "";
const left = "⬅",
right = "➡";
var embed = new MessageEmbed() var embed = new MessageEmbed()
.setTitle("**Emoji list!**") .setTitle("**Emoji list!**")
.setColor("AQUA"); .setColor("AQUA");
let owo = list.slice((page - 1) * epg, page * epg); const msg = await $.channel.send({embed});
owo.forEach(q => (content += q.toString() + " | " + q.name + "\n"));
embed.setDescription(content); $.paginate(msg, $.author.id, pages.length, page => {
const msg = await $.channel.send({ embed.setDescription(`${pages[page]} | ${pages[page].name}`);
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); 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: "<emote>",
async run($: CommonLibrary): Promise<any>
{
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}`);
}
})
}) })
} }
}); });

View File

@ -166,31 +166,33 @@ $.paginate = async(message: Message, senderID: string, total: number, callback:
callback(page); callback(page);
} }
const handle = (emote: string, reacterID: string) => { const handle = (emote: string, reacterID: string) => {
if(reacterID === senderID) switch(emote)
{ {
switch(emote) case '⬅️': turn(-1); break;
{ case '➡️': turn(1); break;
case '⬅️': turn(-1); break; }
case '➡️': turn(1); break; };
}
} // Listen for reactions and call the handler.
}; await message.react('⬅️');
await message.react('➡️');
// Listen for reactions and call the handler. eventListeners.set(message.id, handle);
await message.react('⬅️'); await message.awaitReactions((reaction, user) => {
await message.react('➡️'); if(user.id === senderID)
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.
// 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.
// 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);
const canDeleteEmotes = botHasPermission(message.guild, Permissions.FLAGS.MANAGE_MESSAGES); handle(reaction.emoji.name, user.id);
handle(reaction.emoji.name, user.id);
if(canDeleteEmotes)
if(canDeleteEmotes) reaction.users.remove(user);
reaction.users.remove(user); }
return false; return false;
}, {time: duration}); }, {time: duration});
$.log("removal")
// When time's up, remove the bot's own reactions. // When time's up, remove the bot's own reactions.
eventListeners.delete(message.id); eventListeners.delete(message.id);