sending commands that are almost matching if user has a typo
This commit is contained in:
parent
fb5ac48f50
commit
a6d06f2cf1
@ -8,4 +8,5 @@ beautifulsoup4~=4.11.1
|
|||||||
pandas~=1.4.2
|
pandas~=1.4.2
|
||||||
PyVirtualDisplay~=3.0
|
PyVirtualDisplay~=3.0
|
||||||
selenium~=4.2.0
|
selenium~=4.2.0
|
||||||
plotly~=5.8.0
|
plotly~=5.8.0
|
||||||
|
fuzzywuzzy~=0.18.0
|
@ -16,6 +16,7 @@ import sys
|
|||||||
import datetime as dt
|
import datetime as dt
|
||||||
import time
|
import time
|
||||||
from xml.dom.pulldom import START_DOCUMENT
|
from xml.dom.pulldom import START_DOCUMENT
|
||||||
|
from fuzzywuzzy import fuzz
|
||||||
|
|
||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
import telebot
|
import telebot
|
||||||
@ -751,9 +752,25 @@ def echo_all(message):
|
|||||||
Args:
|
Args:
|
||||||
message (Message): user message that doesnt match any of the commands
|
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
|
answer = 'Do not know this command or text: ' + message.text
|
||||||
bot.reply_to(message, answer)
|
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
|
# inline prints for debugging
|
||||||
@bot.inline_handler(lambda query: query.query == 'text')
|
@bot.inline_handler(lambda query: query.query == 'text')
|
||||||
def query_text(inline_query):
|
def query_text(inline_query):
|
||||||
|
Loading…
Reference in New Issue
Block a user