mirror of
https://github.com/BluemediaGER/muse.git
synced 2024-11-22 16:55:30 +01:00
Add customizable Bot status (#599)
Co-authored-by: Max Isom <codetheweb@users.noreply.github.com> Co-authored-by: Max Isom <hi@maxisom.me>
This commit is contained in:
parent
cf49053370
commit
2f9382f517
11
.env.example
11
.env.example
|
@ -4,5 +4,14 @@ YOUTUBE_API_KEY=
|
||||||
SPOTIFY_CLIENT_ID=
|
SPOTIFY_CLIENT_ID=
|
||||||
SPOTIFY_CLIENT_SECRET=
|
SPOTIFY_CLIENT_SECRET=
|
||||||
|
|
||||||
# Optional
|
############
|
||||||
|
# Optional #
|
||||||
|
############
|
||||||
|
|
||||||
# CACHE_LIMIT=2GB
|
# CACHE_LIMIT=2GB
|
||||||
|
|
||||||
|
# See the README for details on the below variables
|
||||||
|
# BOT_STATUS=
|
||||||
|
# BOT_ACTIVITY_TYPE=
|
||||||
|
# BOT_ACTIVITY_URL=
|
||||||
|
# BOT_ACTIVITY=
|
||||||
|
|
|
@ -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).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
### Added
|
||||||
|
- Added a configurable bot status with user defined activities
|
||||||
### Fixed
|
### Fixed
|
||||||
- Error messages consistently show as `🚫 ope: error`
|
- Error messages consistently show as `🚫 ope: error`
|
||||||
|
|
||||||
|
|
32
README.md
32
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`.
|
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
|
### 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`.
|
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`.
|
||||||
|
|
16
src/bot.ts
16
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 {inject, injectable} from 'inversify';
|
||||||
import ora from 'ora';
|
import ora from 'ora';
|
||||||
import {TYPES} from './types.js';
|
import {TYPES} from './types.js';
|
||||||
|
@ -15,10 +15,12 @@ import {generateDependencyReport} from '@discordjs/voice';
|
||||||
import {REST} from '@discordjs/rest';
|
import {REST} from '@discordjs/rest';
|
||||||
import {Routes} from 'discord-api-types/v9';
|
import {Routes} from 'discord-api-types/v9';
|
||||||
import updatePermissionsForGuild from './utils/update-permissions-for-guild.js';
|
import updatePermissionsForGuild from './utils/update-permissions-for-guild.js';
|
||||||
|
import {ActivityTypes} from 'discord.js/typings/enums';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export default class {
|
export default class {
|
||||||
private readonly client: Client;
|
private readonly client: Client;
|
||||||
|
private readonly config: Config;
|
||||||
private readonly token: string;
|
private readonly token: string;
|
||||||
private readonly shouldRegisterCommandsOnBot: boolean;
|
private readonly shouldRegisterCommandsOnBot: boolean;
|
||||||
private readonly commandsByName!: Collection<string, Command>;
|
private readonly commandsByName!: Collection<string, Command>;
|
||||||
|
@ -29,6 +31,7 @@ export default class {
|
||||||
@inject(TYPES.Config) config: Config,
|
@inject(TYPES.Config) config: Config,
|
||||||
) {
|
) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
this.config = config;
|
||||||
this.token = config.DISCORD_TOKEN;
|
this.token = config.DISCORD_TOKEN;
|
||||||
this.shouldRegisterCommandsOnBot = config.REGISTER_COMMANDS_ON_BOT;
|
this.shouldRegisterCommandsOnBot = config.REGISTER_COMMANDS_ON_BOT;
|
||||||
this.commandsByName = new Collection();
|
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
|
// Update permissions
|
||||||
spinner.text = '📡 updating permissions...';
|
spinner.text = '📡 updating permissions...';
|
||||||
await Promise.all(this.client.guilds.cache.map(async guild => updatePermissionsForGuild(guild)));
|
await Promise.all(this.client.guilds.cache.map(async guild => updatePermissionsForGuild(guild)));
|
||||||
|
|
|
@ -17,6 +17,10 @@ const CONFIG_MAP = {
|
||||||
DATA_DIR,
|
DATA_DIR,
|
||||||
CACHE_DIR: path.join(DATA_DIR, 'cache'),
|
CACHE_DIR: path.join(DATA_DIR, 'cache'),
|
||||||
CACHE_LIMIT_IN_BYTES: xbytes.parseSize(process.env.CACHE_LIMIT ?? '2GB'),
|
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;
|
} as const;
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
|
@ -29,6 +33,10 @@ export default class Config {
|
||||||
readonly DATA_DIR!: string;
|
readonly DATA_DIR!: string;
|
||||||
readonly CACHE_DIR!: string;
|
readonly CACHE_DIR!: string;
|
||||||
readonly CACHE_LIMIT_IN_BYTES!: number;
|
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() {
|
constructor() {
|
||||||
for (const [key, value] of Object.entries(CONFIG_MAP)) {
|
for (const [key, value] of Object.entries(CONFIG_MAP)) {
|
||||||
|
|
Loading…
Reference in a new issue