TravBot-v3/src/modules/emoteRegistry.ts

54 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-03-31 02:56:25 +00:00
import {client} from "../index";
import FileManager from "./storage";
import {EmoteRegistryDump} from "../structures";
2021-03-31 02:56:25 +00:00
function updateGlobalEmoteRegistry(): void {
const data: EmoteRegistryDump = {version: 1, list: []};
for (const guild of client.guilds.cache.values()) {
for (const emote of guild.emojis.cache.values()) {
data.list.push({
ref: emote.name,
id: emote.id,
name: emote.name,
requires_colons: emote.requiresColons || false,
animated: emote.animated,
url: emote.url,
guild_id: emote.guild.name,
guild_name: emote.guild.name
});
}
}
FileManager.write("emote-registry", data, true);
}
client.on("emojiCreate", (emote) => {
console.log(`Updated emote registry. ${emote.name}`);
updateGlobalEmoteRegistry();
});
client.on("emojiDelete", () => {
console.log("Updated emote registry.");
updateGlobalEmoteRegistry();
});
client.on("emojiUpdate", () => {
console.log("Updated emote registry.");
updateGlobalEmoteRegistry();
});
client.on("guildCreate", () => {
console.log("Updated emote registry.");
2021-03-31 02:56:25 +00:00
updateGlobalEmoteRegistry();
});
client.on("guildDelete", () => {
console.log("Updated emote registry.");
2021-03-31 02:56:25 +00:00
updateGlobalEmoteRegistry();
});
client.on("ready", () => {
updateGlobalEmoteRegistry();
});