WIP working example

This commit is contained in:
Marius Begby committed 2023-08-30 22:16:26 +02:00
1 parent 6ebf7b9bd3
commit 3be362f096
4 files changed
+17 -40

No files matched your search

+6 -4
View File
@@ -1,4 +1,4 @@
import { SlashCommandBuilder } from 'discord.js';
import { EmbedBuilder, Message, SlashCommandBuilder } from 'discord.js';
import { BaseCommandInteraction, BaseSlashCommandParams } from '../../../types/interactionTypes';
export class TestCommandInteraction extends BaseCommandInteraction {
@@ -7,16 +7,18 @@ export class TestCommandInteraction extends BaseCommandInteraction {
super(data);
}
async execute(params: BaseSlashCommandParams): Promise<void> {
async execute(params: BaseSlashCommandParams): Promise<Message<boolean> | void> {
const { executionId, interaction } = params;
const logger = this.getLogger('test.ts', 'test', executionId, interaction);
const logger = this.getLogger('test.js', executionId, interaction);
logger.info('test command executed');
logger.info(`${interaction.user.tag} executed test command`);
logger.info(`Execution ID: ${executionId}`);
logger.info(this.embedOptions.icons.success + ' Icon success from config.');
return;
return await interaction.editReply({
embeds: [new EmbedBuilder().setDescription('It works!').setColor(this.embedOptions.colors.success)]
});
}
}
+4 -11
View File
@@ -72,17 +72,10 @@ export class CustomError extends Error {
}
abstract class BaseInteraction {
protected getLoggerBase(
module: string,
source: string,
name: string,
executionId: string,
interaction: Interaction
): Logger {
protected getLoggerBase(module: string, source: string, executionId: string, interaction: Interaction): Logger {
return loggerModule.child({
source: source,
module: module,
name: name,
executionId: executionId,
shardId: interaction.guild?.shardId,
guildId: interaction.guild?.id
@@ -108,15 +101,15 @@ export abstract class BaseCommandInteraction extends BaseInteraction {
isBeta?: boolean
) {
super();
this.data = data;
this.data = data.setDMPermission(false).setNSFW(false);
this.isSystemCommand = isSystemCommand || false;
this.isNew = isNew || false;
this.isBeta = isBeta || false;
this.embedOptions = config.get('embedOptions');
}
protected getLogger(source: string, name: string, executionId: string, interaction: Interaction): Logger {
return super.getLoggerBase('slashCommand', source, name, executionId, interaction);
protected getLogger(source: string, executionId: string, interaction: Interaction): Logger {
return super.getLoggerBase('slashCommand', source, executionId, interaction);
}
abstract execute(params: BaseSlashCommandParams): Promise<Message<boolean> | void>;
+1 -8
View File
@@ -51,7 +51,6 @@ const rest: REST = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_
process.exit(1);
}
/*
for (const folder of commandFolders) {
const commandFiles: string[] = fs
.readdirSync(path.resolve(`./dist/interactions/commands/${folder}`))
@@ -59,18 +58,12 @@ const rest: REST = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_
for (const file of commandFiles) {
// TODO: create commandModule type
const commandModule = await import(`../interactions/commands/${folder}/${file}`);
const command = commandModule.default;
const { default: command } = await import(`../interactions/commands/${folder}/${file}`);
command.isSystemCommand
? systemCommands.push(command.data.toJSON())
: slashCommands.push(command.data.toJSON());
}
}
*/
const commandModule = await import('../interactions/commands/player/test.js');
const command = commandModule.default;
slashCommands.push(command.data.toJSON());
try {
logger.debug(`Bot user slash commands found: ${slashCommands.map((command) => `/${command.name}`).join(', ')}`);
+6 -17
View File
@@ -18,26 +18,23 @@ export const registerClientCommands = async ({ client, executionId }: RegisterCl
logger.debug('Registering client commands...');
client.commands = new Collection();
/*
const commandFolders: string[] = fs.readdirSync(path.resolve('./dist/interactions/commands'));
for (const folder of commandFolders) {
logger.trace(`Registering client commands for folder '${folder}'...`);
const commandFiles: string[] = fs
.readdirSync(path.resolve(`./dist/interactions/commands/${folder}`))
.filter((file) => file.endsWith('.js'));
for (const file of commandFiles) {
try {
// delete command from require cache
delete require.cache[require.resolve(`../interactions/commands/${folder}/${file}`)];
// register command
//const command = require(`../interactions/commands/${folder}/${file}`);
const commandModule = await import(`../interactions/commands/${folder}/${file}`);
client.commands.delete(commandModule.default.data.name);
client.commands.set(commandModule.default.data.name, commandModule.default);
// load command and register it to client.commands collection
const { default: command } = await import(`../interactions/commands/${folder}/${file}`);
client.commands.delete(command.data.name);
client.commands.set(command.data.name, command);
} catch (error) {
if (error instanceof Error) {
logger.error(`Error registering command ${folder}/${file}: ${error.message}`);
@@ -46,15 +43,7 @@ export const registerClientCommands = async ({ client, executionId }: RegisterCl
}
}
}
}
*/
const commandModule = await import('../interactions/commands/player/test.js');
const command = commandModule.default;
logger.info(command.data);
client.commands.set('test', command);
logger.trace('Registering client commands complete.');
};