2022-12-16 14:15:32 +01:00
|
|
|
import { TransformPipe } from '@discord-nestjs/common';
|
|
|
|
|
|
|
|
import {
|
|
|
|
Command,
|
2022-12-17 20:51:03 +01:00
|
|
|
DiscordCommand,
|
2022-12-16 14:15:32 +01:00
|
|
|
InjectDiscordClient,
|
2022-12-17 22:18:31 +01:00
|
|
|
UsePipes
|
2022-12-16 14:15:32 +01:00
|
|
|
} from '@discord-nestjs/core';
|
2022-12-17 20:51:03 +01:00
|
|
|
import {
|
|
|
|
Client,
|
|
|
|
CommandInteraction,
|
|
|
|
InteractionReplyOptions,
|
2022-12-17 22:18:31 +01:00
|
|
|
Status
|
2022-12-17 20:51:03 +01:00
|
|
|
} from 'discord.js';
|
2022-12-16 14:15:32 +01:00
|
|
|
|
2022-12-16 16:10:16 +01:00
|
|
|
import { formatDuration, intervalToDuration } from 'date-fns';
|
2022-12-17 20:51:03 +01:00
|
|
|
import { DiscordMessageService } from '../clients/discord/discord.message.service';
|
|
|
|
import { JellyfinService } from '../clients/jellyfin/jellyfin.service';
|
2022-12-16 21:21:26 +01:00
|
|
|
import { Constants } from '../utils/constants';
|
2022-12-16 16:10:16 +01:00
|
|
|
|
2022-12-17 20:51:03 +01:00
|
|
|
import { getSystemApi } from '@jellyfin/sdk/lib/utils/api/system-api';
|
|
|
|
|
2022-12-16 14:15:32 +01:00
|
|
|
@Command({
|
|
|
|
name: 'status',
|
|
|
|
description: 'Display the current status for troubleshooting',
|
|
|
|
})
|
|
|
|
@UsePipes(TransformPipe)
|
2022-12-17 20:51:03 +01:00
|
|
|
export class StatusCommand implements DiscordCommand {
|
2022-12-16 14:15:32 +01:00
|
|
|
constructor(
|
|
|
|
@InjectDiscordClient()
|
|
|
|
private readonly client: Client,
|
2022-12-17 20:51:03 +01:00
|
|
|
private readonly discordMessageService: DiscordMessageService,
|
|
|
|
private readonly jellyfinService: JellyfinService,
|
2022-12-16 14:15:32 +01:00
|
|
|
) {}
|
|
|
|
|
2022-12-17 20:51:03 +01:00
|
|
|
async handler(
|
|
|
|
commandInteraction: CommandInteraction,
|
|
|
|
): Promise<string | InteractionReplyOptions> {
|
2022-12-16 14:15:32 +01:00
|
|
|
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
|
|
|
|
2022-12-17 20:51:03 +01:00
|
|
|
const jellyfinSystemApi = getSystemApi(this.jellyfinService.getApi());
|
|
|
|
const jellyfinSystemInformation = await jellyfinSystemApi.getSystemInfo();
|
|
|
|
|
2022-12-16 14:15:32 +01:00
|
|
|
return {
|
|
|
|
embeds: [
|
2022-12-17 20:51:03 +01:00
|
|
|
this.discordMessageService.buildMessage({
|
|
|
|
title: 'Discord Bot Status',
|
|
|
|
mixin(embedBuilder) {
|
|
|
|
return embedBuilder.addFields([
|
|
|
|
{
|
|
|
|
name: 'Bot Version',
|
2022-12-19 11:57:04 +01:00
|
|
|
value: Constants.Metadata.Version.All(),
|
2022-12-17 20:51:03 +01:00
|
|
|
inline: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Discord Bot Ping',
|
|
|
|
value: `${ping}ms`,
|
|
|
|
inline: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Discord Bot Status',
|
|
|
|
value: `${status}`,
|
|
|
|
inline: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Discord Bot Uptime',
|
|
|
|
value: `${formattedDuration}`,
|
|
|
|
inline: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Jellyfin Server Version',
|
|
|
|
value: jellyfinSystemInformation.data.Version ?? 'unknown',
|
|
|
|
inline: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Jellyfin Server Operating System',
|
|
|
|
value:
|
|
|
|
jellyfinSystemInformation.data.OperatingSystem ?? 'unknown',
|
|
|
|
inline: true,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
}),
|
2022-12-16 14:15:32 +01:00
|
|
|
],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|