feature: emote adding, listing and removing
This commit is contained in:
43
commands/emotes/emotelog.js
Normal file
43
commands/emotes/emotelog.js
Normal file
@@ -0,0 +1,43 @@
|
||||
const { SlashCommandBuilder } = require("discord.js");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("emotelog")
|
||||
.setDescription("Logs the emote inputted.")
|
||||
.addStringOption(option =>
|
||||
option.setName("emote")
|
||||
.setDescription("The emote to log.")
|
||||
.setRequired(true)
|
||||
),
|
||||
async execute(interaction) {
|
||||
await interaction.deferReply();
|
||||
|
||||
// this regex matches emotes in the format <:name:id> or <a:name:id>
|
||||
let emoteIdRegex = /<(?<animated>a?):(?<name>\w{0,22})\w*:(?<id>\d+)>/gm;
|
||||
let replyMessage = "";
|
||||
const input = interaction.options.getString("emote");
|
||||
// remove duplicates from the emote list
|
||||
let emoteList = input.matchAll(emoteIdRegex);
|
||||
emoteList = [...new Set(emoteList)].join(" ");
|
||||
for (const match of emoteList.matchAll(emoteIdRegex)) {
|
||||
const link = "https://cdn.discordapp.com/emojis/" + match.groups.id + ((match.groups.animated == 'a') ? ".gif": ".webp") + "?quality=lossless";
|
||||
const copyname = match.groups.name + "_FE";
|
||||
await interaction.guild.emojis.create({attachment: link, name: copyname});
|
||||
await interaction.editReply(`Logged ${match[0]}!\n`);
|
||||
replyMessage += `Logged ${match[0]}!\n`;
|
||||
}
|
||||
|
||||
// add a message to say how many emote spots are left
|
||||
interaction.guild.emojis.fetch()
|
||||
.then(emojis => {
|
||||
let animatedEmojis = emojis.filter(emoji => emoji.animated);
|
||||
replyMessage += `\nAnimated emotes: ${animatedEmojis.size}/50\n`
|
||||
let staticEmojis = emojis.filter(emoji => !emoji.animated);
|
||||
replyMessage += `Static emotes: ${staticEmojis.size}/50\n`
|
||||
interaction.editReply(replyMessage);
|
||||
})
|
||||
.catch(console.error);
|
||||
},
|
||||
};
|
||||
|
||||
// https://cdn.discordapp.com/emojis/1166779045711720541.webp?size=44&quality=lossless
|
28
commands/emotes/list.js
Normal file
28
commands/emotes/list.js
Normal file
@@ -0,0 +1,28 @@
|
||||
const { SlashCommandBuilder } = require("discord.js");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("listemotes")
|
||||
.setDescription("Lists all emotes in the server."),
|
||||
async execute(interaction) {
|
||||
await interaction.reply("Fetching emotes...");
|
||||
let replyMessage = "";
|
||||
interaction.guild.emojis.fetch()
|
||||
.then(emojis => {
|
||||
// we need to make followup messages if the list is too long
|
||||
let emoteList = "";
|
||||
emojis.forEach(emoji => {
|
||||
emoteList += `${emoji} - ${emoji.name}\n`;
|
||||
if (emoteList.length > 1900) {
|
||||
interaction.followUp(emoteList);
|
||||
emoteList = "";
|
||||
}
|
||||
});
|
||||
if (emoteList.length > 0) {
|
||||
interaction.followUp(emoteList);
|
||||
}
|
||||
interaction.followUp("Total emotes: " + emojis.size + "\n");
|
||||
})
|
||||
.catch(console.error);
|
||||
},
|
||||
};
|
29
commands/emotes/rm.js
Normal file
29
commands/emotes/rm.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const { SlashCommandBuilder } = require("discord.js");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("rm")
|
||||
.setDescription("Removes emotes from the server.")
|
||||
.addStringOption(option =>
|
||||
option.setName("emotes")
|
||||
.setDescription("Emotes to remove.")
|
||||
.setRequired(true)),
|
||||
async execute(interaction) {
|
||||
await interaction.reply("Removing emotes...");
|
||||
// find every emote in the message and remove them
|
||||
let emoteList = interaction.options.getString("emotes");
|
||||
let emoteIdRegex = /<(?<animated>a?):(?<name>\w{0,22})\w*:(?<id>\d+)>/gm;
|
||||
let replyMessage = "";
|
||||
for (const match of emoteList.matchAll(emoteIdRegex)) {
|
||||
let emote = interaction.guild.emojis.cache.find(emoji => emoji.id === match.groups.id);
|
||||
if (emote) {
|
||||
await emote.delete();
|
||||
replyMessage += `Removed ${match[0]}!\n`;
|
||||
} else {
|
||||
replyMessage += `Could not find ${match[0]}!\n`;
|
||||
}
|
||||
interaction.editReply(replyMessage);
|
||||
replyMessage = "";
|
||||
}
|
||||
},
|
||||
};
|
10
commands/utils/ping.js
Normal file
10
commands/utils/ping.js
Normal file
@@ -0,0 +1,10 @@
|
||||
const { SlashCommandBuilder } = require("discord.js");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("ping")
|
||||
.setDescription("Replies with Pong!"),
|
||||
async execute(interaction) {
|
||||
await interaction.reply("Pong!");
|
||||
},
|
||||
};
|
Reference in New Issue
Block a user