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,
async run($: CommonLibrary): Promise<any> {
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: "<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);
}
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);