diff options
| author | Max Isom <[email protected]> | 2022-08-04 22:06:54 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-08-04 22:06:54 -0500 |
| commit | 89bd6206af3e49ca119656c97c1fa19635120c08 (patch) | |
| tree | 424d8a8e9870fc59b84483bb435a4ae1b9a8b3fc /src | |
| parent | fd3fd32e7675aded4d334b6287d84e97568b4e4b (diff) | |
| download | muse-89bd6206af3e49ca119656c97c1fa19635120c08.tar.xz muse-89bd6206af3e49ca119656c97c1fa19635120c08.zip | |
Bump dependencies & fix bot status (#753)
Diffstat (limited to 'src')
| -rw-r--r-- | src/bot.ts | 8 | ||||
| -rw-r--r-- | src/services/config.ts | 22 |
2 files changed, 22 insertions, 8 deletions
@@ -1,4 +1,4 @@ -import {Client, Collection, PresenceStatusData, User} from 'discord.js'; +import {Client, Collection, User} from 'discord.js'; import {inject, injectable} from 'inversify'; import ora from 'ora'; import {TYPES} from './types.js'; @@ -12,7 +12,7 @@ import {isUserInVoice} from './utils/channels.js'; import Config from './services/config.js'; import {generateDependencyReport} from '@discordjs/voice'; import {REST} from '@discordjs/rest'; -import {Routes, ActivityType} from 'discord-api-types/v10'; +import {Routes} from 'discord-api-types/v10'; import registerCommandsOnGuild from './utils/register-commands-on-guild.js'; @injectable() @@ -150,11 +150,11 @@ export default class { activities: [ { name: this.config.BOT_ACTIVITY, - type: this.config.BOT_ACTIVITY_TYPE as unknown as Exclude<ActivityType, ActivityType.Custom>, + type: this.config.BOT_ACTIVITY_TYPE, url: this.config.BOT_ACTIVITY_URL === '' ? undefined : this.config.BOT_ACTIVITY_URL, }, ], - status: this.config.BOT_STATUS as PresenceStatusData, + status: this.config.BOT_STATUS, }); spinner.succeed(`Ready! Invite the bot with https://discordapp.com/oauth2/authorize?client_id=${this.client.user?.id ?? ''}&scope=bot%20applications.commands&permissions=36700160`); diff --git a/src/services/config.ts b/src/services/config.ts index ca4fc68..1cafd3c 100644 --- a/src/services/config.ts +++ b/src/services/config.ts @@ -4,6 +4,7 @@ import {injectable} from 'inversify'; import path from 'path'; import xbytes from 'xbytes'; import {ConditionalKeys} from 'type-fest'; +import {ActivityType, PresenceStatusData} from 'discord.js'; dotenv.config(); export const DATA_DIR = path.resolve(process.env.DATA_DIR ? process.env.DATA_DIR : './data'); @@ -18,11 +19,18 @@ const CONFIG_MAP = { CACHE_DIR: path.join(DATA_DIR, 'cache'), CACHE_LIMIT_IN_BYTES: xbytes.parseSize(process.env.CACHE_LIMIT ?? '2GB'), BOT_STATUS: process.env.BOT_STATUS ?? 'online', - BOT_ACTIVITY_TYPE: process.env.BOT_ACTIVITY_TYPE ?? 'Listening', + BOT_ACTIVITY_TYPE: process.env.BOT_ACTIVITY_TYPE ?? 'LISTENING', BOT_ACTIVITY_URL: process.env.BOT_ACTIVITY_URL ?? '', BOT_ACTIVITY: process.env.BOT_ACTIVITY ?? 'music', } as const; +const BOT_ACTIVITY_TYPE_MAP = { + PLAYING: ActivityType.Playing, + LISTENING: ActivityType.Listening, + WATCHING: ActivityType.Watching, + STREAMING: ActivityType.Streaming, +} as const; + @injectable() export default class Config { readonly DISCORD_TOKEN!: string; @@ -33,8 +41,8 @@ export default class Config { readonly DATA_DIR!: string; readonly CACHE_DIR!: string; readonly CACHE_LIMIT_IN_BYTES!: number; - readonly BOT_STATUS!: string; - readonly BOT_ACTIVITY_TYPE!: string; + readonly BOT_STATUS!: PresenceStatusData; + readonly BOT_ACTIVITY_TYPE!: Exclude<ActivityType, ActivityType.Custom>; readonly BOT_ACTIVITY_URL!: string; readonly BOT_ACTIVITY!: string; @@ -45,10 +53,16 @@ export default class Config { process.exit(1); } + if (key === 'BOT_ACTIVITY_TYPE') { + this[key] = BOT_ACTIVITY_TYPE_MAP[(value as string).toUpperCase() as keyof typeof BOT_ACTIVITY_TYPE_MAP]; + continue; + } + if (typeof value === 'number') { this[key as ConditionalKeys<typeof CONFIG_MAP, number>] = value; } else if (typeof value === 'string') { - this[key as ConditionalKeys<typeof CONFIG_MAP, string>] = value.trim(); + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + (this as any)[key] = value.trim(); } else if (typeof value === 'boolean') { this[key as ConditionalKeys<typeof CONFIG_MAP, boolean>] = value; } else { |
