diff --git a/.env.example b/.env.example index 32a74a7..cfa8f2f 100644 --- a/.env.example +++ b/.env.example @@ -4,5 +4,14 @@ YOUTUBE_API_KEY= SPOTIFY_CLIENT_ID= SPOTIFY_CLIENT_SECRET= -# Optional +############ +# Optional # +############ + # CACHE_LIMIT=2GB + +# See the README for details on the below variables +# BOT_STATUS= +# BOT_ACTIVITY_TYPE= +# BOT_ACTIVITY_URL= +# BOT_ACTIVITY= diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fdb65c..72e0ab7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- Added a configurable bot status with user defined activities ### Fixed - Error messages consistently show as `🚫 ope: error` diff --git a/README.md b/README.md index a913b2f..a5fb580 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,38 @@ services: By default, Muse limits the total cache size to around 2 GB. If you want to change this, set the environment variable `CACHE_LIMIT`. For example, `CACHE_LIMIT=512MB` or `CACHE_LIMIT=10GB`. +### Custom Bot Status + +In the default state, Muse has the status "Online" and the text "Listening to Music". You can change the status through environment variables: + +- `BOT_STATUS`: + - `online` (Online) + - `idle` (Away) + - `dnd` (Do not Disturb) + +- `BOT_ACTIVITY_TYPE`: + - `PLAYING` (Playing XYZ) + - `LISTENING` (Listening to XYZ) + - `WATCHING` (Watching XYZ) + - `STREAMING` (Streaming XYZ) + +- `BOT_ACTIVITY`: the text that follows the activity type + +- `BOT_ACTIVITY_URL` If you use `STREAMING` you MUST set this variable, otherwise it will not work! Here you write a regular YouTube or Twitch Stream URL. + +#### Examples + +**Muse is watching a movie and is DND**: +- `BOT_STATUS=dnd` +- `BOT_ACTIVITY_TYPE=WATCHING` +- `BOT_ACTIVITY=a movie` + +**Muse is streaming Monstercat**: +- `BOT_STATUS=online` +- `BOT_ACTIVITY_TYPE=STREAMING` +- `BOT_ACTIVITY_URL=https://www.twitch.tv/monstercat` +- `BOT_ACTIVITY=Monstercat` + ### Bot-wide commands If you have Muse running in a lot of guilds (10+) you may want to switch to registering commands bot-wide rather than for each guild. (The downside to this is that command updates can take up to an hour to propagate.) To do this, set the environment variable `REGISTER_COMMANDS_ON_BOT` to `true`. 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; @@ -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, + 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)) {