- Automated command retrieval for the spellchecker, ignoring commands reserved for the owner.

This commit is contained in:
Florian Sylvain
2021-03-31 22:11:33 +02:00
parent 1621d4a9dc
commit 8fd8eb2a18
2 changed files with 13 additions and 5 deletions
+12 -2
View File
@@ -23,6 +23,7 @@ logger = logging.getLogger(__name__)
logger.addHandler(handler) logger.addHandler(handler)
logger.setLevel(logging.INFO) logger.setLevel(logging.INFO)
commandlist = []
@bot.event @bot.event
async def on_ready(): async def on_ready():
@@ -38,13 +39,22 @@ async def on_command_error(ctx, error):
' \'' + str(error) + '\' from ' +str(ctx.author) + ' on ' + ' \'' + str(error) + '\' from ' +str(ctx.author) + ' on ' +
(ctx.message.guild.name if ctx.message.guild is not None else 'DMs') + '.') (ctx.message.guild.name if ctx.message.guild is not None else 'DMs') + '.')
if isinstance(error, commands.CommandNotFound): 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: else:
await ctx.send(error) await ctx.send(error)
if __name__ == "__main__": def init():
for extension in startup_extensions: for extension in startup_extensions:
bot.load_extension('ext.' + extension) bot.load_extension('ext.' + extension)
print('Extension "' + str(extension) + '" loaded.') 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) bot.run(TOKEN_BOT)
+1 -3
View File
@@ -7,8 +7,7 @@ def all_maximum(lst):
return lst_result return lst_result
def spellchecker(word): def spellchecker(word, lst):
lst = ['osu_acc','osu_lastgame','osu_profile','lol_rank','lol_lastgame','chat_set','chat_stop','issou','help']
probs = [] probs = []
wo_size = len(word) wo_size = len(word)
for element in lst: for element in lst:
@@ -27,4 +26,3 @@ def spellchecker(word):
for indice in lst_maxs: for indice in lst_maxs:
str_words += '$' + lst[indice] + ' ?\n' str_words += '$' + lst[indice] + ' ?\n'
return str_words return str_words