mirror of
https://github.com/keanuplayz/TravBot-v3.git
synced 2024-08-15 02:33:12 +00:00
Added (currently broken) emote dumper.
This commit is contained in:
parent
aeff8ac832
commit
a99386c431
8 changed files with 96 additions and 1 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import {writeFileSync} from "fs";
|
||||||
import {GenericWrapper, NumberWrapper, StringWrapper, ArrayWrapper} from "./wrappers";
|
import {GenericWrapper, NumberWrapper, StringWrapper, ArrayWrapper} from "./wrappers";
|
||||||
import {Client, Message, TextChannel, DMChannel, NewsChannel, Guild, User, GuildMember, Permissions} from "discord.js";
|
import {Client, Message, TextChannel, DMChannel, NewsChannel, Guild, User, GuildMember, Permissions} from "discord.js";
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
|
@ -5,6 +6,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 +162,31 @@ 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()) {
|
||||||
|
$.debug(client.guilds.cache.size);
|
||||||
|
for (const emote of guild.emojis.cache.values()) {
|
||||||
|
$.debug(client.emojis.cache.size);
|
||||||
|
console.log("HELLO?!");
|
||||||
|
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
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const sData = JSON.stringify(data);
|
||||||
|
$.debug(data);
|
||||||
|
$.debug(sData);
|
||||||
|
writeFileSync("emote-registry.json", sData);
|
||||||
|
}
|
||||||
|
|
||||||
// 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[];
|
||||||
|
}
|
||||||
|
|
10
src/events/emojiCreate.ts
Normal file
10
src/events/emojiCreate.ts
Normal file
|
@ -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();
|
||||||
|
}
|
||||||
|
});
|
10
src/events/emojiDelete.ts
Normal file
10
src/events/emojiDelete.ts
Normal file
|
@ -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();
|
||||||
|
}
|
||||||
|
});
|
10
src/events/emojiUpdate.ts
Normal file
10
src/events/emojiUpdate.ts
Normal file
|
@ -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();
|
||||||
|
}
|
||||||
|
});
|
10
src/events/guildCreate.ts
Normal file
10
src/events/guildCreate.ts
Normal file
|
@ -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();
|
||||||
|
}
|
||||||
|
});
|
10
src/events/guildDelete.ts
Normal file
10
src/events/guildDelete.ts
Normal file
|
@ -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 a new issue