mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02:00
feat: update bot chunk 4
This commit is contained in:
1 parent
5499cb5cca
commit
98724df711
11 files changed
+122
-91
No files matched your search
@@ -26,7 +26,7 @@ export const inactiveCommand = new Promise<CommandRegistry>((resolve) => {
|
||||
.setName('threshold')
|
||||
.setNameLocalizations(
|
||||
localizationObject(
|
||||
'bot.commands.inactive.options.threshold',
|
||||
(strings) => strings.bot.commands.inactive.options.threshold.$,
|
||||
undefined,
|
||||
true,
|
||||
),
|
||||
@@ -36,7 +36,8 @@ export const inactiveCommand = new Promise<CommandRegistry>((resolve) => {
|
||||
)
|
||||
.setDescriptionLocalizations(
|
||||
localizationObject(
|
||||
'bot.commands.inactive.options.threshold.description',
|
||||
(strings) =>
|
||||
strings.bot.commands.inactive.options.threshold.description,
|
||||
),
|
||||
)
|
||||
.setMinValue(0);
|
||||
|
||||
@@ -12,9 +12,7 @@ export function translator(localeRaw: Locale) {
|
||||
SUPPORTED_LOCALES_DISCORD.includes(localeRaw)
|
||||
? localeRaw
|
||||
: DEFAULT_LOCALE_DISCORD;
|
||||
STRINGS;
|
||||
const strings = STRINGS[SUPPORTED_LOCALES_DISCORD_MAP_INVERSE[locale]];
|
||||
|
||||
const unwrap = unwrapper(SUPPORTED_LOCALES_DISCORD_MAP_INVERSE[locale]);
|
||||
|
||||
return { locale, strings, unwrap };
|
||||
|
||||
@@ -2,11 +2,13 @@ import {
|
||||
ActionRowBuilder,
|
||||
AttachmentBuilder,
|
||||
ButtonBuilder,
|
||||
ButtonStyle,
|
||||
CacheType,
|
||||
ChatInputCommandInteraction,
|
||||
InteractionReplyOptions,
|
||||
} from 'discord.js';
|
||||
import { InteractionRawReturnable, commands } from '..';
|
||||
import { UserError } from '../../../core/blitzkit/userError';
|
||||
import { buttonLink } from '../../../core/discord/buttonLink';
|
||||
import { embedWarning } from '../../../core/discord/embedWarning';
|
||||
import { normalizeInteractionReturnable } from '../../../core/discord/normalizeInteractionReturnable';
|
||||
@@ -124,26 +126,27 @@ export async function handleChatInputCommand(
|
||||
index++;
|
||||
}
|
||||
} 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 { strings } = translator(interaction.locale);
|
||||
|
||||
const components = [
|
||||
new ActionRowBuilder<ButtonBuilder>().addComponents(
|
||||
new ButtonBuilder()
|
||||
.setLabel(strings.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: strings.bot.common.errors.uncaught_error,
|
||||
components,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { assertSecret } from '@blitzkit/core';
|
||||
import {
|
||||
AttachmentBuilder,
|
||||
AutocompleteInteraction,
|
||||
@@ -7,11 +8,36 @@ 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 =
|
||||
| string
|
||||
@@ -54,63 +80,63 @@ interface CommandRegistryExplicit extends CommandRegistryBase {
|
||||
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()) {
|
||||
// handleAutocomplete(interaction);
|
||||
handleAutocomplete(interaction);
|
||||
} else if (interaction.isChatInputCommand()) {
|
||||
// handleChatInputCommand(interaction);
|
||||
handleChatInputCommand(interaction);
|
||||
} else if (interaction.isButton()) {
|
||||
// handleButton(interaction);
|
||||
handleButton(interaction);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user