Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
danielguirra committed Mar 20, 2024
1 parent d49a850 commit 642e2b7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 51 deletions.
22 changes: 20 additions & 2 deletions src/command/Builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ import {
import { allComands } from './allComands';

export class Command {
constructor(comm: Command) {
Object.assign(this, comm);
}

data!:
| SlashCommandBuilder
| Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>;
executeMessageCommand!: (
message: Message
) => Promise<Message<boolean> | void | undefined>;
executeSlashCommand!: (
commandSlash: CommandInteraction | Interaction
commandSlash: CommandInteraction
) => Promise<
void | Message<boolean> | InteractionResponse<boolean> | undefined
>;
Expand All @@ -26,5 +30,19 @@ export class Command {
export const commands = new Collection() as Collection<string, Command>;

for (const key of allComands) {
if (key instanceof Command) commands.set(key.data.name, key);
const command = new Command(key);

try {
commands.set(command.data.name, command);
} catch (error) {
console.error(error, {
command,
expected: {
data: SlashCommandBuilder,
executeMessageCommand: Promise<Function>,
executeSlashCommand: Promise<Function>,
},
});
break;
}
}
2 changes: 0 additions & 2 deletions src/command/allComands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { lerolero } from './commandLeroLero';
import { loreleagueoflegends } from './commandLoreLeagueOfLegends';
import { love } from './commandLove';
import { motivacao } from './commandMotivacao';

import { pdl } from './commandPdl';
import { peace } from './commandPeace';
import { pensador } from './commandPensador';
Expand Down Expand Up @@ -67,7 +66,6 @@ export const allComands = [
bibleverday,
duel,
queuqlol,

climate,
deleteUser,
editUser,
Expand Down
45 changes: 0 additions & 45 deletions src/command/commandJoke.ts

This file was deleted.

5 changes: 3 additions & 2 deletions src/command/commandSaveUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { Interaction, Message, SlashCommandBuilder } from 'discord.js';

import { embedBuilder } from '../../src/util/getEmbed';
import { UserDB } from '../database/users/user.class';
import { Command } from './Builder';

/**
* Don't forget to export
* Não esqueça de exportar
* @param Command
* @danielguirra
*/
export const saveUser = {
export const saveUser: Command = {
data: new SlashCommandBuilder()
.setName('salvabanco')
.setDescription('salva o seu usuário no banco de dados do bot')
Expand All @@ -34,7 +35,7 @@ export const saveUser = {
commandMessage.reply('usa de /');
},

async executeSlashCommand(commandSlash: Interaction) {
async executeSlashCommand(commandSlash) {
if (!commandSlash.isChatInputCommand()) return;
const pais = commandSlash.options.getString('pais');
const city = commandSlash.options.getString('cidade');
Expand Down

0 comments on commit 642e2b7

Please sign in to comment.