diff --git a/requirements.txt b/requirements.txt index c4a319c..3f2dcaf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,5 @@ beautifulsoup4~=4.11.1 pandas~=1.4.2 PyVirtualDisplay~=3.0 selenium~=4.2.0 -plotly~=5.8.0 \ No newline at end of file +plotly~=5.8.0 +fuzzywuzzy~=0.18.0 \ No newline at end of file diff --git a/source/bot.py b/source/bot.py index 18ffd3e..60e3099 100644 --- a/source/bot.py +++ b/source/bot.py @@ -16,6 +16,7 @@ import sys import datetime as dt import time from xml.dom.pulldom import START_DOCUMENT +from fuzzywuzzy import fuzz import sqlalchemy import telebot @@ -751,9 +752,25 @@ def echo_all(message): Args: message (Message): user message that doesnt match any of the commands """ + user_id = int(message.from_user.id) + + possible_commands = ['/addproduct', '/daily', '/help', '/me', '/gameinfo', '/scoreboard', '/changename', '/setadmin', '/users', ] # all possible commands + matching_commands = [] + + for command in possible_commands: + print(fuzz.ratio(command, message.text)) + if fuzz.ratio(command, message.text) > 79: # If word is similar enough for suggestion + matching_commands.append(command) + + answer = 'Do not know this command or text: ' + message.text bot.reply_to(message, answer) + # send all possible matches + if len(matching_commands)>0: + bot.send_message(chat_id=user_id, text='Did you mean: ' + ', '.join(matching_commands)) + + # inline prints for debugging @bot.inline_handler(lambda query: query.query == 'text') def query_text(inline_query):