diff --git a/src/BaseClient/Other/language/slashCommands.ts b/src/BaseClient/Other/language/slashCommands.ts index f88e647a5..7d8e11a45 100644 --- a/src/BaseClient/Other/language/slashCommands.ts +++ b/src/BaseClient/Other/language/slashCommands.ts @@ -52,4 +52,5 @@ export default (t: CT.Language) => ({ info: info(t), settings: settings(t), giveaway: giveaway(t), + useSlashCommands: (c: string) => t.stp(t.JSON.slashCommands.useSlashCommands, { c }), }); diff --git a/src/Events/messageEvents/messageCreate/commandHandler.ts b/src/Events/messageEvents/messageCreate/commandHandler.ts index e3fd20707..22ad86583 100644 --- a/src/Events/messageEvents/messageCreate/commandHandler.ts +++ b/src/Events/messageEvents/messageCreate/commandHandler.ts @@ -1,3 +1,4 @@ +import * as stringSimilarity from 'string-similarity'; import * as Jobs from 'node-schedule'; import * as Discord from 'discord.js'; import { glob } from 'glob'; @@ -23,7 +24,8 @@ const dmCommand = async (msg: Discord.Message) => { .trim() .split(/\s+|\n+/g); - const command = await getComand(args.shift()?.toLowerCase() as string); + const commandName = args.shift()?.toLowerCase() as string; + const command = await getComand(commandName); if (!command) return; if (!command.dmAllowed) return; @@ -44,7 +46,40 @@ const guildCommand = async (msg: Discord.Message) => { if (!commandName) return; const command = await getComand(commandName); - if (!command) return; + if (!command) { + const allSlashCommands = (await glob(`${process.cwd()}/Commands/SlashCommands/**/*`)) + .filter((f) => f.endsWith('.js') && !f.endsWith('.map.js')) + .map((f) => f.replace(`${process.cwd()}/Commands/SlashCommands/`, '').replace('.js', '')) + .filter((f) => !f.includes('/')); + + const slashCommand = await getSlashCommand( + msg.guild, + stringSimilarity.findBestMatch(commandName, allSlashCommands).bestMatch.target, + ); + if (!slashCommand) return; + + const canUse = checkCommandPermissions(msg, commandName); + if (!canUse) { + const reaction = await ch.request.channels.addReaction( + msg, + ch.constants.standard.getEmoteIdentifier(ch.emotes.cross), + ); + + if (typeof reaction !== 'undefined') ch.error(msg.guild, new Error(reaction.message)); + return; + } + + const language = await ch.getLanguage(msg.author.id); + const embed: Discord.APIEmbed = { + description: language.slashCommands.useSlashCommands( + ``, + ), + color: ch.constants.colors.ephemeral, + }; + + ch.replyMsg(msg, { embeds: [embed] }); + return; + } if (command.thisGuildOnly?.length && command.thisGuildOnly?.includes(msg.guildId)) return; if (command.type === 'owner' && msg.author.id !== auth.ownerID) return; @@ -132,6 +167,9 @@ const getComand = async (commandName: string) => { return (await import(path)) as CT.Command; }; +const getSlashCommand = (guild: Discord.Guild, commandName: string) => + ch.getCustomCommand(guild, commandName as Parameters[1]); + export const checkCommandPermissions = ( msg: { guildId: string; diff --git a/src/Languages/en-GB.json b/src/Languages/en-GB.json index dfc8abd8d..a3064981f 100644 --- a/src/Languages/en-GB.json +++ b/src/Languages/en-GB.json @@ -1358,6 +1358,7 @@ "antirad": "{{t.botName}} Anti-Raid" }, "slashCommands": { + "useSlashCommands": "Unknown Command. Did you mean {{c}}?", "setLevel": { "reset": "Reset", "save": "Save and Apply", @@ -1380,8 +1381,8 @@ "areYouSure2": "Are you sure you want to reset all Levels?\n**This cannot be un-done!**", "all": "All Levels have been reset", "areYouSure": "Are you sure you want to reset all Levels?\n**This cannot be un-done!**\n__Notice__: This will not un-assign Level-Roles\n\nThe Buttons will unlock {{t}}", - "confirmUser": "Confirm Reset of Levels of\n{{t.languageFunction.getUser(user)}}", - "confirmRole": "Confirm Reset of Levels of all {{amount}} Members in\n{{t.languageFunction.getRole(role)}}", + "confirmUser": "Confirm Reset of Levels of\n{{user}}", + "confirmRole": "Confirm Reset of Levels of all {{amount}} Members in\n{{role}}", "user": "The Levels of\n{{user}}have been reset", "role": "The Levels of all {{amount}} Members in\n{{role)}}have been reset" },