diff --git a/python/ext/cmd_lol.py b/python/ext/cmd_lol.py index bb36e07..aec6183 100644 --- a/python/ext/cmd_lol.py +++ b/python/ext/cmd_lol.py @@ -2,7 +2,6 @@ import discord import asyncio from discord.ext import commands from discord.ext.commands.cooldowns import BucketType -from private import TOKEN_RIOT from api_riot import rank_track, what_player, last_match CD_LOLRANK = 0 diff --git a/python/main.py b/python/main.py index af21746..e631d3c 100644 --- a/python/main.py +++ b/python/main.py @@ -2,6 +2,7 @@ from private import TOKEN_BOT from time import time from datetime import datetime from discord.ext import commands +from miscellaneous import spellchecker import discord @@ -22,7 +23,10 @@ async def on_ready(): @bot.event async def on_command_error(ctx, error): print(datetime.now().strftime("[%H:%M:%S]") + ' \'' + str(error) + '\' from ' + str(ctx.author) + ' on ' + ctx.message.guild.name + '.') - await ctx.send(error) + if isinstance(error, commands.CommandNotFound): + await ctx.send(spellchecker(str(ctx.message.content)[1:])) + else: + await ctx.send(error) @bot.command(hidden=True, ignore_extra=False) diff --git a/python/miscellaneous.py b/python/miscellaneous.py new file mode 100644 index 0000000..907fe26 --- /dev/null +++ b/python/miscellaneous.py @@ -0,0 +1,33 @@ +def all_maximum(lst): + lst_result = [] + nbmax = max(lst) + for i, j in enumerate(lst): + if j == nbmax: + lst_result.append(i) + return lst_result + + +def spellchecker(word): + lst = ['osu_acc','osu_lastgame','osu_profile','lol_rank','lol_lastgame','chat_set','chat_stop','issou','help'] + probs = [] + wo_size = len(word) + for element in lst: + prob = 0 + el_size = len(element) + for car in element: + for c in word: + if car == c: + prob += 1 + for i in range(4): + if el_size == wo_size - i: + prob += 4-i + probs.append(prob) + lst_maxs = all_maximum(probs) + str_words = 'This command does not seems to exist, did you mean :\n' + for indice in lst_maxs: + str_words += '$' + lst[indice] + ' ?\n' + return str_words + + +if __name__ == '__main__': + main()