Add command to view ups status
This commit is contained in:
parent
9057229157
commit
c41079584c
6 changed files with 148 additions and 4 deletions
|
|
@ -70,6 +70,31 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"apcstatus": {
|
||||
"title": "Status for {{SERVER}}",
|
||||
"fields": [
|
||||
{
|
||||
"name": "**MODEL**",
|
||||
"value": "```{{MODEL}}```"
|
||||
},
|
||||
{
|
||||
"name": "**STATUS**",
|
||||
"value": "```{{STATUS}}```"
|
||||
},
|
||||
{
|
||||
"name": "**BCHARGE**",
|
||||
"value": "```{{BCHARGE}}```"
|
||||
},
|
||||
{
|
||||
"name": "**TIMELEFT**",
|
||||
"value": "```{{TIMELEFT}}```"
|
||||
},
|
||||
{
|
||||
"name": "**STATUS**",
|
||||
"value": "```{{STATUS}}```"
|
||||
}
|
||||
]
|
||||
},
|
||||
"helpContactSupport": {
|
||||
"title": "Help - {{REF:helpOptions.contactSupport}}",
|
||||
"description": [
|
||||
|
|
@ -250,7 +275,8 @@
|
|||
"test": "test",
|
||||
"howtojoin": "howtojoin",
|
||||
"map": "map",
|
||||
"checkstatus": "check"
|
||||
"checkstatus": "check",
|
||||
"upsstatus": "upstats"
|
||||
},
|
||||
"userCommands": {
|
||||
"viewDateJoined": "View Date Joined"
|
||||
|
|
@ -262,7 +288,8 @@
|
|||
"command": "command",
|
||||
"option": "option",
|
||||
"platform": "platform",
|
||||
"server": "server"
|
||||
"server": "server",
|
||||
"upslocation": "location"
|
||||
},
|
||||
"commandDescs": {
|
||||
"dev": "Developer use only.",
|
||||
|
|
@ -271,14 +298,16 @@
|
|||
"test": "Run the test command.",
|
||||
"howtojoin": "How To Join.",
|
||||
"map": "The dynmap for the server.",
|
||||
"checkstatus": "Check the servers status."
|
||||
"checkstatus": "Check the servers status.",
|
||||
"upsstatus": "UPS Status."
|
||||
},
|
||||
"argDescs": {
|
||||
"devCommand": "Command.",
|
||||
"helpOption": "Option.",
|
||||
"infoOption": "Option.",
|
||||
"platform": "Ex. PC, Xbox, Playstation, Mobile.",
|
||||
"server": "The server's name"
|
||||
"server": "The server's name",
|
||||
"upslocation": "Location you wish to check. (Avail: pxlvrs.net, network)"
|
||||
},
|
||||
"fields": {
|
||||
"commands": "Commands",
|
||||
|
|
|
|||
|
|
@ -71,4 +71,11 @@ export class Args {
|
|||
description_localizations: Lang.getRefLocalizationMap('argDescs.server'),
|
||||
type: ApplicationCommandOptionType.String,
|
||||
};
|
||||
public static readonly upslocation: APIApplicationCommandBasicOption = {
|
||||
name: Lang.getRef('arguments.upslocation', Language.Default),
|
||||
name_localizations: Lang.getRefLocalizationMap('arguments.upslocation'),
|
||||
description: Lang.getRef('argDescs.upslocation', Language.Default),
|
||||
description_localizations: Lang.getRefLocalizationMap('argDescs.upslocation'),
|
||||
type: ApplicationCommandOptionType.String,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,3 +5,4 @@ export { TestCommand } from './test-command.js';
|
|||
export { HowToJoinCommand } from './information/howtojoin-command.js';
|
||||
export { MapCommand } from './information/map-command.js';
|
||||
export { CheckCommand } from './information/check-command.js';
|
||||
export { UpsStatusCommand } from './information/upsstats-command.js';
|
||||
90
src/commands/chat/information/upsstats-command.ts
Normal file
90
src/commands/chat/information/upsstats-command.ts
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
import { ChatInputCommandInteraction, PermissionsString } from 'discord.js';
|
||||
import { RateLimiter } from 'discord.js-rate-limiter';
|
||||
import axios from 'axios';
|
||||
import { Language } from '../../../models/enum-helpers/index.js';
|
||||
import { EventData } from '../../../models/internal-models.js';
|
||||
import { Lang } from '../../../services/index.js';
|
||||
import { InteractionUtils } from '../../../utils/index.js';
|
||||
import { Command, CommandDeferType } from '../../index.js';
|
||||
|
||||
export class UpsStatusCommand implements Command {
|
||||
public names = [Lang.getRef('chatCommands.upsstatus', Language.Default)];
|
||||
public cooldown = new RateLimiter(1, 5000);
|
||||
public deferType = CommandDeferType.PUBLIC;
|
||||
public requireClientPerms: PermissionsString[] = [];
|
||||
|
||||
public async execute(intr: ChatInputCommandInteraction, data: EventData): Promise<void> {
|
||||
let args = {
|
||||
location: intr.options.getString(
|
||||
Lang.getRef('arguments.upslocation', Language.Default)
|
||||
),
|
||||
};
|
||||
|
||||
let url = '';
|
||||
|
||||
// Determine the URL based on the location argument
|
||||
if (args.location.toLowerCase() === 'pxlvrs.net') {
|
||||
url = 'https://na-pa-01.joshseveros.cloud/cgi-bin/apcupsd/upsfstats.cgi?host=127.0.0.1';
|
||||
} else if (args.location.toLowerCase() === 'network') {
|
||||
url = 'https://na-pa-04.joshseveros.cloud/cgi-bin/apcupsd/upsfstats.cgi?host=127.0.0.1';
|
||||
} else {
|
||||
await InteractionUtils.send(
|
||||
intr,
|
||||
Lang.getEmbed('errorEmbeds.command', data.lang, {
|
||||
"ERROR_CODE": "Invalid location argument",
|
||||
})
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await axios.get(url, {
|
||||
headers: {
|
||||
'User-Agent': 'pxlvrs.net, me@joshsevero.dev',
|
||||
}
|
||||
});
|
||||
|
||||
// Assuming the response contains the APC status in text format
|
||||
const apcStatusText = response.data;
|
||||
|
||||
// Now you can process the apcStatusText to extract the desired information
|
||||
// For example, you can split the text by lines and extract specific fields
|
||||
|
||||
// Example extraction:
|
||||
const lines = apcStatusText.split('\n');
|
||||
const modelLine = lines.find(line => line.startsWith('MODEL'));
|
||||
const model = modelLine.split(':')[1].trim();
|
||||
|
||||
// Extracting BCHARGE and TIMELEFT
|
||||
const bchargeLine = lines.find(line => line.startsWith('BCHARGE'));
|
||||
const bcharge = bchargeLine.split(':')[1].trim();
|
||||
|
||||
const timeleftLine = lines.find(line => line.startsWith('TIMELEFT'));
|
||||
const timeleft = timeleftLine.split(':')[1].trim();
|
||||
|
||||
// Extracting STATUS
|
||||
const statusLine = lines.find(line => line.startsWith('STATUS'));
|
||||
const status = statusLine.split(':')[1].trim();
|
||||
|
||||
await InteractionUtils.send(
|
||||
intr,
|
||||
Lang.getEmbed('displayEmbeds.apcstatus', data.lang, {
|
||||
SERVER: args.location,
|
||||
MODEL: model,
|
||||
BCHARGE: bcharge,
|
||||
TIMELEFT: timeleft,
|
||||
STATUS: status,
|
||||
// Add other extracted fields here...
|
||||
})
|
||||
);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
await InteractionUtils.send(
|
||||
intr,
|
||||
Lang.getEmbed('errorEmbeds.command', data.lang, {
|
||||
"ERROR_CODE": error.code,
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -108,6 +108,21 @@ export const ChatCommandMetadata: {
|
|||
},
|
||||
],
|
||||
},
|
||||
UPSLOCATION: {
|
||||
type: ApplicationCommandType.ChatInput,
|
||||
name: Lang.getRef('chatCommands.upsstatus', Language.Default),
|
||||
name_localizations: Lang.getRefLocalizationMap('chatCommands.upsstatus'),
|
||||
description: Lang.getRef('commandDescs.upsstatus', Language.Default),
|
||||
description_localizations: Lang.getRefLocalizationMap('commandDescs.upsstatus'),
|
||||
dm_permission: true,
|
||||
default_member_permissions: undefined,
|
||||
options: [
|
||||
{
|
||||
...Args.upslocation,
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
export const MessageCommandMetadata: {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import {
|
|||
HowToJoinCommand,
|
||||
MapCommand,
|
||||
CheckCommand,
|
||||
UpsStatusCommand,
|
||||
} from './commands/chat/index.js';
|
||||
import {
|
||||
ChatCommandMetadata,
|
||||
|
|
@ -79,6 +80,7 @@ async function start(): Promise<void> {
|
|||
new HowToJoinCommand(),
|
||||
new MapCommand(),
|
||||
new CheckCommand(),
|
||||
new UpsStatusCommand(),
|
||||
];
|
||||
|
||||
// Buttons
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue