diff options
| author | Zagrthos <[email protected]> | 2022-03-25 00:19:48 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-03-24 18:19:48 -0500 |
| commit | 2f9382f5171717fa512c03b3a3c08bd15ae85dd7 (patch) | |
| tree | d377ed5d0fbb68e682b22b064a4eac705e228475 /src | |
| parent | cf4905337005768644178d46c744cfdc90bef7ff (diff) | |
| download | muse-2f9382f5171717fa512c03b3a3c08bd15ae85dd7.tar.xz muse-2f9382f5171717fa512c03b3a3c08bd15ae85dd7.zip | |
Add customizable Bot status (#599)
Co-authored-by: Max Isom <[email protected]>
Co-authored-by: Max Isom <[email protected]>
Diffstat (limited to 'src')
| -rw-r--r-- | src/bot.ts | 16 | ||||
| -rw-r--r-- | src/services/config.ts | 8 |
2 files changed, 23 insertions, 1 deletions
@@ -1,4 +1,4 @@ -import {Client, Collection, User} from 'discord.js'; +import {Client, Collection, ExcludeEnum, PresenceStatusData, User} from 'discord.js'; import {inject, injectable} from 'inversify'; import ora from 'ora'; import {TYPES} from './types.js'; @@ -15,10 +15,12 @@ import {generateDependencyReport} from '@discordjs/voice'; import {REST} from '@discordjs/rest'; import {Routes} from 'discord-api-types/v9'; import updatePermissionsForGuild from './utils/update-permissions-for-guild.js'; +import {ActivityTypes} from 'discord.js/typings/enums'; @injectable() export default class { private readonly client: Client; + private readonly config: Config; private readonly token: string; private readonly shouldRegisterCommandsOnBot: boolean; private readonly commandsByName!: Collection<string, Command>; @@ -29,6 +31,7 @@ export default class { @inject(TYPES.Config) config: Config, ) { this.client = client; + this.config = config; this.token = config.DISCORD_TOKEN; this.shouldRegisterCommandsOnBot = config.REGISTER_COMMANDS_ON_BOT; this.commandsByName = new Collection(); @@ -148,6 +151,17 @@ export default class { ); } + this.client.user!.setPresence({ + activities: [ + { + name: this.config.BOT_ACTIVITY, + type: this.config.BOT_ACTIVITY_TYPE as unknown as ExcludeEnum<typeof ActivityTypes, 'CUSTOM'>, + url: this.config.BOT_ACTIVITY_URL === '' ? undefined : this.config.BOT_ACTIVITY_URL, + }, + ], + status: this.config.BOT_STATUS as PresenceStatusData, + }); + // Update permissions spinner.text = '📡 updating permissions...'; await Promise.all(this.client.guilds.cache.map(async guild => updatePermissionsForGuild(guild))); diff --git a/src/services/config.ts b/src/services/config.ts index cd56915..1b4f4c9 100644 --- a/src/services/config.ts +++ b/src/services/config.ts @@ -17,6 +17,10 @@ const CONFIG_MAP = { DATA_DIR, 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_URL: process.env.BOT_ACTIVITY_URL ?? '', + BOT_ACTIVITY: process.env.BOT_ACTIVITY ?? 'music', } as const; @injectable() @@ -29,6 +33,10 @@ 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_ACTIVITY_URL!: string; + readonly BOT_ACTIVITY!: string; constructor() { for (const [key, value] of Object.entries(CONFIG_MAP)) { |
