mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 06:28:53 +00:00
WIP
This commit is contained in:
1 parent
3be362f096
commit
6d7a931f16
6 files changed
+28
-43
No files matched your search
@@ -1,8 +1,9 @@
|
||||
import { ChatInputCommandInteraction } from 'discord.js';
|
||||
import { Logger } from 'pino';
|
||||
import loggerModule from '../services/logger';
|
||||
import { Command, ExtendedClient } from '../types/clientTypes';
|
||||
import { ExtendedClient } from '../types/clientTypes';
|
||||
import { cannotSendMessageInChannel } from '../utils/validation/permissionValidator';
|
||||
import { BaseSlashCommandInteraction } from '../types/interactionTypes';
|
||||
|
||||
export const handleCommand = async (
|
||||
interaction: ChatInputCommandInteraction,
|
||||
@@ -20,7 +21,9 @@ export const handleCommand = async (
|
||||
logger.debug('Interaction deferred.');
|
||||
|
||||
// TODO: Update TS Type for command
|
||||
const command: Command = client.commands?.get(interaction.commandName) as Command;
|
||||
const command: BaseSlashCommandInteraction = client.commands!.get(
|
||||
interaction.commandName
|
||||
) as BaseSlashCommandInteraction;
|
||||
if (!command) {
|
||||
logger.warn(`Interaction created but command '${interaction.commandName}' was not found.`);
|
||||
return;
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import config from 'config';
|
||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||
import {
|
||||
EmbedBuilder,
|
||||
SharedSlashCommandOptions,
|
||||
SlashCommandBuilder,
|
||||
SlashCommandNumberOption,
|
||||
SlashCommandStringOption
|
||||
} from 'discord.js';
|
||||
import { Logger } from 'pino';
|
||||
import loggerModule from '../../../services/logger';
|
||||
import { BotOptions, EmbedOptions } from '../../../types/configTypes';
|
||||
@@ -27,16 +33,20 @@ const command: BaseSlashCommandInteraction = {
|
||||
});
|
||||
|
||||
// TODO: Create interface for command list
|
||||
const commandList = client!.commands!
|
||||
.filter((command) => {
|
||||
const commandList = client!
|
||||
.commands!.filter((command: BaseSlashCommandInteraction) => {
|
||||
// don't include system commands
|
||||
if (command.isSystemCommand) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
})
|
||||
.map((command) => {
|
||||
const params: string = command.data.options[0] ? `**\`${command.data.options[0].name}\`**` + ' ' : '';
|
||||
.map((command: BaseSlashCommandInteraction) => {
|
||||
let params: string = '';
|
||||
const option = command.data.options[0];
|
||||
if (option instanceof SlashCommandNumberOption || option instanceof SlashCommandStringOption) {
|
||||
params = `**\`${option.name}\`**` + ' ';
|
||||
}
|
||||
const beta: string = command.isBeta ? `${embedOptions.icons.beta} ` : '';
|
||||
const newCommand: string = command.isNew ? `${embedOptions.icons.new} ` : '';
|
||||
return `- **\`/${command.data.name}\`** ${params}- ${beta}${newCommand}${command.data.description}`;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { EmbedBuilder, Message, SlashCommandBuilder } from 'discord.js';
|
||||
import { BaseCommandInteraction, BaseSlashCommandParams } from '../../../types/interactionTypes';
|
||||
import { BaseSlashCommandInteraction, BaseSlashCommandParams } from '../../../types/interactionTypes';
|
||||
|
||||
export class TestCommandInteraction extends BaseCommandInteraction {
|
||||
export class TestCommandInteraction extends BaseSlashCommandInteraction {
|
||||
constructor() {
|
||||
const data = new SlashCommandBuilder().setName('test').setDescription('Test command');
|
||||
super(data);
|
||||
|
||||
@@ -1,24 +1,9 @@
|
||||
import { Client, Collection } from 'discord.js';
|
||||
import { BaseCommandInteraction } from './interactionTypes';
|
||||
import { BaseSlashCommandInteraction } from './interactionTypes';
|
||||
|
||||
type RegisterClientCommandsFunction = (params: { client: Client; executionId: string }) => void;
|
||||
|
||||
/*
|
||||
export interface Command {
|
||||
isNew?: boolean;
|
||||
isBeta?: boolean;
|
||||
isSystemCommand?: boolean;
|
||||
data: {
|
||||
name: string;
|
||||
description: string;
|
||||
options: SharedNameAndDescription[]
|
||||
};
|
||||
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, BaseCommandInteraction>;
|
||||
commands?: Collection<string, BaseSlashCommandInteraction>;
|
||||
}
|
||||
@@ -22,23 +22,16 @@ export interface BaseSlashCommandParams extends BaseInteractionParams {
|
||||
client?: ExtendedClient;
|
||||
}
|
||||
|
||||
interface BaseAutocompleteParams {
|
||||
interface BaseAutocompleteParams extends BaseInteractionParams {
|
||||
interaction: AutocompleteInteraction;
|
||||
}
|
||||
|
||||
interface BaseComponentParams {
|
||||
interface BaseComponentParams extends BaseInteractionParams {
|
||||
interaction: MessageComponentInteraction;
|
||||
referenceId?: string;
|
||||
}
|
||||
|
||||
// Interaction types
|
||||
export interface BaseSlashCommandInteraction {
|
||||
isNew: boolean;
|
||||
isBeta: boolean;
|
||||
isSystemCommand?: boolean;
|
||||
data: Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>;
|
||||
execute(params: BaseSlashCommandParams): Promise<Message<boolean> | void>;
|
||||
}
|
||||
|
||||
export interface BaseAutocompleteInteraction {
|
||||
execute(params: BaseAutocompleteParams): Promise<ApplicationCommandOptionChoiceData | void>;
|
||||
@@ -87,7 +80,7 @@ abstract class BaseInteraction {
|
||||
): Promise<Message<boolean> | ApplicationCommandOptionChoiceData | void>;
|
||||
}
|
||||
|
||||
export abstract class BaseCommandInteraction extends BaseInteraction {
|
||||
export abstract class BaseSlashCommandInteraction extends BaseInteraction {
|
||||
data: Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>;
|
||||
isSystemCommand: boolean;
|
||||
isNew: boolean;
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import 'dotenv/config';
|
||||
|
||||
import config from 'config';
|
||||
import {
|
||||
REST,
|
||||
RESTPostAPIChatInputApplicationCommandsJSONBody,
|
||||
RouteLike,
|
||||
Routes,
|
||||
SlashCommandBuilder
|
||||
} from 'discord.js';
|
||||
import { REST, RESTPostAPIChatInputApplicationCommandsJSONBody, RouteLike, Routes } from 'discord.js';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
Reference in new issue
Block a user