mirror of
https://github.com/Floriansylvain/Risitas_BOT.git
synced 2026-08-19 11:43:16 +02:00
✨ - Spellchecker for wrong commands
This commit is contained in:
@@ -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
|
||||
|
||||
+5
-1
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user