diff --git a/i18n/en-US.json b/i18n/en-US.json index 65643c86..229c1aff 100644 --- a/i18n/en-US.json +++ b/i18n/en-US.json @@ -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", diff --git a/i18n/pl.json b/i18n/pl.json index 59a8df86..99918769 100644 --- a/i18n/pl.json +++ b/i18n/pl.json @@ -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ść", diff --git a/src/classes/Client.ts b/src/classes/Client.ts index 38d4c150..f7ecae08 100644 --- a/src/classes/Client.ts +++ b/src/classes/Client.ts @@ -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'; @@ -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); @@ -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'], diff --git a/src/classes/handlers/ApplicationCommandHandler.ts b/src/classes/handlers/ApplicationCommandHandler.ts deleted file mode 100644 index 1b428b0c..00000000 --- a/src/classes/handlers/ApplicationCommandHandler.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { ChatInputCommand, ChatInputSubcommand, ContextMenuCommand } from 'types/structures'; -import { Collection } from 'discord.js'; -import FluorineClient from '@classes/Client'; -import { loadDirectory, loadParentDirectory } from '@util/files'; -import { SlashCommandBuilder, SlashCommandSubcommandBuilder } from '@discordjs/builders'; - -export default class ApplicationCommandHandler { - chatInput = new Collection(); - contextMenu = new Collection(); - - constructor(private client: FluorineClient) { - this.client = client; - } - - 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 && (process.env.NODE_ENV === 'development' || subcommand.name !== 'eval')) { - base.addSubcommand(subcommand); - } - } - - return base; - } - - async loadChatInput() { - const [commands, subcommands] = await loadParentDirectory('../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('../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; - } -} diff --git a/src/classes/handlers/CommandHandler.ts b/src/classes/handlers/CommandHandler.ts index ca149f13..920be330 100644 --- a/src/classes/handlers/CommandHandler.ts +++ b/src/classes/handlers/CommandHandler.ts @@ -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 { - client: FluorineClient; - constructor(client) { - super(); +import { loadDirectory, loadParentDirectory } from '@util/files'; +import { SlashCommandBuilder, SlashCommandSubcommandBuilder } from '@discordjs/builders'; + +export default class CommandHandler { + chatInput = new Collection(); + contextMenu = new Collection(); + + 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('../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('../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; } } diff --git a/src/cmds/8ball.ts b/src/cmds/8ball.ts deleted file mode 100644 index 29f297ad..00000000 --- a/src/cmds/8ball.ts +++ /dev/null @@ -1,17 +0,0 @@ -import FluorineClient from '@classes/Client'; -import Embed from '@classes/Embed'; -import { Message } from 'discord.js'; -export async function run(client: FluorineClient, message: Message, args: string[]) { - if (!args[0]) { - return message.reply(client.i18n.t('8BALL_ERROR', { lng: message.guild.preferredLocale })); - } - - const randNumber = Math.floor(Math.random() * 6); - - const embed = new Embed(client, message.guild.preferredLocale).setDescription(args.join(' ')).addLocaleField({ - name: '8BALL_RESPONSE', - localeValue: `8BALL_RESPONSES.${randNumber}` - }); - - message.reply({ embeds: [embed] }); -} diff --git a/src/cmds/avatar.ts b/src/cmds/avatar.ts deleted file mode 100644 index a381577a..00000000 --- a/src/cmds/avatar.ts +++ /dev/null @@ -1,12 +0,0 @@ -import FluorineClient from '@classes/Client'; -import Embed from '@classes/Embed'; -import { Message } from 'discord.js'; - -export async function run(client: FluorineClient, message: Message, args: string[]) { - const user = message.mentions.users.first() ?? client.users.cache.get(args[0]) ?? message.author; - - const embed = new Embed(client, message.guild.preferredLocale) - .setLocaleTitle('AVATAR') - .setImage(user.displayAvatarURL({ dynamic: true, size: 512 })); - message.reply({ embeds: [embed] }); -} diff --git a/src/cmds/bedwars.ts b/src/cmds/bedwars.ts deleted file mode 100644 index 1eec9e11..00000000 --- a/src/cmds/bedwars.ts +++ /dev/null @@ -1,78 +0,0 @@ -import FluorineClient from '@classes/Client'; -import Embed from '@classes/Embed'; -import { Message } from 'discord.js'; -import { HypixelType } from 'types/hypixel'; -export async function run(client: FluorineClient, message: Message, args: string[]) { - if (!args[0]) { - return message.reply( - client.i18n.t('HYPIXEL_NO_ARGS', { - lng: message.guild.preferredLocale, - command: 'bedwars' - }) - ); - } - - const uuid: any = await fetch(`https://api.mojang.com/users/profiles/minecraft/${args[0]}`).then(res => res.json()); - - if (!uuid.id) { - return message.reply( - client.i18n.t('HYPIXEL_INVALID_PLAYER', { - lng: message.guild.preferredLocale - }) - ); - } - - const data = (await fetch( - `https://api.hypixel.net/player?uuid=${uuid.data.id}&key=${process.env.HYPIXEL_TOKEN}` - ).then(res => res.json())) as HypixelType; - const bedStats = data.player?.stats?.Bedwars; - if (!bedStats) { - return message.reply( - client.i18n.t('HYPIXEL_PLAYER_NOT_FOUND', { - lng: message.guild.preferredLocale - }) - ); - } - - const kd = (bedStats.kills_bedwars / bedStats.deaths_bedwars).toFixed(2); - const winratio = (bedStats.wins_bedwars / bedStats.losses_bedwars).toFixed(2); - const bedEmbed = new Embed(client, message.guild.preferredLocale) - .setLocaleTitle('HYPIXEL_STATISTICS_TITLE', { - player: args[0] - }) - .setDescription(`K/D: ${kd}\n Win/loss ratio: ${winratio}`) - .addLocaleField({ - name: 'HYPIXEL_WON_GAMES', - value: `${bedStats.wins_bedwars || 0}`, - inline: true - }) - .addLocaleField({ - name: 'HYPIXEL_LOST_GAMES', - value: `${bedStats.losses_bedwars || 0}`, - inline: true - }) - .addField('\u200B', '\u200B', true) - .addLocaleField({ - name: 'HYPIXEL_KILLS', - value: `${bedStats.kills_bedwars || 0}`, - inline: true - }) - .addLocaleField({ - name: 'HYPIXEL_DEATHS', - value: `${bedStats.deaths_bedwars || 0}`, - inline: true - }) - .addField('\u200B', '\u200B', true) - .addLocaleField({ - name: 'HYPIXEL_BEDS_DESTROYED', - value: `${bedStats.beds_broken_bedwars || 0}`, - inline: true - }) - .addLocaleField({ - name: 'HYPIXEL_BEDS_LOST', - value: `${bedStats.beds_lost_bedwars || 0}`, - inline: true - }) - .setThumbnail(`https://crafatar.com/avatars/${uuid.data.id}?default=MHF_Steve&overlay`); - message.reply({ embeds: [bedEmbed] }); -} diff --git a/src/cmds/birb.ts b/src/cmds/birb.ts deleted file mode 100644 index 2f0f3f0d..00000000 --- a/src/cmds/birb.ts +++ /dev/null @@ -1,9 +0,0 @@ -import FluorineClient from '@classes/Client'; -import Embed from '@classes/Embed'; -import { Message } from 'discord.js'; - -export async function run(client: FluorineClient, message: Message) { - const { file }: any = await (await fetch('https://api.alexflipnote.dev/birb')).json(); - const embed = new Embed(client, message.guild.preferredLocale).setLocaleTitle('BIRB').setImage(file); - message.reply({ embeds: [embed] }); -} diff --git a/src/cmds/cat.ts b/src/cmds/cat.ts deleted file mode 100644 index ee41e0bb..00000000 --- a/src/cmds/cat.ts +++ /dev/null @@ -1,9 +0,0 @@ -import FluorineClient from '@classes/Client'; -import Embed from '@classes/Embed'; -import { Message } from 'discord.js'; - -export async function run(client: FluorineClient, message: Message) { - const { file }: any = await (await fetch('https://api.alexflipnote.dev/cats')).json(); - const embed = new Embed(client, message.guild.preferredLocale).setLocaleTitle('CAT').setImage(file); - message.reply({ embeds: [embed] }); -} diff --git a/src/cmds/dev.ts b/src/cmds/dev.ts deleted file mode 100644 index bf757004..00000000 --- a/src/cmds/dev.ts +++ /dev/null @@ -1,40 +0,0 @@ -import FluorineClient from '@classes/Client'; -import Embed from '@classes/Embed'; -import { Message } from 'discord.js'; -import { clean } from '@util/clean'; -import { execSync } from 'child_process'; -export async function run(client: FluorineClient, message: Message, args: string[]) { - if (!client.devs.includes(message.author.id) || args.includes('client.token')) { - return message.reply('you wish'); - } - - let codex: any = args.join(' ').replaceAll('```js', '').replaceAll('```ts', ''); - if (codex.includes('```sh')) { - codex = codex.replaceAll('```sh', '').replaceAll('```', ''); - const output = execSync(codex).toString(); - const embed2 = new Embed(client, message.guild.preferredLocale) - .setTitle('Done!') - .setDescription(`\`\`\`sh\n${output}\n\`\`\``); - return message.reply({ embeds: [embed2] }); - } - if (codex.indexOf('```', codex.length - 4) !== -1) { - codex = codex.slice(0, -3); - } - const code = codex.replaceAll('client.token', '"no"'); - try { - const evaled = eval(code); - const cleant = await clean(client, evaled); - - const embed = new Embed(client, message.guild.preferredLocale) - .setTitle('Done!') - .setDescription(`\`\`\`js\n${cleant}\n\`\`\``); - message.reply({ embeds: [embed] }); - message.react('✅'); - } catch (err) { - const errorEmbed = new Embed(client, message.guild.preferredLocale) - .setTitle('Error') - .setDescription(`\`\`\`xl\n${await clean(client, err)}\n\`\`\``); - message.reply({ embeds: [errorEmbed] }); - message.react('❌'); - } -} diff --git a/src/cmds/dog.ts b/src/cmds/dog.ts deleted file mode 100644 index 2b7e6a5d..00000000 --- a/src/cmds/dog.ts +++ /dev/null @@ -1,9 +0,0 @@ -import FluorineClient from '@classes/Client'; -import Embed from '@classes/Embed'; -import { Message } from 'discord.js'; - -export async function run(client: FluorineClient, message: Message) { - const { file }: any = await (await fetch('https://api.alexflipnote.dev/dogs')).json(); - const embed = new Embed(client, message.guild.preferredLocale).setLocaleTitle('DOG').setImage(file); - message.reply({ embeds: [embed] }); -} diff --git a/src/cmds/help.ts b/src/cmds/help.ts deleted file mode 100644 index 074f9449..00000000 --- a/src/cmds/help.ts +++ /dev/null @@ -1,37 +0,0 @@ -import FluorineClient from '@classes/Client'; -import Embed from '@classes/Embed'; -import { Message, MessageActionRow, MessageSelectMenu } from 'discord.js'; - -export async function run(client: FluorineClient, message: Message) { - const embed = new Embed(client, message.guild.preferredLocale).setTitle('Help').setDescription('Select a category'); - const row = new MessageActionRow().addComponents([ - new MessageSelectMenu().setCustomId(`help:${message.author.id}`).setOptions([ - { - label: client.i18n.t('FUN', { - lng: message.guild.preferredLocale - }), - value: 'fun', - emoji: '🎮' - }, - { - label: client.i18n.t('TOOLS', { - lng: message.guild.preferredLocale - }), - value: 'tools', - emoji: '🛠️' - }, - { - label: client.i18n.t('MODERATION', { - lng: message.guild.preferredLocale - }), - value: 'moderation', - emoji: '🔨' - } - ]) - ]); - - message.channel.send({ - embeds: [embed], - components: [row] - }); -} diff --git a/src/cmds/howgay.ts b/src/cmds/howgay.ts deleted file mode 100644 index ce2f684b..00000000 --- a/src/cmds/howgay.ts +++ /dev/null @@ -1,27 +0,0 @@ -import FluorineClient from '@classes/Client'; -import { Message } from 'discord.js'; -import hash from 'murmurhash-v3'; - -export async function run(client: FluorineClient, message: Message, args: string[]) { - if (!args[0]) { - return message.reply( - client.i18n.t('HOWGAY_ARGS', { - lng: message.guild.preferredLocale - }) - ); - } - - const thing = message.mentions.users.first() ?? args.join(' '); - - const percent = ['<@478823932913516544>', '<@348591272476540928>'].includes(thing.toString()) - ? 100 - : hash(thing.toString()) % 101; - - message.reply( - client.i18n.t('HOWGAY', { - lng: message.guild.preferredLocale, - percent, - thing: thing.toString() - }) - ); -} diff --git a/src/cmds/inpost.ts b/src/cmds/inpost.ts deleted file mode 100644 index 22b4af69..00000000 --- a/src/cmds/inpost.ts +++ /dev/null @@ -1,41 +0,0 @@ -import FluorineClient from '@classes/Client'; -import Embed from '@classes/Embed'; -import { Message } from 'discord.js'; -export async function run(client: FluorineClient, message: Message, args: string[]) { - if (!args[0]) { - return message.reply( - client.i18n.t('INPOST_ARGS', { - lng: message.guild.preferredLocale - }) - ); - } - - const statusURL = client.i18n.t('INPOST_URL', { - lng: message.guild.preferredLocale - }); - const statuses: any = await fetch(statusURL).then(res => res.json()); - const req: any = await fetch(`https://api-shipx-pl.easypack24.net/v1/tracking/${args[0]}`); - const response = await req.json(); - if (req.status !== 200) { - return message.reply( - client.i18n.t('INPOST_NOT_FOUND', { - lng: message.guild.preferredLocale, - id: args[0] - }) - ); - } - const embed = new Embed(client, message.guild.preferredLocale) - .setLocaleTitle('INPOST_TITLE', { - id: args[0] - }) - .setColor('#ffcb39'); - - if (response.custom_attributes.target_machine_detail.name) { - embed.setLocaleDescription('INPOST_DESCRIPTION', response.custom_attributes.target_machine_detail); - } - response.tracking_details.reverse().forEach(data => { - const statusObj = statuses.items.find(element => element.name === data.status); - embed.addField(statusObj.title, statusObj.description); - }); - message.reply({ embeds: [embed] }); -} diff --git a/src/cmds/ping.ts b/src/cmds/ping.ts deleted file mode 100644 index c3c2c4d3..00000000 --- a/src/cmds/ping.ts +++ /dev/null @@ -1,10 +0,0 @@ -import FluorineClient from '@classes/Client'; -import Embed from '@classes/Embed'; -import { Message } from 'discord.js'; - -export async function run(client: FluorineClient, message: Message) { - const embed = new Embed(client, message.guild.preferredLocale) - .setTitle('Ping') - .addLocaleField({ name: 'PING', value: `${client.ws.ping}ms` }); - message.reply({ embeds: [embed] }); -} diff --git a/src/cmds/serverinfo.ts b/src/cmds/serverinfo.ts deleted file mode 100644 index 0906e3ea..00000000 --- a/src/cmds/serverinfo.ts +++ /dev/null @@ -1,29 +0,0 @@ -import FluorineClient from '@classes/Client'; -import Embed from '@classes/Embed'; -import { Message } from 'discord.js'; - -export async function run(client: FluorineClient, message: Message) { - const embed = new Embed(client, message.guild.preferredLocale) - .setLocaleTitle('SERVER_INFO') - .addLocaleField({ - name: 'SERVER_INFO_NAME', - value: message.guild.name - }) - .addLocaleField({ - name: 'SERVER_INFO_CREATED', - value: `` - }) - .addLocaleField({ - name: 'SERVER_INFO_MEMBERS', - value: `${message.guild?.memberCount}` - }) - .addLocaleField({ - name: 'SERVER_INFO_CHANNELS', - value: `${message.guild?.channels.cache.size}` - }) - .addLocaleField({ - name: 'SERVER_INFO_ROLES', - value: `${message.guild?.roles.cache.size}` - }); - message.reply({ embeds: [embed] }); -} diff --git a/src/cmds/skywars.ts b/src/cmds/skywars.ts deleted file mode 100644 index f44cf559..00000000 --- a/src/cmds/skywars.ts +++ /dev/null @@ -1,71 +0,0 @@ -import FluorineClient from '@classes/Client'; -import Embed from '@classes/Embed'; -import { HypixelType } from 'types/hypixel'; -import { Message } from 'discord.js'; -export async function run(client: FluorineClient, message: Message, args: string[]) { - if (!args[0]) { - return message.reply( - client.i18n.t('HYPIXEL_NO_ARGS', { - lng: message.guild.preferredLocale, - command: 'bedwars' - }) - ); - } - const uuid: any = await fetch(`https://api.mojang.com/users/profiles/minecraft/${args[0]}`).then(res => res.json()); - - if (!uuid.data.id) { - return message.reply( - client.i18n.t('HYPIXEL_INVALID_PLAYER', { - lng: message.guild.preferredLocale - }) - ); - } - const data = (await fetch( - `https://api.hypixel.net/player?uuid=${uuid.data.id}&key=${process.env.HYPIXEL_TOKEN}` - ).then(res => res.json())) as HypixelType; - - const skyStats = data.player?.stats?.SkyWars; - if (!skyStats) { - return message.reply( - client.i18n.t('HYPIXEL_PLAYER_NOT_FOUND', { - lng: message.guild.preferredLocale - }) - ); - } - const kd = (skyStats.kills / skyStats.deaths).toFixed(2); - const winratio = (skyStats.wins / skyStats.deaths).toFixed(2); - const embed = new Embed(client, message.guild.preferredLocale) - .setLocaleTitle('HYPIXEL_STATISTICS_TITLE', { - player: args[0] - }) - .setDescription(`K/D: ${kd}\n Win/loss ratio: ${winratio}`) - .addLocaleField({ - name: 'HYPIXEL_WON_GAMES', - value: `${skyStats.wins || 0}`, - inline: true - }) - .addLocaleField({ - name: 'HYPIXEL_LOST_GAMES', - value: `${skyStats.losses || 0}`, - inline: true - }) - .addField('\u200B', '\u200B', true) - .addLocaleField({ - name: 'HYPIXEL_KILLS', - value: `${skyStats.kills || 0}`, - inline: true - }) - .addLocaleField({ - name: 'HYPIXEL_DEATHS', - value: `${skyStats.deaths || 0}`, - inline: true - }) - .addField('\u200B', '\u200B', true) - .addLocaleField({ - name: 'HYPIXEL_ASSISTS', - value: `${skyStats.assists || 0}`, - inline: true - }) - .setThumbnail(`https://crafatar.com/avatars/${uuid.data.id}?default=MHF_Steve&overlay`); - message.reply({ embeds: [embed] }); -} diff --git a/src/commands/deploy/create.ts b/src/commands/deploy/create.ts index 27bc131f..deb23b26 100644 --- a/src/commands/deploy/create.ts +++ b/src/commands/deploy/create.ts @@ -9,7 +9,7 @@ export async function run(client: FluorineClient, interaction: CommandInteractio const name = interaction.options.getString('command'); let guildId = interaction.options.getString('guild'); - const command = client.applicationCommands.chatInput.get(name) ?? client.applicationCommands.contextMenu.get(name); + const command = client.commands.chatInput.get(name) ?? client.commands.contextMenu.get(name); if (!command && name !== 'all') { return interaction.reply({ @@ -31,11 +31,11 @@ export async function run(client: FluorineClient, interaction: CommandInteractio // @ts-expect-error await commands?.fetch(); - const chatInputCommands = client.applicationCommands.chatInput + const chatInputCommands = client.commands.chatInput .filter(c => 'category' in c && (commands.cache.some(cmd => cmd.name === 'deploy') || !c.dev)) .map(command => command.data.toJSON()); - const contextMenuCommands = client.applicationCommands.contextMenu + const contextMenuCommands = client.commands.contextMenu .filter(c => commands.cache.some(cmd => cmd.name === 'deploy') || !c.dev) .map(command => command.data.toJSON()); diff --git a/src/commands/deploy/delete.ts b/src/commands/deploy/delete.ts index 2e43834f..d8068d32 100644 --- a/src/commands/deploy/delete.ts +++ b/src/commands/deploy/delete.ts @@ -26,7 +26,7 @@ export async function run(client: FluorineClient, interaction: CommandInteractio await client.restModule.put(route, { body: guildId && commands.cache.some(c => c.name === 'deploy') - ? [client.applicationCommands.chatInput.get('deploy').data.toJSON()] + ? [client.commands.chatInput.get('deploy').data.toJSON()] : [] }); } else { diff --git a/src/commands/dev/reload.ts b/src/commands/dev/reload.ts index d0d6b177..7bf2b384 100644 --- a/src/commands/dev/reload.ts +++ b/src/commands/dev/reload.ts @@ -55,12 +55,12 @@ export async function run(client: FluorineClient, interaction: CommandInteractio case 'commands': { if (module === 'all') { - await client.applicationCommands.loadChatInput(); + await client.commands.loadChatInput(); return interaction.editReply('Reloaded `all` chat input commands.'); } const commandFile = await import(`./../../commands/${module}`); - client.applicationCommands.chatInput.set(module, commandFile); + client.commands.chatInput.set(module, commandFile); interaction.editReply(`Reloaded the \`${module}\` chat input command.`); break; @@ -68,12 +68,12 @@ export async function run(client: FluorineClient, interaction: CommandInteractio case 'context': { if (module === 'all') { - await client.applicationCommands.loadContextMenu(); + await client.commands.loadContextMenu(); return interaction.editReply('Reloaded `all` context menu commands.'); } const commandFile = await import(`./../../context/${module}`); - client.applicationCommands.contextMenu.set(module, commandFile); + client.commands.contextMenu.set(module, commandFile); interaction.editReply(`Reloaded the \`${module}\` context menu command.`); break; diff --git a/src/commands/dev/shell.ts b/src/commands/dev/shell.ts index 73969830..74bf4783 100644 --- a/src/commands/dev/shell.ts +++ b/src/commands/dev/shell.ts @@ -5,10 +5,6 @@ import { execSync } from 'child_process'; import { CommandInteraction } from 'discord.js'; export async function run(client: FluorineClient, interaction: CommandInteraction) { - if (process.env.NODE_ENV === 'production' && interaction.user.id !== '707675871355600967') { - interaction.reply({ content: "You aren't Kubus!", ephemeral: true }); - } - await interaction.deferReply(); const script = interaction.options.getString('script'); script.replace('```\nsh', '').replace('\n```', ''); diff --git a/src/commands/dev/sql.ts b/src/commands/dev/sql.ts index 7d66788c..152f37ac 100644 --- a/src/commands/dev/sql.ts +++ b/src/commands/dev/sql.ts @@ -5,10 +5,6 @@ import { clean } from '@util/clean'; import { CommandInteraction } from 'discord.js'; export async function run(client: FluorineClient, interaction: CommandInteraction) { - if (process.env.NODE_ENV === 'production' && interaction.user.id !== '707675871355600967') { - interaction.reply({ content: "You aren't Kubus!", ephemeral: true }); - } - await interaction.deferReply(); const code = interaction.options.getString('code'); code.replace('```\nsql', '').replace('\n```', ''); diff --git a/src/commands/help.ts b/src/commands/help.ts index f1561f3a..33ba8188 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -6,9 +6,7 @@ import { Category, ChatInputCommand } from 'types/structures'; export async function run(client: FluorineClient, interaction: CommandInteraction) { const category = interaction.options.getString('category'); - const commands = client.applicationCommands.chatInput.filter( - (c: ChatInputCommand) => c.category === category && !c.dev - ); + const commands = client.commands.chatInput.filter((c: ChatInputCommand) => c.category === category && !c.dev); const fields: EmbedFieldData[] = commands.map(c => ({ name: `/${c.data.name_localizations[interaction.locale] ?? c.data.name}`, diff --git a/src/components/help.ts b/src/components/help.ts index 3619c3ea..39479ad6 100644 --- a/src/components/help.ts +++ b/src/components/help.ts @@ -7,9 +7,7 @@ export const authorOnly = true; export async function run(client: FluorineClient, interaction: SelectMenuInteraction) { const [category] = interaction.values; - const commands = client.applicationCommands.chatInput.filter( - (c: ChatInputCommand) => c.category === category && !c.dev - ); + const commands = client.commands.chatInput.filter((c: ChatInputCommand) => c.category === category && !c.dev); const fields: EmbedFieldData[] = commands.map(c => ({ name: `/${c.data.name_localizations[interaction.locale] ?? c.data.name}`, diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index 1925a53c..af8bcc03 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -18,7 +18,7 @@ export async function run(client: FluorineClient, interaction: Interaction) { component?.run(client, interaction, value); } else if (interaction.isContextMenu()) { - const contextCommand = client.applicationCommands.contextMenu.get(interaction.commandName); + const contextCommand = client.commands.contextMenu.get(interaction.commandName); if (contextCommand.dev && !client.devs.includes(interaction.user.id)) { return interaction.reply({ @@ -32,8 +32,8 @@ export async function run(client: FluorineClient, interaction: Interaction) { const subcommand = interaction.options.getSubcommand(false); const key = subcommand ? `${interaction.commandName}/${subcommand}` : interaction.commandName; - const command = client.applicationCommands.chatInput.get(key); - const { dev } = client.applicationCommands.chatInput.get(interaction.commandName) as ChatInputCommand; + const command = client.commands.chatInput.get(key); + const { dev } = client.commands.chatInput.get(interaction.commandName) as ChatInputCommand; if (command.cooldown) { const cooldown = await client.cooldowns.get(interaction.user, key); diff --git a/src/events/messageCreate.ts b/src/events/messageCreate.ts index a814993b..2989bf6f 100644 --- a/src/events/messageCreate.ts +++ b/src/events/messageCreate.ts @@ -1,5 +1,4 @@ import FluorineClient from '@classes/Client'; -import Embed from '@classes/Embed'; import { Message, MessageActionRow, MessageButton } from 'discord.js'; export async function run(client: FluorineClient, message: Message) { @@ -62,54 +61,31 @@ export async function run(client: FluorineClient, message: Message) { } } - const args = message.content.slice(prefix.length).split(' '); - const command = args.shift(); - - if (message.content.startsWith(prefix)) { - const chance = 5; - const random = Math.floor(Math.random() * chance) + 1; + if (message.content === `<@${client.user.id}>`) { + return message.channel.send(client.i18n.t('MESSAGE_MENTION', { lng: message.guild.preferredLocale })); + } - if (random === 1) { - const removalTimestamp = 1656676800; - await client.application.fetch(); - message.channel.send({ - content: `<:SlashCommands:934768130474004500> **Use Slash Commands!**\nPrefix (message) commands are not supported and will be removed ! ()\nIf you can't see Slash Commands, make sure to reinvite the bot`, - components: [ - new MessageActionRow().addComponents([ - new MessageButton() - .setLabel('Bot Invite') - .setStyle('LINK') - .setURL(client.generateInvite(client.application.installParams)), - new MessageButton().setLabel('Support Server').setStyle('LINK').setURL(client.support) - ]) - ] - }); - } + const command = message.content.slice(prefix.length).split(' ').shift(); - const code = client.cmds.get(command); - code?.run(client, message, args); - } else if (message.content === `<@!${client.user.id}>` || message.content === `<@${client.user.id}>`) { - const embed = new Embed(client, message.guild.preferredLocale) - .setTitle('Fluorine') - .setLocaleDescription('MESSAGE_CREATE_DESCRIPTION', { - prefix - }) - .addLocaleField({ - name: 'STATS_SERVER_COUNT', - value: client.guilds.cache.size.toString() - }) - .addLocaleField({ - name: 'STATS_USER_COUNT', - value: client.users.cache.size.toString() - }) - .addLocaleField({ - name: 'STATS_COMMAND_COUNT', - value: client.cmds.size.toString() - }) - .addLocaleField({ - name: 'STATS_CHANNELS_COUNT', - value: client.channels.cache.size.toString() - }); - message.channel.send({ embeds: [embed] }); + if (!message.content.startsWith(prefix) || !client.commands.chatInput.has(command)) { + return; } + + await client.application.fetch(); + message.channel.send({ + content: `<:SlashCommands:934768130474004500> **Use Slash Commands!**\nThis command can only be used via the Slash Command \`/${command}\`.\nIf you can't see Slash Commands, make sure to re-invite the bot`, + components: [ + new MessageActionRow().addComponents([ + new MessageButton() + .setLabel('Bot Invite') + .setStyle('LINK') + .setURL( + client.generateInvite( + client.application.installParams ?? { scopes: ['bot', 'applications.commands'] } + ) + ), + new MessageButton().setLabel('Support Server').setStyle('LINK').setURL(client.support) + ]) + ] + }); } diff --git a/src/events/ready.ts b/src/events/ready.ts index 87295a05..6424207b 100644 --- a/src/events/ready.ts +++ b/src/events/ready.ts @@ -8,7 +8,7 @@ export async function run(client: FluorineClient) { if (!commands.some(c => c.name === 'deploy')) { const route = Routes.applicationGuildCommands(client.user.id, process.env.DISCORD_DEV_GUILD); - const command = client.applicationCommands.chatInput.get('deploy'); + const command = client.commands.chatInput.get('deploy'); await client.restModule.post(route, { body: command.data.toJSON() diff --git a/src/types/command.ts b/src/types/command.ts deleted file mode 100644 index 1b9db13d..00000000 --- a/src/types/command.ts +++ /dev/null @@ -1,6 +0,0 @@ -import FluorineClient from '@classes/Client'; -import { Message } from 'discord.js'; - -export interface Command { - run: (client: FluorineClient, message: Message, args: string[]) => void; -} diff --git a/src/util/info.ts b/src/util/info.ts index 6e79d651..61c7dc2f 100644 --- a/src/util/info.ts +++ b/src/util/info.ts @@ -71,7 +71,7 @@ export async function getEmbed(client: FluorineClient, interaction: Interaction, }) .addLocaleField({ name: 'INFO_STATS_COMMANDS', - value: client.applicationCommands.chatInput.size.toString(), + value: client.commands.chatInput.size.toString(), inline: true }) .addLocaleField({