mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02:00
feat: update bot chunk 1
This commit is contained in:
1 parent
bb557a7dd7
commit
d2b24fc953
42 files changed
+370
-389
No files matched your search
@@ -2,7 +2,6 @@ import {
|
||||
ActionRowBuilder,
|
||||
AttachmentBuilder,
|
||||
ButtonBuilder,
|
||||
ButtonStyle,
|
||||
CacheType,
|
||||
ChatInputCommandInteraction,
|
||||
InteractionReplyOptions,
|
||||
@@ -14,7 +13,6 @@ import { normalizeInteractionReturnable } from '../../../core/discord/normalizeI
|
||||
import { psa } from '../../../core/discord/psa';
|
||||
import { translator } from '../../../core/localization/translator';
|
||||
import { Writeable } from '../../../types/writable';
|
||||
import { UserError } from '../../../core/blitzkit/userError';
|
||||
|
||||
export async function handleChatInputCommand(
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
@@ -127,27 +125,25 @@ export async function handleChatInputCommand(
|
||||
}
|
||||
} catch (error) {
|
||||
const { t } = translator(interaction.locale);
|
||||
const components = [
|
||||
new ActionRowBuilder<ButtonBuilder>().addComponents(
|
||||
new ButtonBuilder()
|
||||
.setLabel(t`bot.common.errors.get_help`)
|
||||
.setURL('https://discord.gg/nDt7AjGJQH')
|
||||
.setStyle(ButtonStyle.Link),
|
||||
),
|
||||
];
|
||||
|
||||
if (error instanceof UserError) {
|
||||
interaction.editReply({
|
||||
content: error.message,
|
||||
components,
|
||||
});
|
||||
} else {
|
||||
console.error(interaction.commandName, error);
|
||||
|
||||
interaction.editReply({
|
||||
content: t`bot.common.errors.uncaught_error`,
|
||||
components,
|
||||
});
|
||||
}
|
||||
// const components = [
|
||||
// new ActionRowBuilder<ButtonBuilder>().addComponents(
|
||||
// new ButtonBuilder()
|
||||
// .setLabel(t`bot.common.errors.get_help`)
|
||||
// .setURL('https://discord.gg/nDt7AjGJQH')
|
||||
// .setStyle(ButtonStyle.Link),
|
||||
// ),
|
||||
// ];
|
||||
// if (error instanceof UserError) {
|
||||
// interaction.editReply({
|
||||
// content: error.message,
|
||||
// components,
|
||||
// });
|
||||
// } else {
|
||||
// console.error(interaction.commandName, error);
|
||||
// interaction.editReply({
|
||||
// content: t`bot.common.errors.uncaught_error`,
|
||||
// components,
|
||||
// });
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import { assertSecret } from '@blitzkit/core';
|
||||
import {
|
||||
AttachmentBuilder,
|
||||
AutocompleteInteraction,
|
||||
@@ -8,35 +7,12 @@ import {
|
||||
ChatInputCommandInteraction,
|
||||
EmbedBuilder,
|
||||
Interaction,
|
||||
REST,
|
||||
Routes,
|
||||
SlashCommandBuilder,
|
||||
SlashCommandOptionsOnlyBuilder,
|
||||
SlashCommandSubcommandsOnlyBuilder,
|
||||
} from 'discord.js';
|
||||
import { aboutCommand } from '../../commands/about';
|
||||
import { auctionCommand } from '../../commands/auction';
|
||||
import { breakdownCommand } from '../../commands/breakdown';
|
||||
import { debugCommand } from '../../commands/debug';
|
||||
import { evolutionCommand } from '../../commands/evolution';
|
||||
import { fullStatsCommand } from '../../commands/fullStats';
|
||||
import { inactiveCommand } from '../../commands/inactive';
|
||||
import { verifyCommand } from '../../commands/link';
|
||||
import { ownedTanksCommand } from '../../commands/ownedTanks';
|
||||
import { permissionsCommand } from '../../commands/permissions';
|
||||
import { pingCommand } from '../../commands/ping';
|
||||
import { playerInfoCommand } from '../../commands/playerInfo';
|
||||
import { ratingCommand } from '../../commands/rating';
|
||||
import { ratingLeaderboardCommand } from '../../commands/ratingLeaderboard';
|
||||
import { replayCommand } from '../../commands/replay';
|
||||
import { researchCommand } from '../../commands/research';
|
||||
import { searchClansCommand } from '../../commands/searchClans';
|
||||
import { searchPlayersCommand } from '../../commands/searchPlayers';
|
||||
import { statsCommand } from '../../commands/stats';
|
||||
import { todayCommand } from '../../commands/today';
|
||||
import { RenderConfiguration } from '../../core/blitzkit/renderConfiguration';
|
||||
import { handleAutocomplete } from './handlers/autocomplete';
|
||||
import { handleButton } from './handlers/button';
|
||||
import { handleChatInputCommand } from './handlers/chatInputCommand';
|
||||
|
||||
export type InteractionRawReturnable =
|
||||
@@ -64,71 +40,72 @@ interface CommandRegistryBase {
|
||||
autocomplete?: (interaction: AutocompleteInteraction<CacheType>) => void;
|
||||
button?: (interaction: ButtonInteraction<CacheType>) => InteractionReturnable;
|
||||
}
|
||||
|
||||
interface CommandRegistryImplicit extends CommandRegistryBase {
|
||||
handlesInteraction: true;
|
||||
handler: (interaction: ChatInputCommandInteraction<CacheType>) => void;
|
||||
}
|
||||
|
||||
interface CommandRegistryExplicit extends CommandRegistryBase {
|
||||
handlesInteraction?: false;
|
||||
handler: (
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
) => InteractionReturnable;
|
||||
}
|
||||
|
||||
export type CommandRegistry = CommandRegistryImplicit | CommandRegistryExplicit;
|
||||
|
||||
export const COMMANDS_RAW: Promise<CommandRegistry>[] = [
|
||||
auctionCommand,
|
||||
permissionsCommand,
|
||||
debugCommand,
|
||||
aboutCommand,
|
||||
inactiveCommand,
|
||||
ownedTanksCommand,
|
||||
playerInfoCommand,
|
||||
searchClansCommand,
|
||||
searchPlayersCommand,
|
||||
fullStatsCommand,
|
||||
breakdownCommand,
|
||||
verifyCommand,
|
||||
pingCommand,
|
||||
evolutionCommand,
|
||||
statsCommand,
|
||||
ratingLeaderboardCommand,
|
||||
todayCommand,
|
||||
researchCommand,
|
||||
ratingCommand,
|
||||
replayCommand,
|
||||
// auctionCommand,
|
||||
// permissionsCommand,
|
||||
// debugCommand,
|
||||
// aboutCommand,
|
||||
// inactiveCommand,
|
||||
// ownedTanksCommand,
|
||||
// playerInfoCommand,
|
||||
// searchClansCommand,
|
||||
// searchPlayersCommand,
|
||||
// fullStatsCommand,
|
||||
// breakdownCommand,
|
||||
// verifyCommand,
|
||||
// pingCommand,
|
||||
// evolutionCommand,
|
||||
// statsCommand,
|
||||
// ratingLeaderboardCommand,
|
||||
// todayCommand,
|
||||
// researchCommand,
|
||||
// ratingCommand,
|
||||
// replayCommand,
|
||||
];
|
||||
|
||||
export const commands = Promise.allSettled(COMMANDS_RAW).then((rawCommands) => {
|
||||
return rawCommands.reduce<Record<string, CommandRegistry>>(
|
||||
(commands, registry, index) => {
|
||||
if (registry.status === 'rejected') {
|
||||
console.warn(
|
||||
`Command ${index} failed to load; skipping...`,
|
||||
registry.reason,
|
||||
);
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
return { ...commands, [registry.value.command.name]: registry.value };
|
||||
},
|
||||
{},
|
||||
);
|
||||
// return rawCommands.reduce<Record<string, CommandRegistry>>(
|
||||
// (commands, registry, index) => {
|
||||
// if (registry.status === 'rejected') {
|
||||
// console.warn(
|
||||
// `Command ${index} failed to load; skipping...`,
|
||||
// registry.reason,
|
||||
// );
|
||||
// return commands;
|
||||
// }
|
||||
// return { ...commands, [registry.value.command.name]: registry.value };
|
||||
// },
|
||||
// {},
|
||||
// );
|
||||
});
|
||||
|
||||
const rest = new REST().setToken(assertSecret(import.meta.env.DISCORD_TOKEN));
|
||||
// const rest = new REST().setToken(assertSecret(import.meta.env.DISCORD_TOKEN));
|
||||
|
||||
commands.then((awaitedCommands) => {
|
||||
const body = Object.values(awaitedCommands).map((registry) =>
|
||||
registry.command.toJSON(),
|
||||
);
|
||||
// commands.then((awaitedCommands) => {
|
||||
// const body = Object.values(awaitedCommands).map((registry) =>
|
||||
// registry.command.toJSON(),
|
||||
// );
|
||||
|
||||
rest.put(
|
||||
Routes.applicationCommands(assertSecret(import.meta.env.DISCORD_CLIENT_ID)),
|
||||
{ body },
|
||||
);
|
||||
});
|
||||
// rest.put(
|
||||
// Routes.applicationCommands(assertSecret(import.meta.env.DISCORD_CLIENT_ID)),
|
||||
// { body },
|
||||
// );
|
||||
// });
|
||||
|
||||
export async function interactionCreate(interaction: Interaction<CacheType>) {
|
||||
if (interaction.isAutocomplete()) {
|
||||
@@ -136,6 +113,6 @@ export async function interactionCreate(interaction: Interaction<CacheType>) {
|
||||
} else if (interaction.isChatInputCommand()) {
|
||||
handleChatInputCommand(interaction);
|
||||
} else if (interaction.isButton()) {
|
||||
handleButton(interaction);
|
||||
// handleButton(interaction);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user