Add a check cmd

This commit is contained in:
DIVISIONSolar 2023-09-11 16:49:23 -04:00
parent ca046bd709
commit 9057229157
No known key found for this signature in database
GPG key ID: CA10B18BED096A06
5 changed files with 106 additions and 3 deletions

View file

@ -37,6 +37,39 @@
"title": "**Dynmap for {{SERVER}}**",
"description": ["{{LINK}}"]
},
"checkresponse": {
"title": "Status for {{HOSTNAME}}",
"fields": [
{
"name": "**HOSTNAME**",
"value": "```{{HOSTNAME}}```"
},
{
"name": "**PLAYERS**",
"value": "```{{PLAYERS}}```"
},
{
"name": "**VERSION**",
"value": "```{{VERSION}}```"
},
{
"name": "**MOTD**",
"value": "```{{MOTD}}```"
},
{
"name": "**STATUS**",
"value": "```Online: {{ONLINE}}```"
},
{
"name": "**PING**",
"value": "```{{PING}}```"
},
{
"name": "**QUERY**",
"value": "```{{QUERY}}```"
}
]
},
"helpContactSupport": {
"title": "Help - {{REF:helpOptions.contactSupport}}",
"description": [
@ -216,7 +249,8 @@
"info": "info",
"test": "test",
"howtojoin": "howtojoin",
"map": "map"
"map": "map",
"checkstatus": "check"
},
"userCommands": {
"viewDateJoined": "View Date Joined"
@ -236,7 +270,8 @@
"info": "View bot info.",
"test": "Run the test command.",
"howtojoin": "How To Join.",
"map": "The dynmap for the server."
"map": "The dynmap for the server.",
"checkstatus": "Check the servers status."
},
"argDescs": {
"devCommand": "Command.",

View file

@ -4,3 +4,4 @@ export { InfoCommand } from './info-command.js';
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';

View file

@ -0,0 +1,56 @@
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 CheckCommand implements Command {
public names = [Lang.getRef('chatCommands.checkstatus', Language.Default)]; // Change the command name as needed
public cooldown = new RateLimiter(1, 5000);
public deferType = CommandDeferType.PUBLIC;
public requireClientPerms: PermissionsString[] = [];
public async execute(intr: ChatInputCommandInteraction, data: EventData): Promise<void> {
// Construct the request URL
const url = 'https://api.mcsrvstat.us/2/play.pxlvrs.net';
try {
// Make the HTTP GET request
const response = await axios.get(url, {
headers: {
'User-Agent': 'PixelVerse Helper, me@joshsevero.dev',
},
});
const serverInfo = response.data;
await InteractionUtils.send(
intr,
Lang.getEmbed('displayEmbeds.checkresponse', data.lang, {
IP: serverInfo.ip,
HOSTNAME: serverInfo.hostname || 'N/A',
PLAYERS: serverInfo.players
? `${serverInfo.players.online}/${serverInfo.players.max}`
: 'N/A',
VERSION: serverInfo.version || 'N/A',
MOTD: serverInfo.motd ? serverInfo.motd.clean : 'N/A',
ONLINE: serverInfo.online || 'N/A',
PING: serverInfo.ping || 'N/A',
QUERY: serverInfo.query || 'N/A',
})
);
} catch (error) {
console.error(error);
// Handle error if the request fails
await InteractionUtils.send(
intr,
Lang.getEmbed('errorEmbeds.command', data.lang, {
ERROR_CODE: error.code,
})
);
}
}
}

View file

@ -69,6 +69,15 @@ export const ChatCommandMetadata: {
dm_permission: true,
default_member_permissions: undefined,
},
CHECKSTATUS: {
type: ApplicationCommandType.ChatInput,
name: Lang.getRef('chatCommands.checkstatus', Language.Default),
name_localizations: Lang.getRefLocalizationMap('chatCommands.checkstatus'),
description: Lang.getRef('commandDescs.checkstatus', Language.Default),
description_localizations: Lang.getRefLocalizationMap('commandDescs.checkstatus'),
dm_permission: true,
default_member_permissions: undefined,
},
HOWTOJOIN: {
type: ApplicationCommandType.ChatInput,
name: Lang.getRef('chatCommands.howtojoin', Language.Default),

View file

@ -9,7 +9,8 @@ import {
InfoCommand,
TestCommand,
HowToJoinCommand,
MapCommand
MapCommand,
CheckCommand,
} from './commands/chat/index.js';
import {
ChatCommandMetadata,
@ -77,6 +78,7 @@ async function start(): Promise<void> {
// TODO: Add new commands here
new HowToJoinCommand(),
new MapCommand(),
new CheckCommand(),
];
// Buttons