Add a check cmd
This commit is contained in:
parent
ca046bd709
commit
9057229157
5 changed files with 106 additions and 3 deletions
|
|
@ -37,6 +37,39 @@
|
||||||
"title": "**Dynmap for {{SERVER}}**",
|
"title": "**Dynmap for {{SERVER}}**",
|
||||||
"description": ["{{LINK}}"]
|
"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": {
|
"helpContactSupport": {
|
||||||
"title": "Help - {{REF:helpOptions.contactSupport}}",
|
"title": "Help - {{REF:helpOptions.contactSupport}}",
|
||||||
"description": [
|
"description": [
|
||||||
|
|
@ -216,7 +249,8 @@
|
||||||
"info": "info",
|
"info": "info",
|
||||||
"test": "test",
|
"test": "test",
|
||||||
"howtojoin": "howtojoin",
|
"howtojoin": "howtojoin",
|
||||||
"map": "map"
|
"map": "map",
|
||||||
|
"checkstatus": "check"
|
||||||
},
|
},
|
||||||
"userCommands": {
|
"userCommands": {
|
||||||
"viewDateJoined": "View Date Joined"
|
"viewDateJoined": "View Date Joined"
|
||||||
|
|
@ -236,7 +270,8 @@
|
||||||
"info": "View bot info.",
|
"info": "View bot info.",
|
||||||
"test": "Run the test command.",
|
"test": "Run the test command.",
|
||||||
"howtojoin": "How To Join.",
|
"howtojoin": "How To Join.",
|
||||||
"map": "The dynmap for the server."
|
"map": "The dynmap for the server.",
|
||||||
|
"checkstatus": "Check the servers status."
|
||||||
},
|
},
|
||||||
"argDescs": {
|
"argDescs": {
|
||||||
"devCommand": "Command.",
|
"devCommand": "Command.",
|
||||||
|
|
|
||||||
|
|
@ -4,3 +4,4 @@ export { InfoCommand } from './info-command.js';
|
||||||
export { TestCommand } from './test-command.js';
|
export { TestCommand } from './test-command.js';
|
||||||
export { HowToJoinCommand } from './information/howtojoin-command.js';
|
export { HowToJoinCommand } from './information/howtojoin-command.js';
|
||||||
export { MapCommand } from './information/map-command.js';
|
export { MapCommand } from './information/map-command.js';
|
||||||
|
export { CheckCommand } from './information/check-command.js';
|
||||||
|
|
|
||||||
56
src/commands/chat/information/check-command.ts
Normal file
56
src/commands/chat/information/check-command.ts
Normal 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,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -69,6 +69,15 @@ export const ChatCommandMetadata: {
|
||||||
dm_permission: true,
|
dm_permission: true,
|
||||||
default_member_permissions: undefined,
|
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: {
|
HOWTOJOIN: {
|
||||||
type: ApplicationCommandType.ChatInput,
|
type: ApplicationCommandType.ChatInput,
|
||||||
name: Lang.getRef('chatCommands.howtojoin', Language.Default),
|
name: Lang.getRef('chatCommands.howtojoin', Language.Default),
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,8 @@ import {
|
||||||
InfoCommand,
|
InfoCommand,
|
||||||
TestCommand,
|
TestCommand,
|
||||||
HowToJoinCommand,
|
HowToJoinCommand,
|
||||||
MapCommand
|
MapCommand,
|
||||||
|
CheckCommand,
|
||||||
} from './commands/chat/index.js';
|
} from './commands/chat/index.js';
|
||||||
import {
|
import {
|
||||||
ChatCommandMetadata,
|
ChatCommandMetadata,
|
||||||
|
|
@ -77,6 +78,7 @@ async function start(): Promise<void> {
|
||||||
// TODO: Add new commands here
|
// TODO: Add new commands here
|
||||||
new HowToJoinCommand(),
|
new HowToJoinCommand(),
|
||||||
new MapCommand(),
|
new MapCommand(),
|
||||||
|
new CheckCommand(),
|
||||||
];
|
];
|
||||||
|
|
||||||
// Buttons
|
// Buttons
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue