2021-03-31 02:56:25 +00:00
|
|
|
import {client} from "../index";
|
2021-04-05 04:35:12 +00:00
|
|
|
import FileManager from "./storage";
|
2021-04-08 21:43:58 +00:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
2021-04-08 21:43:58 +00:00
|
|
|
client.on("guildCreate", () => {
|
|
|
|
console.log("Updated emote registry.");
|
2021-03-31 02:56:25 +00:00
|
|
|
updateGlobalEmoteRegistry();
|
|
|
|
});
|
|
|
|
|
2021-04-08 21:43:58 +00:00
|
|
|
client.on("guildDelete", () => {
|
|
|
|
console.log("Updated emote registry.");
|
2021-03-31 02:56:25 +00:00
|
|
|
updateGlobalEmoteRegistry();
|
|
|
|
});
|
|
|
|
|
|
|
|
client.on("ready", () => {
|
|
|
|
updateGlobalEmoteRegistry();
|
|
|
|
});
|