TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 1 | import Discord, { Client, Interaction, AutocompleteInteraction, GatewayIntentBits, Collection } from 'discord.js'; |
PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame] | 2 | import { Logger } from "../utils/log.js"; |
| 3 | import Memory from "../utils/memory.js"; |
| 4 | import type { VerifySchema } from "../reflex/verify.js"; |
TheCodedProf | b5e9d55 | 2023-01-29 15:43:26 -0500 | [diff] [blame] | 5 | import { Guilds, History, ModNotes, Premium, PerformanceTest, ScanCache } from "../utils/database.js"; |
PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame] | 6 | import EventScheduler from "../utils/eventScheduler.js"; |
| 7 | import type { RoleMenuSchema } from "../actions/roleMenu.js"; |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 8 | import config from "../config/main.json" assert { type: "json" }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 9 | |
PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame] | 10 | |
| 11 | class NucleusClient extends Client { |
| 12 | logger = Logger; |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 13 | config: typeof config = config; |
PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame] | 14 | verify: Record<string, VerifySchema> = {}; |
| 15 | roleMenu: Record<string, RoleMenuSchema> = {}; |
| 16 | memory: Memory = new Memory() as Memory; |
| 17 | noLog: string[] = []; |
| 18 | database: { |
| 19 | guilds: Guilds; |
| 20 | history: History; |
| 21 | notes: ModNotes; |
| 22 | premium: Premium; |
| 23 | eventScheduler: EventScheduler; |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 24 | performanceTest: PerformanceTest; |
TheCodedProf | b5e9d55 | 2023-01-29 15:43:26 -0500 | [diff] [blame] | 25 | scanCache: ScanCache; |
PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame] | 26 | }; |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 27 | preloadPage: Record<string, {command: string, argument: string}> = {}; // e.g. { channelID: { command: privacy, page: 3}} |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 28 | commands: Record<string, [{ |
PineaFan | df4996f | 2023-01-01 14:20:06 +0000 | [diff] [blame] | 29 | command: Discord.SlashCommandBuilder | |
| 30 | ((builder: Discord.SlashCommandBuilder) => Discord.SlashCommandBuilder) | |
| 31 | Discord.SlashCommandSubcommandBuilder | ((builder: Discord.SlashCommandSubcommandBuilder) => Discord.SlashCommandSubcommandBuilder) | Discord.SlashCommandSubcommandGroupBuilder | ((builder: Discord.SlashCommandSubcommandGroupBuilder) => Discord.SlashCommandSubcommandGroupBuilder), |
| 32 | callback: (interaction: Interaction) => Promise<void>, |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 33 | check: (interaction: Interaction, partial: boolean) => Promise<boolean> | boolean, |
PineaFan | a34d04b | 2023-01-03 22:05:42 +0000 | [diff] [blame] | 34 | autocomplete: (interaction: AutocompleteInteraction) => Promise<string[]> |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 35 | } | undefined,{name: string, description: string}]> = {}; |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 36 | fetchedCommands: Collection<string, Discord.ApplicationCommand> = new Collection(); |
PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame] | 37 | constructor(database: typeof NucleusClient.prototype.database) { |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 38 | super({ intents: [ |
| 39 | GatewayIntentBits.Guilds, |
| 40 | GatewayIntentBits.GuildMessages, |
| 41 | GatewayIntentBits.MessageContent, |
| 42 | GatewayIntentBits.GuildPresences, |
| 43 | GatewayIntentBits.GuildMembers |
| 44 | ]}); |
PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame] | 45 | this.database = database; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | const client = new NucleusClient({ |
PineaFan | 100df68 | 2023-01-02 13:26:08 +0000 | [diff] [blame] | 50 | guilds: await new Guilds().setup(), |
PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame] | 51 | history: new History(), |
| 52 | notes: new ModNotes(), |
| 53 | premium: new Premium(), |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 54 | eventScheduler: new EventScheduler(), |
TheCodedProf | b5e9d55 | 2023-01-29 15:43:26 -0500 | [diff] [blame] | 55 | performanceTest: new PerformanceTest(), |
| 56 | scanCache: new ScanCache() |
PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame] | 57 | }); |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 58 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 59 | export default client; |
PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame] | 60 | export { NucleusClient }; |