diff --git a/server/structures/client.ts b/server/structures/client.ts index 1517e66..fd1008c 100644 --- a/server/structures/client.ts +++ b/server/structures/client.ts @@ -2,25 +2,30 @@ import { ApplicationCommandDataResolvable, Client, ClientOptions, Collection, Ga import { CommandType } from "../types/commandTypes"; import fs from 'fs' import { config } from "../configuration"; +import { JellyfinHandler } from "../../jellyfin/handler"; +import { logger } from "../logger"; export class ExtendedClient extends Client { private eventFilePath = `${__dirname}/../events` private commandFilePath = `${__dirname}/../commands` + private jellyfin: JellyfinHandler public commands: Collection = new Collection() - public constructor() { + public constructor(jf: JellyfinHandler) { const intents: IntentsBitField = new IntentsBitField() intents.add(IntentsBitField.Flags.GuildMembers, IntentsBitField.Flags.MessageContent, IntentsBitField.Flags.Guilds, IntentsBitField.Flags.DirectMessages) const options: ClientOptions = { intents } super(options) + this.jellyfin = jf } - public start() { + public async start() { if (process.env.NODE_ENV === 'test') return const promises: Promise[] = Array() promises.push(this.registerSlashCommands()) promises.push(this.registerEventCallback()) Promise.all(promises).then(() => { - this.login(config.token) + this.login(config.bot.token) }) + logger.info(`Connected with ${await this.jellyfin.ServerName()}`) } private async importFile(filepath: string): Promise { console.debug(`Importing ${filepath}`) @@ -65,7 +70,7 @@ export class ExtendedClient extends Client { } } public async cacheUsers(guilds: Collection) { - guilds.forEach((guild:Guild, id:Snowflake) => { + guilds.forEach((guild: Guild, id: Snowflake) => { console.log(`Fetching members for ${guild.name}|${id}`) guild.members.fetch() console.log(`Fetched: ${guild.memberCount} members`)