This commit is contained in:
Marius Begby committed 2023-08-30 21:47:50 +02:00
1 parent d0f1e940a5
commit 6ebf7b9bd3
30 files changed
+174 -71

No files matched your search

+2 -2
View File
@@ -3,7 +3,7 @@ import { Player, SearchResult, useMainPlayer } from 'discord-player';
import { ApplicationCommandOptionChoiceData } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../services/logger';
import { CustomAutocompleteInteraction } from '../../types/interactionTypes';
import { BaseAutocompleteInteraction } from '../../types/interactionTypes';
const loggerTemplate: Logger = loggerModule.child({
source: 'lyrics.js',
@@ -14,7 +14,7 @@ const loggerTemplate: Logger = loggerModule.child({
// TODO: create interface for recent query object
const recentQueries = new Map();
const autocomplete: CustomAutocompleteInteraction = {
const autocomplete: BaseAutocompleteInteraction = {
execute: async ({ interaction, executionId }) => {
const logger: Logger = loggerTemplate.child({
executionId: executionId,
+2 -2
View File
@@ -2,7 +2,7 @@ import { Player, SearchResult, useMainPlayer } from 'discord-player';
import { ApplicationCommandOptionChoiceData } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../services/logger';
import { CustomAutocompleteInteraction } from '../../types/interactionTypes';
import { BaseAutocompleteInteraction } from '../../types/interactionTypes';
const loggerTemplate: Logger = loggerModule.child({
source: 'play.js',
@@ -13,7 +13,7 @@ const loggerTemplate: Logger = loggerModule.child({
// TODO: create interface for recent query object
const recentQueries = new Map();
const autocomplete: CustomAutocompleteInteraction = {
const autocomplete: BaseAutocompleteInteraction = {
execute: async ({ interaction, executionId }) => {
const logger: Logger = loggerTemplate.child({
executionId: executionId,
+2 -2
View File
@@ -3,12 +3,12 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { BotOptions, EmbedOptions } from '../../../types/configTypes';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
const embedOptions: EmbedOptions = config.get('embedOptions');
const botOptions: BotOptions = config.get('botOptions');
const command: CustomSlashCommandInteraction = {
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
+2 -2
View File
@@ -6,12 +6,12 @@ import { Logger } from 'pino';
import { version } from '../../../../package.json';
import loggerModule from '../../../services/logger';
import { EmbedOptions } from '../../../types/configTypes';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import { getUptimeFormatted } from '../../../utils/system/getUptimeFormatted';
const embedOptions: EmbedOptions = config.get('embedOptions');
const command: CustomSlashCommandInteraction = {
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
+2 -2
View File
@@ -16,14 +16,14 @@ import {
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { EmbedOptions, FFmpegFilterOption, FFmpegFilterOptions } from '../../../types/configTypes';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions');
const command: CustomSlashCommandInteraction = {
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
+2 -2
View File
@@ -4,13 +4,13 @@ import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { EmbedOptions } from '../../../types/configTypes';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
const command: CustomSlashCommandInteraction = {
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
+2 -2
View File
@@ -4,14 +4,14 @@ import { EmbedBuilder, GuildMember, SlashCommandBuilder, SlashCommandStringOptio
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { BotOptions, EmbedOptions } from '../../../types/configTypes';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
const botOptions: BotOptions = config.get('botOptions');
const command: CustomSlashCommandInteraction = {
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
+2 -2
View File
@@ -5,7 +5,7 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import { LyricsData, lyricsExtractor } from '@discord-player/extractor';
import loggerModule from '../../../services/logger';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import { EmbedOptions } from '../../../types/configTypes';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
@@ -19,7 +19,7 @@ const loggerTemplate: Logger = loggerModule.child({
name: '/lyrics'
});
const command: CustomSlashCommandInteraction = {
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
@@ -12,7 +12,7 @@ import {
} from 'discord.js';
import loggerModule from '../../../services/logger';
import { CustomSlashCommandInteraction, TrackMetadata } from '../../../types/interactionTypes';
import { BaseSlashCommandInteraction, TrackMetadata } from '../../../types/interactionTypes';
import { EmbedOptions, PlayerOptions } from '../../../types/configTypes';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
@@ -21,7 +21,7 @@ import { Logger } from 'pino';
const embedOptions: EmbedOptions = config.get('embedOptions');
const playerOptions: PlayerOptions = config.get('playerOptions');
const command: CustomSlashCommandInteraction = {
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
+2 -2
View File
@@ -4,13 +4,13 @@ import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { EmbedOptions } from '../../../types/configTypes';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
const command: CustomSlashCommandInteraction = {
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
+2 -2
View File
@@ -3,7 +3,7 @@ import { GuildQueue, useMainPlayer, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import loggerModule from '../../../services/logger';
import { CustomError, CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { CustomError, BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import { BotOptions, EmbedOptions, PlayerOptions } from '../../../types/configTypes';
import { cannotJoinVoiceOrTalk } from '../../../utils/validation/permissionValidator';
import { transformQuery } from '../../../utils/validation/searchQueryValidator';
@@ -20,7 +20,7 @@ const loggerTemplate: Logger = loggerModule.child({
name: '/play'
});
const command: CustomSlashCommandInteraction = {
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
+2 -2
View File
@@ -4,14 +4,14 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { EmbedOptions, PlayerOptions } from '../../../types/configTypes';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
const playerOptions: PlayerOptions = config.get('playerOptions');
const command: CustomSlashCommandInteraction = {
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
+2 -2
View File
@@ -4,13 +4,13 @@ import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { EmbedOptions } from '../../../types/configTypes';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
const command: CustomSlashCommandInteraction = {
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
+2 -2
View File
@@ -4,13 +4,13 @@ import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { EmbedOptions } from '../../../types/configTypes';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
const command: CustomSlashCommandInteraction = {
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
+2 -2
View File
@@ -4,13 +4,13 @@ import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { EmbedOptions } from '../../../types/configTypes';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import { queueDoesNotExist, queueIsEmpty } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
const command: CustomSlashCommandInteraction = {
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
+2 -2
View File
@@ -4,13 +4,13 @@ import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { EmbedOptions } from '../../../types/configTypes';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
const command: CustomSlashCommandInteraction = {
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
+2 -2
View File
@@ -4,13 +4,13 @@ import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { EmbedOptions } from '../../../types/configTypes';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
const command: CustomSlashCommandInteraction = {
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
+23
View File
@@ -0,0 +1,23 @@
import { SlashCommandBuilder } from 'discord.js';
import { BaseCommandInteraction, BaseSlashCommandParams } from '../../../types/interactionTypes';
export class TestCommandInteraction extends BaseCommandInteraction {
constructor() {
const data = new SlashCommandBuilder().setName('test').setDescription('Test command');
super(data);
}
async execute(params: BaseSlashCommandParams): Promise<void> {
const { executionId, interaction } = params;
const logger = this.getLogger('test.ts', 'test', 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;
}
}
export default new TestCommandInteraction();
+2 -2
View File
@@ -4,13 +4,13 @@ import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { EmbedOptions } from '../../../types/configTypes';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
const command: CustomSlashCommandInteraction = {
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
+2 -2
View File
@@ -3,12 +3,12 @@ import { EmbedBuilder, Guild, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { EmbedOptions } from '../../../types/configTypes';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import { notValidGuildId } from '../../../utils/validation/systemCommandValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
const command: CustomSlashCommandInteraction = {
const command: BaseSlashCommandInteraction = {
isSystemCommand: true,
isNew: false,
isBeta: false,
+2 -2
View File
@@ -4,12 +4,12 @@ import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { ExtendedClient } from '../../../types/clientTypes';
import { EmbedOptions } from '../../../types/configTypes';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import { notValidGuildId } from '../../../utils/validation/systemCommandValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
const command: CustomSlashCommandInteraction = {
const command: BaseSlashCommandInteraction = {
isSystemCommand: true,
isNew: false,
isBeta: false,
+2 -2
View File
@@ -4,12 +4,12 @@ import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { ExtendedClient } from '../../../types/clientTypes';
import { EmbedOptions } from '../../../types/configTypes';
import { CustomSlashCommandInteraction, ShardInfo } from '../../../types/interactionTypes';
import { BaseSlashCommandInteraction, ShardInfo } from '../../../types/interactionTypes';
import { notValidGuildId } from '../../../utils/validation/systemCommandValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
const command: CustomSlashCommandInteraction = {
const command: BaseSlashCommandInteraction = {
isSystemCommand: true,
isNew: false,
isBeta: false,
@@ -4,7 +4,7 @@ import osu from 'node-os-utils';
// @ts-ignore
import { dependencies, version } from '../../../../package.json';
import loggerModule from '../../../services/logger';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import { EmbedOptions } from '../../../types/configTypes';
import { getUptimeFormatted } from '../../../utils/system/getUptimeFormatted';
import { notValidGuildId } from '../../../utils/validation/systemCommandValidator';
@@ -12,7 +12,7 @@ import { Logger } from 'pino';
const embedOptions: EmbedOptions = config.get('embedOptions');
const command: CustomSlashCommandInteraction = {
const command: BaseSlashCommandInteraction = {
isSystemCommand: true,
isNew: false,
isBeta: false,
@@ -4,12 +4,12 @@ import { EmbedBuilder, GuildMember } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../services/logger';
import { EmbedOptions } from '../../types/configTypes';
import { CustomComponentInteraction } from '../../types/interactionTypes';
import { BaseComponentInteraction } from '../../types/interactionTypes';
import { queueDoesNotExist } from '../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
const component: CustomComponentInteraction = {
const component: BaseComponentInteraction = {
execute: async ({ interaction, executionId }) => {
const logger: Logger = loggerModule.child({
source: 'filters-disable-button.js',
@@ -4,13 +4,13 @@ import { EmbedBuilder, GuildMember, StringSelectMenuInteraction } from 'discord.
import { Logger } from 'pino';
import loggerModule from '../../services/logger';
import { EmbedOptions, FFmpegFilterOption, FFmpegFilterOptions } from '../../types/configTypes';
import { CustomComponentInteraction } from '../../types/interactionTypes';
import { BaseComponentInteraction } from '../../types/interactionTypes';
import { queueDoesNotExist } from '../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions');
const component: CustomComponentInteraction = {
const component: BaseComponentInteraction = {
execute: async ({ interaction, executionId }) => {
const logger: Logger = loggerModule.child({
source: 'filters-select-menu.js',
@@ -4,13 +4,13 @@ import { EmbedBuilder, GuildMember } from 'discord.js';
import loggerModule from '../../services/logger';
import { EmbedOptions } from '../../types/configTypes';
import { CustomComponentInteraction } from '../../types/interactionTypes';
import { BaseComponentInteraction } from '../../types/interactionTypes';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../utils/validation/queueValidator';
import { Logger } from 'pino';
const embedOptions: EmbedOptions = config.get('embedOptions');
const component: CustomComponentInteraction = {
const component: BaseComponentInteraction = {
execute: async ({ interaction, referenceId, executionId }) => {
const logger: Logger = loggerModule.child({
source: 'nowplaying-skip.js',
+5 -2
View File
@@ -1,7 +1,9 @@
import { Client, Collection, SharedNameAndDescription } from 'discord.js';
import { Client, Collection } from 'discord.js';
import { BaseCommandInteraction } from './interactionTypes';
type RegisterClientCommandsFunction = (params: { client: Client; executionId: string }) => void;
/*
export interface Command {
isNew?: boolean;
isBeta?: boolean;
@@ -14,8 +16,9 @@ export interface Command {
execute: (params: { interaction: object; client: ExtendedClient | undefined; executionId: string }) => void;
autocomplete?: (params: { interaction: object; executionId: string }) => void;
}
*/
export interface ExtendedClient extends Client {
registerClientCommands?: RegisterClientCommandsFunction;
commands?: Collection<string, Command>;
commands?: Collection<string, BaseCommandInteraction>;
}
+70 -15
View File
@@ -1,49 +1,53 @@
import config from 'config';
import {
ApplicationCommandOptionChoiceData,
AutocompleteInteraction,
ChatInputCommandInteraction,
Interaction,
Message,
MessageComponentInteraction,
SlashCommandBuilder
} from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../services/logger';
import { ExtendedClient } from './clientTypes';
import { EmbedOptions } from './configTypes';
// Local types
interface CommandParams {
client?: ExtendedClient;
interface BaseInteractionParams {
executionId: string;
interaction: ChatInputCommandInteraction;
}
interface AutocompleteParams {
executionId: string;
export interface BaseSlashCommandParams extends BaseInteractionParams {
interaction: ChatInputCommandInteraction;
client?: ExtendedClient;
}
interface BaseAutocompleteParams {
interaction: AutocompleteInteraction;
}
interface ComponentParams {
interface BaseComponentParams {
interaction: MessageComponentInteraction;
referenceId?: string;
executionId: string;
}
// Interaction types
export interface CustomSlashCommandInteraction {
export interface BaseSlashCommandInteraction {
isNew: boolean;
isBeta: boolean;
isSystemCommand?: boolean;
data: Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>;
execute(params: CommandParams): Promise<Message<boolean> | void>;
execute(params: BaseSlashCommandParams): Promise<Message<boolean> | void>;
}
export interface CustomAutocompleteInteraction {
execute(params: AutocompleteParams): Promise<ApplicationCommandOptionChoiceData | void>;
export interface BaseAutocompleteInteraction {
execute(params: BaseAutocompleteParams): Promise<ApplicationCommandOptionChoiceData | void>;
}
export interface CustomComponentInteraction {
execute(params: ComponentParams): Promise<Message<boolean> | void>;
export interface BaseComponentInteraction {
execute(params: BaseComponentParams): Promise<Message<boolean> | void>;
}
// Command specific types
export interface ShardInfo {
shardId: number;
memUsage: number;
@@ -66,3 +70,54 @@ export class CustomError extends Error {
type?: string;
code?: string;
}
abstract class BaseInteraction {
protected getLoggerBase(
module: string,
source: string,
name: 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
});
}
abstract execute(
params: BaseInteractionParams
): Promise<Message<boolean> | ApplicationCommandOptionChoiceData | void>;
}
export abstract class BaseCommandInteraction extends BaseInteraction {
data: Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>;
isSystemCommand: boolean;
isNew: boolean;
isBeta: boolean;
embedOptions: EmbedOptions;
constructor(
data: Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>,
isSystemCommand?: boolean,
isNew?: boolean,
isBeta?: boolean
) {
super();
this.data = data;
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);
}
abstract execute(params: BaseSlashCommandParams): Promise<Message<boolean> | void>;
}
+15 -3
View File
@@ -1,7 +1,13 @@
import 'dotenv/config';
import config from 'config';
import { REST, RouteLike, Routes, SlashCommandBuilder } from 'discord.js';
import {
REST,
RESTPostAPIChatInputApplicationCommandsJSONBody,
RouteLike,
Routes,
SlashCommandBuilder
} from 'discord.js';
import fs from 'node:fs';
import path from 'node:path';
import { v4 as uuidv4 } from 'uuid';
@@ -23,8 +29,8 @@ const logger: Logger = loggerModule.child({
//TODO: Fix deploying not working with require()
const slashCommands: SlashCommandBuilder[] = [];
const systemCommands: SlashCommandBuilder[] = [];
const slashCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] = [];
const systemCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] = [];
const commandFolders: string[] = fs.readdirSync(path.resolve('./dist/interactions/commands'));
if (!process.env.DISCORD_BOT_TOKEN) {
@@ -45,6 +51,7 @@ 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,6 +66,11 @@ const rest: REST = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_
: 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(', ')}`);
+11 -1
View File
@@ -18,13 +18,15 @@ 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
@@ -44,7 +46,15 @@ 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.');
};