From 8fd8eb2a187f7bd5d83f185448dabc015ca4c242 Mon Sep 17 00:00:00 2001 From: Florian Sylvain Date: Wed, 31 Mar 2021 22:11:33 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20-=20Automated=20command=20retrieval?= =?UTF-8?q?=20for=20the=20spellchecker,=20ignoring=20commands=20reserved?= =?UTF-8?q?=20for=20the=20owner.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/main.py | 14 ++++++++++++-- python/miscellaneous.py | 4 +--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/python/main.py b/python/main.py index 826d393..4c6a4ea 100644 --- a/python/main.py +++ b/python/main.py @@ -23,6 +23,7 @@ logger = logging.getLogger(__name__) logger.addHandler(handler) logger.setLevel(logging.INFO) +commandlist = [] @bot.event async def on_ready(): @@ -38,13 +39,22 @@ async def on_command_error(ctx, error): ' \'' + str(error) + '\' from ' +str(ctx.author) + ' on ' + (ctx.message.guild.name if ctx.message.guild is not None else 'DMs') + '.') if isinstance(error, commands.CommandNotFound): - await ctx.send(spellchecker(str(ctx.message.content)[1:])) + await ctx.send(spellchecker(str(ctx.message.content)[1:], commandlist)) else: await ctx.send(error) -if __name__ == "__main__": +def init(): for extension in startup_extensions: bot.load_extension('ext.' + extension) print('Extension "' + str(extension) + '" loaded.') + ignore = list(map(lambda cmd : cmd.name, bot.cogs["Owner commands"].get_commands())) + for command in bot.commands: + name = command.name + if not name in ignore: + commandlist.append(name) + + +if __name__ == "__main__": + init() bot.run(TOKEN_BOT) diff --git a/python/miscellaneous.py b/python/miscellaneous.py index d9dcd2c..fe9c6d4 100644 --- a/python/miscellaneous.py +++ b/python/miscellaneous.py @@ -7,8 +7,7 @@ def all_maximum(lst): return lst_result -def spellchecker(word): - lst = ['osu_acc','osu_lastgame','osu_profile','lol_rank','lol_lastgame','chat_set','chat_stop','issou','help'] +def spellchecker(word, lst): probs = [] wo_size = len(word) for element in lst: @@ -27,4 +26,3 @@ def spellchecker(word): for indice in lst_maxs: str_words += '$' + lst[indice] + ' ?\n' return str_words -