aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZagrthos <[email protected]>2022-03-25 00:19:48 +0100
committerGitHub <[email protected]>2022-03-24 18:19:48 -0500
commit2f9382f5171717fa512c03b3a3c08bd15ae85dd7 (patch)
treed377ed5d0fbb68e682b22b064a4eac705e228475 /src
parentcf4905337005768644178d46c744cfdc90bef7ff (diff)
downloadmuse-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.ts16
-rw-r--r--src/services/config.ts8
2 files changed, 23 insertions, 1 deletions
diff --git a/src/bot.ts b/src/bot.ts
index 5803a64..37be7f9 100644
--- a/src/bot.ts
+++ b/src/bot.ts
@@ -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)) {