use jf handler in client

This commit is contained in:
mightypanders 2023-04-16 02:03:39 +02:00
parent 75aae28cbb
commit 901daa4f10

View File

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