Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyameliaaaa committed Jul 2, 2022
2 parents 402e813 + 8ea5eb9 commit f525aae
Show file tree
Hide file tree
Showing 30 changed files with 106 additions and 565 deletions.
2 changes: 1 addition & 1 deletion i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"LISTCASE_NEXT": "Next",
"LISTCASE_NO_CASES": "{{- user}} doesn't have any cases!",
"LISTCASE_TITLE": "Case history for {{- user}}",
"MESSAGE_CREATE_DESCRIPTION": "Hi! I'm Fluorine.\nMy prefix in this guild is {{- prefix}}",
"MESSAGE_MENTION": "Hi! Type `/` to see my commands",
"MESSAGE_DELETE_AUTHOR": "Author",
"MESSAGE_DELETE_CONTENT": "Content",
"MESSAGE_DELETE_TITLE": "Message deleted",
Expand Down
2 changes: 1 addition & 1 deletion i18n/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"LISTCASE_NEXT": "Następna strona",
"LISTCASE_NO_CASES": "{{- user}} nie ma żadnych kar!",
"LISTCASE_TITLE": "Historia kar dla {{- user}}",
"MESSAGE_CREATE_DESCRIPTION": "Cześć! Jestem Fluorine.\nMój prefix na tym serwerze to {{- prefix}}",
"MESSAGE_MENTION": "Cześć! Wpisz `/` aby zobaczyć moje komendy",
"MESSAGE_DELETE_AUTHOR": "Autor",
"MESSAGE_DELETE_CONTENT": "Treść",
"MESSAGE_DELETE_TITLE": "Usunięto wiadomość",
Expand Down
13 changes: 4 additions & 9 deletions src/classes/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import { performance } from 'perf_hooks';
import { PrismaClient } from '@prisma/client';

import EventHandler from '@handlers/EventHandler';
import ApplicationCommandHandler from '@handlers/ApplicationCommandHandler';
import CommandHandler from '@handlers/CommandHandler';
import CommandHandler from '@classes/handlers/CommandHandler';
import ComponentHandler from '@handlers/ComponentHandler';
import CooldownHandler from '@handlers/CooldownHandler';

Expand All @@ -28,10 +27,9 @@ export default class FluorineClient extends Client {
i18n = i18next;
prisma = new PrismaClient();

applicationCommands = new ApplicationCommandHandler(this);
commands = new CommandHandler(this);
components = new ComponentHandler(this);
cooldowns = new CooldownHandler(this);
cmds = new CommandHandler(this);

economy = new EconomyModule(this);
phishing = new PhishingModule(this);
Expand Down Expand Up @@ -67,15 +65,12 @@ export default class FluorineClient extends Client {
async init() {
this.logger.log(`Starting ${bold(red(process.env.NODE_ENV))} build...`);

this.applicationCommands.loadChatInput();
this.applicationCommands.loadContextMenu();
this.commands.loadChatInput();
this.commands.loadContextMenu();

this.components.loadComponents();
new EventHandler(this).loadEvents();

// TODO: remove prefix commands a month after 2.0
this.cmds.loadCommands();

await this.i18n.use(Backend).init({
fallbackLng: 'en-US',
preload: ['en-US', 'pl'],
Expand Down
68 changes: 0 additions & 68 deletions src/classes/handlers/ApplicationCommandHandler.ts

This file was deleted.

77 changes: 61 additions & 16 deletions src/classes/handlers/CommandHandler.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,68 @@
import { readdirSync } from 'fs';
import { Command } from 'types/command';
import { ChatInputCommand, ChatInputSubcommand, ContextMenuCommand } from 'types/structures';
import { Collection } from 'discord.js';
import FluorineClient from '@classes/Client';
export default class CommandHandler extends Collection<string, Command> {
client: FluorineClient;
constructor(client) {
super();
import { loadDirectory, loadParentDirectory } from '@util/files';
import { SlashCommandBuilder, SlashCommandSubcommandBuilder } from '@discordjs/builders';

export default class CommandHandler {
chatInput = new Collection<string, ChatInputCommand | ChatInputSubcommand>();
contextMenu = new Collection<string, ContextMenuCommand>();

constructor(private client: FluorineClient) {
this.client = client;
}
loadCommands() {
const dir = readdirSync(`${__dirname}/../../cmds`);
dir.forEach(async file => {
if (!file.endsWith('.js')) {
return;

private addFullBuilder(command: ChatInputCommand | ChatInputSubcommand) {
if ('category' in command) {
const subcommandNames = [...this.chatInput.keys()].filter(c => c.startsWith(`${command.data.name}/`));

const subcommands = subcommandNames.map(subcommandName => {
const subcommand = this.chatInput.get(subcommandName);
if (!('category' in subcommand)) {
return subcommand.data;
}
});

this.getMergedCommandData(command.data, subcommands);
}
}

private getMergedCommandData(base: SlashCommandBuilder, data: SlashCommandSubcommandBuilder[] = []) {
for (const subcommand of data) {
if (subcommand) {
base.addSubcommand(subcommand);
}
const [name] = file.split('.');
this.set(name, await import(`${__dirname}/../../cmds/${file}`));
});
this.client.logger.log(`Loaded ${dir.length} text commands`);
return this;
}

return base;
}

async loadChatInput() {
const [commands, subcommands] = await loadParentDirectory<ChatInputCommand, ChatInputSubcommand>('../commands');

for (const command of commands) {
this.chatInput.set(command.data.name, command);
}

for (const subcommand of subcommands) {
const [key] = subcommand.name.endsWith('index') ? subcommand.name.split('/') : [subcommand.name];
this.chatInput.set(key, subcommand.data);
}

this.chatInput.forEach(c => this.addFullBuilder(c));

const commandsLoaded = [...this.chatInput.keys()].filter(key => !key.includes('/'));
this.client.logger.log(`Loaded ${commandsLoaded.length} chat input commands.`);
return this.chatInput;
}

async loadContextMenu() {
const files = await loadDirectory<ContextMenuCommand>('../context');
for (const file of files) {
this.contextMenu.set(file.data.data.name, file.data);
}

this.client.logger.log(`Loaded ${files.length} context menu commands.`);
return this.contextMenu;
}
}
17 changes: 0 additions & 17 deletions src/cmds/8ball.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/cmds/avatar.ts

This file was deleted.

78 changes: 0 additions & 78 deletions src/cmds/bedwars.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/cmds/birb.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/cmds/cat.ts

This file was deleted.

40 changes: 0 additions & 40 deletions src/cmds/dev.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/cmds/dog.ts

This file was deleted.

Loading

0 comments on commit f525aae

Please sign in to comment.