discord-jellyfin-bot/src/commands/status.command.ts

73 lines
1.8 KiB
TypeScript
Raw Normal View History

2022-12-16 14:15:32 +01:00
import { TransformPipe } from '@discord-nestjs/common';
import {
Command,
DiscordTransformedCommand,
InjectDiscordClient,
TransformedCommandExecutionContext,
UsePipes,
} from '@discord-nestjs/core';
import { EmbedBuilder } from '@discordjs/builders';
2022-12-16 16:10:16 +01:00
import { Client, InteractionReplyOptions, Status } from 'discord.js';
2022-12-16 14:15:32 +01:00
import { DefaultJellyfinColor } from 'src/types/colors';
2022-12-16 16:10:16 +01:00
import { formatDuration, intervalToDuration } from 'date-fns';
import { Constants } from 'src/utils/constants';
2022-12-16 14:15:32 +01:00
@Command({
name: 'status',
description: 'Display the current status for troubleshooting',
})
@UsePipes(TransformPipe)
export class StatusCommand implements DiscordTransformedCommand<unknown> {
constructor(
@InjectDiscordClient()
private readonly client: Client,
) {}
handler(
dto: unknown,
executionContext: TransformedCommandExecutionContext<any>,
): InteractionReplyOptions {
const ping = this.client.ws.ping;
2022-12-16 16:10:16 +01:00
const status = Status[this.client.ws.status];
const interval = intervalToDuration({
start: this.client.uptime,
end: 0,
});
const formattedDuration = formatDuration(interval);
2022-12-16 14:15:32 +01:00
return {
embeds: [
new EmbedBuilder()
.setTitle('Online and ready')
.setColor(DefaultJellyfinColor)
.addFields([
2022-12-16 16:10:16 +01:00
{
name: 'Version',
value: Constants.Metadata.Version,
inline: false,
},
2022-12-16 14:15:32 +01:00
{
name: 'Ping',
value: `${ping}ms`,
inline: true,
},
{
2022-12-16 16:10:16 +01:00
name: 'Status',
value: `${status}`,
inline: true,
},
{
name: 'Uptime',
value: `${formattedDuration}`,
2022-12-16 14:15:32 +01:00
inline: true,
},
])
.toJSON(),
],
};
}
}