mirror of
https://github.com/BluemediaDev/muse.git
synced 2025-05-09 19:51:36 +02: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
5 changed files with 67 additions and 2 deletions
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 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)));
|
||||
|
|
|
@ -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)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue