Skip to content

Commit

Permalink
Added status command.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pickysaurus committed Jan 30, 2025
1 parent 4eea292 commit 732f0aa
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/api/DiscordBotUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/api/queries/other.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@ export async function ModDownloads(gameId: number = -1, modId: number = -1): Pro
}
}

export async function WebsiteStatus<B>(headers: Record<string, string>, full: B): Promise <StatusPageResponse<B>> {
export async function WebsiteStatus<B extends boolean>(headers: Record<string, string>, full: B): Promise <StatusPageResponse<B>> {
try {
const response = await axios({
url: full ? nexusModsFullStatus : nexusModsStatus,
transformResponse: (res) => JSON.parse(res),
headers,
});
return response.data as StatusPageResponse<B>;
return response.data;
}
catch(err) {
logMessage('Error fetching Nexus Mods status page data', err, true);
Expand Down
44 changes: 44 additions & 0 deletions src/interactions/status.ts
Original file line number Diff line number Diff line change
@@ -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<any> {
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;
}
}
4 changes: 2 additions & 2 deletions src/types/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export interface IBadFileRule {
flagMessage: string;
}

export type StatusPageResponse<T> = T extends true ? IStatusPageFullResponse : IStatusPageQuickResponse;
export type StatusPageResponse<T extends boolean> = T extends true ? IStatusPageFullResponse : IStatusPageQuickResponse;

interface IStatusPageQuickResponse {
page: {
Expand All @@ -209,7 +209,7 @@ interface IStatusPageQuickResponse {
}
}

interface IStatusPageFullResponse extends IStatusPageQuickResponse {
export interface IStatusPageFullResponse extends IStatusPageQuickResponse {
components: IStatusPageComponent[];
incidents: IStatusPageIncident[];
scheduled_maintenances: IStatusPageIncident[];
Expand Down

0 comments on commit 732f0aa

Please sign in to comment.