diff --git a/package.json b/package.json index 77a21b0..388906b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nexus-bot-typescript", - "version": "3.8.1", + "version": "3.8.2", "description": "A Discord bot for Nexus Mods, written in TypeScript", "main": "dist/app.js", "scripts": { diff --git a/src/api/DiscordBotUser.ts b/src/api/DiscordBotUser.ts index c347a5a..45a2e90 100644 --- a/src/api/DiscordBotUser.ts +++ b/src/api/DiscordBotUser.ts @@ -183,7 +183,7 @@ export class DiscordBotUser { // Mod stats from the static CSV files. ModDownloads: async (gameId: number, modId?: number) => other.ModDownloads(gameId, modId), SiteStats: async () => other.SiteStats(this.headers()), - WebsiteStatus: async (full: boolean) => other.WebsiteStatus(this.headers(), full), + WebsiteStatus: async (full: boolean = false) => other.WebsiteStatus(this.headers(), full), } } } diff --git a/src/api/queries/other.ts b/src/api/queries/other.ts index 9fa5b65..53e1b91 100644 --- a/src/api/queries/other.ts +++ b/src/api/queries/other.ts @@ -167,14 +167,14 @@ export async function ModDownloads(gameId: number = -1, modId: number = -1): Pro } } -export async function WebsiteStatus(headers: Record, full: B): Promise > { +export async function WebsiteStatus(headers: Record, full: B): Promise > { try { const response = await axios({ url: full ? nexusModsFullStatus : nexusModsStatus, transformResponse: (res) => JSON.parse(res), headers, }); - return response.data as StatusPageResponse; + return response.data; } catch(err) { logMessage('Error fetching Nexus Mods status page data', err, true); diff --git a/src/interactions/status.ts b/src/interactions/status.ts new file mode 100644 index 0000000..a372561 --- /dev/null +++ b/src/interactions/status.ts @@ -0,0 +1,44 @@ +import {ChatInputCommandInteraction, CommandInteraction, EmbedBuilder, PermissionFlagsBits, SlashCommandBuilder } from "discord.js"; +import { DiscordInteraction, ClientExt } from "../types/DiscordTypes"; +import { getUserByDiscordId } from '../api/bot-db'; +import { DiscordBotUser, DummyNexusModsUser } from "../api/DiscordBotUser"; +import { IStatusPageFullResponse } from "../types/util"; + +const discordInteraction: DiscordInteraction = { + command: new SlashCommandBuilder() + .setName('status') + .setDescription('Check the status of the Nexus Mods website and services.') + .setDefaultMemberPermissions(PermissionFlagsBits.Administrator), + public: false, + guilds: [ + '581095546291355649', + '268004475510325248', + + ], + action +} + +async function action(client: ClientExt, baseInteraction: CommandInteraction): Promise { + const interaction = (baseInteraction as ChatInputCommandInteraction); + await interaction.deferReply({ ephemeral: true }); + const discordId = interaction.user.id; + const botuser: DiscordBotUser = await getUserByDiscordId(discordId) ?? new DiscordBotUser(DummyNexusModsUser); + + try { + const statusPage: IStatusPageFullResponse = await botuser.NexusMods.API.Other.WebsiteStatus(true) as IStatusPageFullResponse; + const embed = new EmbedBuilder() + .setTitle('Nexus Mods Status - '+statusPage.status.indicator) + .setDescription(statusPage.status.description) + .addFields( + statusPage.components.map(c => ({ + name: c.name, + value: c.description, + inline: false, + })) + ); + return interaction.editReply({ embeds: [embed] }); + } + catch(err) { + throw err; + } +} \ No newline at end of file diff --git a/src/types/util.ts b/src/types/util.ts index 1629899..8d5c4f3 100644 --- a/src/types/util.ts +++ b/src/types/util.ts @@ -193,7 +193,7 @@ export interface IBadFileRule { flagMessage: string; } -export type StatusPageResponse = T extends true ? IStatusPageFullResponse : IStatusPageQuickResponse; +export type StatusPageResponse = T extends true ? IStatusPageFullResponse : IStatusPageQuickResponse; interface IStatusPageQuickResponse { page: { @@ -209,7 +209,7 @@ interface IStatusPageQuickResponse { } } -interface IStatusPageFullResponse extends IStatusPageQuickResponse { +export interface IStatusPageFullResponse extends IStatusPageQuickResponse { components: IStatusPageComponent[]; incidents: IStatusPageIncident[]; scheduled_maintenances: IStatusPageIncident[];