feat: switched to vite node

This commit is contained in:
TresAbhi committed 2023-04-28 13:42:42 +00:00
1 parent d9deeb3630
commit 8ff34f0bbb
14 files changed
+370 -222

No files matched your search

+73 -35
View File
@@ -3,15 +3,16 @@ import {
ChatInputCommandInteraction,
Collection,
Interaction,
REST,
RESTPostAPIChatInputApplicationCommandsJSONBody,
Routes,
SlashCommandBuilder,
} from 'discord.js';
export interface CommandSet {
commandCollection: Collection<string, CommandRegistry>;
guildCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[];
publicCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[];
}
import { readdirSync } from 'fs';
import discord from '../../discord.json' assert { type: 'json' };
import { args } from '../utilities/args.js';
import getClientId from '../utilities/getClientId.js';
import isDev from '../utilities/isDev.js';
export interface CommandRegistry {
inDevelopment: boolean; // register with Skilled Bot (default: false)
@@ -19,39 +20,76 @@ export interface CommandRegistry {
inPublic: boolean; // registers on all servers (default: true)
command: Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>;
execute: (
interaction: ChatInputCommandInteraction<CacheType>,
commandSed: CommandSet,
) => void;
execute: (interaction: ChatInputCommandInteraction<CacheType>) => void;
}
export default function interactionCreateCurry(commandSet: CommandSet) {
return async function interactionCreate(interaction: Interaction<CacheType>) {
if (!interaction.isChatInputCommand()) return;
const command = commandSet.commandCollection.get(interaction.commandName);
const rest = new REST().setToken(args['discord-token']);
if (!command) {
console.error(
`No command matching ${interaction.commandName} was found.`,
);
return;
const commandFolders = readdirSync('src/commands/');
const commandCollection = new Collection<string, CommandRegistry>();
export const guildCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] =
[];
export const publicCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] =
[];
for (const file of commandFolders) {
const command = (await import(`../commands/${file}`))
.default as CommandRegistry;
if (isDev() ? command.inDevelopment : command.inProduction) {
if (command.inPublic) {
publicCommands.push(command.command.toJSON());
} else {
guildCommands.push(command.command.toJSON());
}
try {
command.execute(interaction, commandSet);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({
content: 'There was an error while executing this command!',
ephemeral: true,
});
} else {
await interaction.reply({
content: 'There was an error while executing this command!',
ephemeral: true,
});
}
commandCollection.set(command.command.name, command);
}
}
try {
console.log(`Refreshing ${publicCommands.length} public command(s).`);
const publicData = (await rest.put(
Routes.applicationCommands(getClientId()),
{ body: publicCommands },
)) as RESTPostAPIChatInputApplicationCommandsJSONBody[];
console.log(`Successfully refreshed ${publicData.length} public command(s).`);
console.log(`Refreshing ${guildCommands.length} guild command(s).`);
const guildData = (await rest.put(
Routes.applicationGuildCommands(getClientId(), discord.guild_id),
{ body: guildCommands },
)) as RESTPostAPIChatInputApplicationCommandsJSONBody[];
console.log(`Successfully refreshed ${guildData.length} guild command(s).`);
} catch (error) {
console.error(error);
}
export default async function interactionCreate(
interaction: Interaction<CacheType>,
) {
if (!interaction.isChatInputCommand()) return;
const command = commandCollection.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
command.execute(interaction);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({
content: 'There was an error while executing this command!',
ephemeral: true,
});
} else {
await interaction.reply({
content: 'There was an error while executing this command!',
ephemeral: true,
});
}
};
}
}