From f5c1cb71a6bf0a493ac604446a7f075b4d0006a2 Mon Sep 17 00:00:00 2001 From: Manuel Ruwe Date: Fri, 16 Dec 2022 14:15:32 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20status=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/command.module.ts | 3 +- src/commands/help.command.ts | 37 ++---------------------- src/commands/status.command.ts | 52 ++++++++++++++++++++++++++++++++++ src/types/colors.ts | 3 ++ 4 files changed, 60 insertions(+), 35 deletions(-) create mode 100644 src/commands/status.command.ts create mode 100644 src/types/colors.ts diff --git a/src/commands/command.module.ts b/src/commands/command.module.ts index e816157..a6f6066 100644 --- a/src/commands/command.module.ts +++ b/src/commands/command.module.ts @@ -2,11 +2,12 @@ import { Module } from '@nestjs/common'; import { DiscordModule } from '@discord-nestjs/core'; import { HelpCommand } from './help.command'; +import { StatusCommand } from './status.command'; @Module({ imports: [DiscordModule.forFeature()], controllers: [], - providers: [HelpCommand], + providers: [HelpCommand, StatusCommand], exports: [], }) export class CommandModule {} diff --git a/src/commands/help.command.ts b/src/commands/help.command.ts index b011fbc..f909a06 100644 --- a/src/commands/help.command.ts +++ b/src/commands/help.command.ts @@ -8,10 +8,11 @@ import { } from '@discord-nestjs/core'; import { EmbedBuilder } from '@discordjs/builders'; import { InteractionReplyOptions, MessagePayload } from 'discord.js'; +import { DefaultJellyfinColor } from 'src/types/colors'; @Command({ name: 'help', - description: 'ejifejf', + description: 'Get help if you're having problems with this bot', }) @UsePipes(TransformPipe) export class HelpCommand implements DiscordTransformedCommand { @@ -33,6 +34,7 @@ export class HelpCommand implements DiscordTransformedCommand { 'https://github.com/walkxcode/dashboard-icons/blob/main/png/jellyfin.png?raw=true', url: 'https://github.com/manuel-rw/jellyfin-discord-music-bot', }) + .setColor(DefaultJellyfinColor) .setTitle('Help Information') .setDescription( 'Jellyfin Discord Music bot is an easy way to broadcast your music collection to a Discord voicechannel.', @@ -54,37 +56,4 @@ export class HelpCommand implements DiscordTransformedCommand { ], }; } - - /* - handler( - dto: unknown, - executionContext: TransformedCommandExecutionContext, - ) { - return new EmbedBuilder() - .setAuthor({ - name: 'Jellyfin Discord Bot', - iconURL: - 'https://github.com/walkxcode/dashboard-icons/blob/main/png/jellyfin.png?raw=true', - url: 'https://github.com/manuel-rw/jellyfin-discord-music-bot', - }) - .setTitle('Help Information') - .setDescription( - 'Jellyfin Discord Music bot is an easy way to broadcast your music collection to a Discord voicechannel.', - ) - .addFields([ - { - name: 'Report an issue', - value: - 'https://github.com/manuel-rw/jellyfin-discord-music-bot/issues/new/choose', - inline: true, - }, - { - name: 'Source code', - value: 'https://github.com/manuel-rw/jellyfin-discord-music-bot', - inline: true, - }, - ]) - .toJSON(); - } - */ } diff --git a/src/commands/status.command.ts b/src/commands/status.command.ts new file mode 100644 index 0000000..a478e8d --- /dev/null +++ b/src/commands/status.command.ts @@ -0,0 +1,52 @@ +import { TransformPipe } from '@discord-nestjs/common'; + +import { + Command, + DiscordTransformedCommand, + InjectDiscordClient, + TransformedCommandExecutionContext, + UsePipes, +} from '@discord-nestjs/core'; +import { EmbedBuilder } from '@discordjs/builders'; +import { Client, InteractionReplyOptions } from 'discord.js'; +import { DefaultJellyfinColor } from 'src/types/colors'; + +@Command({ + name: 'status', + description: 'Display the current status for troubleshooting', +}) +@UsePipes(TransformPipe) +export class StatusCommand implements DiscordTransformedCommand { + constructor( + @InjectDiscordClient() + private readonly client: Client, + ) {} + + handler( + dto: unknown, + executionContext: TransformedCommandExecutionContext, + ): InteractionReplyOptions { + const ping = this.client.ws.ping; + + return { + embeds: [ + new EmbedBuilder() + .setTitle('Online and ready') + .setColor(DefaultJellyfinColor) + .addFields([ + { + name: 'Ping', + value: `${ping}ms`, + inline: true, + }, + { + name: 'Source code', + value: 'https://github.com/manuel-rw/jellyfin-discord-music-bot', + inline: true, + }, + ]) + .toJSON(), + ], + }; + } +} diff --git a/src/types/colors.ts b/src/types/colors.ts new file mode 100644 index 0000000..8c64332 --- /dev/null +++ b/src/types/colors.ts @@ -0,0 +1,3 @@ +import { RGBTuple } from 'discord.js'; + +export const DefaultJellyfinColor: RGBTuple = [119, 116, 204];