Skip to content

Commit 5aae1a1

Browse files
telegram bot keyboard buttons fix
1 parent 2dfece2 commit 5aae1a1

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

telegram_bot/dispatcher.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def _setup_dispatcher(self):
2222
conversation_handler = ConversationHandler(
2323
entry_points=[
2424
CommandHandler('start', logic.handle_start),
25-
MessageHandler(Filters.all, logic.handle_other_messages)
25+
MessageHandler(Filters.all, logic.handle_start_menu)
2626
],
2727
states={
2828
MenuEntry.START_MENU.value: [
@@ -51,15 +51,14 @@ def _setup_dispatcher(self):
5151
MessageHandler(Filters.text, logic.handle_equation_query)
5252
],
5353
MenuEntry.TAYLOR_SERIES.value: [
54-
MessageHandler(Filters.text,
55-
logic.handle_taylor_series_query)
54+
MessageHandler(
55+
Filters.text,
56+
logic.handle_taylor_series_query
57+
)
5658
],
5759
MenuEntry.EXTREMA.value: [
5860
MessageHandler(Filters.text, logic.handle_extrema_query)
5961
],
60-
MenuEntry.TOGGLE_MODE.value: [
61-
MessageHandler(Filters.text, logic.handle_mode_toggling)
62-
]
6362
},
6463
fallbacks=[]
6564
)

telegram_bot/logic.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from telegram_bot.tools import send_typing, write_logs, remember_new_user
99
from telegram_bot.models import User
1010
from telegram_bot.menu import MenuEntry
11+
from telegram.error import TimedOut
1112

1213
from wolfram_tools.requests import make_wolfram_request
1314

@@ -303,7 +304,9 @@ def handle_examples(bot, update):
303304
def handle_detailed_mode(bot, update):
304305
db.session.query(User).filter_by(
305306
telegram_id=update.message.from_user.id
306-
).update(dict(simple_mode=False))
307+
).update({
308+
'simple_mode': False
309+
})
307310
db.session.commit()
308311
bot.send_message(
309312
chat_id=update.message.chat_id,
@@ -317,7 +320,9 @@ def handle_detailed_mode(bot, update):
317320
def handle_simple_mode(bot, update):
318321
db.session.query(User).filter_by(
319322
telegram_id=update.message.from_user.id
320-
).update(dict(simple_mode=True))
323+
).update({
324+
'simple_mode': True
325+
})
321326
db.session.commit()
322327
bot.send_message(
323328
chat_id=update.message.chat_id,
@@ -381,12 +386,8 @@ def handle_errors(bot, update, error):
381386
logging.warning('Update {} caused {} error'.format(update, error))
382387
try:
383388
raise error
384-
except TimeoutError:
385-
bot.send_message(
386-
chat_id=update.message.chat_id,
387-
text='Connection problems... Please, try again'
388-
)
389-
handle_start(bot, update)
389+
except TimedOut:
390+
pass
390391
except Exception:
391392
bot.send_message(
392393
chat_id=update.message.chat_id,

telegram_bot/menu.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
'EQUATION',
1717
'TAYLOR_SERIES',
1818
'EXTREMA',
19-
'TOGGLE_MODE'
2019
],
2120
count()
2221
)

0 commit comments

Comments
 (0)