Merge pull request #21 from keanuplayz/emote-dump
This commit is contained in:
commit
56dafed616
|
@ -68,4 +68,4 @@ typings/
|
||||||
.env
|
.env
|
||||||
|
|
||||||
config.json
|
config.json
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
|
@ -5,6 +5,7 @@ import {get} from "https";
|
||||||
import FileManager from "./storage";
|
import FileManager from "./storage";
|
||||||
import {eventListeners} from "../events/messageReactionRemove";
|
import {eventListeners} from "../events/messageReactionRemove";
|
||||||
import {client} from "../index";
|
import {client} from "../index";
|
||||||
|
import {EmoteRegistryDump, EmoteRegistryDumpEntry} from "./structures";
|
||||||
|
|
||||||
/** A type that describes what the library module does. */
|
/** A type that describes what the library module does. */
|
||||||
export interface CommonLibrary {
|
export interface CommonLibrary {
|
||||||
|
@ -160,6 +161,27 @@ export function botHasPermission(guild: Guild | null, permission: number): boole
|
||||||
return !!(client.user && guild?.members.resolve(client.user)?.hasPermission(permission));
|
return !!(client.user && guild?.members.resolve(client.user)?.hasPermission(permission));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export 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);
|
||||||
|
}
|
||||||
|
|
||||||
// Pagination function that allows for customization via a callback.
|
// Pagination function that allows for customization via a callback.
|
||||||
// Define your own pages outside the function because this only manages the actual turning of pages.
|
// Define your own pages outside the function because this only manages the actual turning of pages.
|
||||||
$.paginate = async (
|
$.paginate = async (
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import FileManager from "./storage";
|
import FileManager from "./storage";
|
||||||
import $, {select, GenericJSON, GenericStructure} from "./lib";
|
import $, {select, GenericJSON, GenericStructure} from "./lib";
|
||||||
import {watch} from "fs";
|
import {watch} from "fs";
|
||||||
import {Guild as DiscordGuild} from "discord.js";
|
import {Guild as DiscordGuild, Snowflake} from "discord.js";
|
||||||
|
|
||||||
class ConfigStructure extends GenericStructure {
|
class ConfigStructure extends GenericStructure {
|
||||||
public token: string;
|
public token: string;
|
||||||
|
@ -106,3 +106,19 @@ if (process.argv[2] === "dev") {
|
||||||
export function getPrefix(guild: DiscordGuild | null): string {
|
export function getPrefix(guild: DiscordGuild | null): string {
|
||||||
return Storage.getGuild(guild?.id || "N/A").prefix ?? Config.prefix;
|
return Storage.getGuild(guild?.id || "N/A").prefix ?? Config.prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface EmoteRegistryDumpEntry {
|
||||||
|
ref: string;
|
||||||
|
id: Snowflake;
|
||||||
|
name: string;
|
||||||
|
requires_colons: boolean;
|
||||||
|
animated: boolean;
|
||||||
|
url: string;
|
||||||
|
guild_id: Snowflake;
|
||||||
|
guild_name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EmoteRegistryDump {
|
||||||
|
version: number;
|
||||||
|
list: EmoteRegistryDumpEntry[];
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
import Event from "../core/event";
|
||||||
|
import $ from "../core/lib";
|
||||||
|
import {updateGlobalEmoteRegistry} from "../core/lib";
|
||||||
|
|
||||||
|
export default new Event<"emojiCreate">({
|
||||||
|
on(emote) {
|
||||||
|
$.log(`Updated emote registry. ${emote.name}`);
|
||||||
|
updateGlobalEmoteRegistry();
|
||||||
|
}
|
||||||
|
});
|
|
@ -0,0 +1,10 @@
|
||||||
|
import Event from "../core/event";
|
||||||
|
import $ from "../core/lib";
|
||||||
|
import {updateGlobalEmoteRegistry} from "../core/lib";
|
||||||
|
|
||||||
|
export default new Event<"emojiDelete">({
|
||||||
|
on() {
|
||||||
|
$.log("Updated emote registry.");
|
||||||
|
updateGlobalEmoteRegistry();
|
||||||
|
}
|
||||||
|
});
|
|
@ -0,0 +1,10 @@
|
||||||
|
import Event from "../core/event";
|
||||||
|
import $ from "../core/lib";
|
||||||
|
import {updateGlobalEmoteRegistry} from "../core/lib";
|
||||||
|
|
||||||
|
export default new Event<"emojiUpdate">({
|
||||||
|
on() {
|
||||||
|
$.log("Updated emote registry.");
|
||||||
|
updateGlobalEmoteRegistry();
|
||||||
|
}
|
||||||
|
});
|
|
@ -0,0 +1,10 @@
|
||||||
|
import Event from "../core/event";
|
||||||
|
import $ from "../core/lib";
|
||||||
|
import {updateGlobalEmoteRegistry} from "../core/lib";
|
||||||
|
|
||||||
|
export default new Event<"guildCreate">({
|
||||||
|
on() {
|
||||||
|
$.log("Updated emote registry.");
|
||||||
|
updateGlobalEmoteRegistry();
|
||||||
|
}
|
||||||
|
});
|
|
@ -0,0 +1,10 @@
|
||||||
|
import Event from "../core/event";
|
||||||
|
import $ from "../core/lib";
|
||||||
|
import {updateGlobalEmoteRegistry} from "../core/lib";
|
||||||
|
|
||||||
|
export default new Event<"guildDelete">({
|
||||||
|
on() {
|
||||||
|
$.log("Updated emote registry.");
|
||||||
|
updateGlobalEmoteRegistry();
|
||||||
|
}
|
||||||
|
});
|
|
@ -2,6 +2,7 @@ import Event from "../core/event";
|
||||||
import {client} from "../index";
|
import {client} from "../index";
|
||||||
import $ from "../core/lib";
|
import $ from "../core/lib";
|
||||||
import {Config} from "../core/structures";
|
import {Config} from "../core/structures";
|
||||||
|
import {updateGlobalEmoteRegistry} from "../core/lib";
|
||||||
|
|
||||||
export default new Event<"ready">({
|
export default new Event<"ready">({
|
||||||
once() {
|
once() {
|
||||||
|
@ -12,5 +13,6 @@ export default new Event<"ready">({
|
||||||
name: `${Config.prefix}help`
|
name: `${Config.prefix}help`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
updateGlobalEmoteRegistry();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue