Files
blitzkit/packages/bot/src/commands/ping.ts
T

34 lines
1.1 KiB
TypeScript
Raw Normal View History

2025-01-16 13:48:13 -06:00
import { literals } from '@blitzkit/i18n';
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({
handlesInteraction: true,
2023-06-17 18:16:41 +00:00
2024-03-08 20:29:35 -06:00
command: createLocalizedCommand('ping', [
2024-04-23 10:19:32 -05:00
{ subcommand: 'blitzkit' },
2024-03-08 20:29:35 -06:00
{ subcommand: 'wotb' },
]),
2023-06-17 18:16:41 +00:00
2024-03-06 15:34:10 -06:00
async handler(interaction) {
2025-01-16 13:48:13 -06:00
const { strings } = 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-04-23 10:19:32 -05:00
if (subcommand === 'blitzkit') {
2025-01-16 13:48:13 -06:00
await interaction.editReply(strings.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(
2025-01-16 13:48:13 -06:00
literals(strings.bot.commands.ping.body.pong_with_time, [
2024-03-08 20:29:35 -06:00
`${Math.round(executionTime)}`,
]),
);
2024-03-06 15:34:10 -06:00
},
});
});