Files
blitzkit/src/commands/ping.ts
T

35 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-03-08 20:29:35 -06:00
import { createLocalizedCommand } from '../core/discord/createLocalizedCommand';
import { translator } from '../core/localization/translator';
2023-07-11 19:54:57 +00:00
import { CommandRegistry } from '../events/interactionCreate';
2023-06-17 18:16:41 +00:00
2024-03-06 15:34:10 -06:00
export const pingCommand = new Promise<CommandRegistry>((resolve) => {
resolve({
inProduction: true,
inPublic: true,
handlesInteraction: true,
2023-06-17 18:16:41 +00:00
2024-03-08 20:29:35 -06:00
command: createLocalizedCommand('ping', [
{ subcommand: 'blitzkrieg' },
{ subcommand: 'wotb' },
]),
2023-06-17 18:16:41 +00:00
2024-03-06 15:34:10 -06:00
async handler(interaction) {
2024-03-08 20:29:35 -06:00
const { t, translate } = translator(interaction.locale);
2024-03-06 15:34:10 -06:00
const subcommand = interaction.options.getSubcommand();
const executionStart = Date.now();
2023-06-23 17:10:18 +00:00
2024-03-06 15:34:10 -06:00
if (subcommand === 'blitzkrieg') {
2024-03-08 20:29:35 -06:00
await interaction.editReply(t`bot.commands.ping.body.pong`);
2024-03-06 15:34:10 -06:00
} else {
await fetch('https://api.wotblitz.com/');
}
2023-06-23 17:10:18 +00:00
2024-03-06 15:34:10 -06:00
const executionTime = Date.now() - executionStart;
2024-03-08 20:29:35 -06:00
interaction.editReply(
translate('bot.commands.ping.body.pong_with_time', [
`${Math.round(executionTime)}`,
]),
);
2024-03-06 15:34:10 -06:00
},
});
});