-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot2.py
67 lines (51 loc) · 2.27 KB
/
bot2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, ParseMode
from load_data import tdy, tmr, load_data, format_menu
import os
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
data = load_data()
def start(bot, update):
keyboard = [[InlineKeyboardButton("Today's Menu", callback_data='today'),
InlineKeyboardButton("Tomorrow's Menu", callback_data='tomorrow')]]
reply_markup = InlineKeyboardMarkup(keyboard)
update.message.reply_text('Please choose:', reply_markup=reply_markup)
def button(bot, update):
query = update.callback_query
if query.data == 'today':
bot.edit_message_text(
text='*TODAY\'S MENU:* \n' + format_menu(data[tdy]),
parse_mode=ParseMode.MARKDOWN,
chat_id=query.message.chat_id,
message_id=query.message.message_id)
elif query.data == 'tomorrow':
bot.edit_message_text(
text='*TOMORROW\'S MENU:* \n' + format_menu(data[tmr]),
parse_mode=ParseMode.MARKDOWN,
chat_id=query.message.chat_id,
message_id=query.message.message_id)
else:
bot.sendmessage(query.message.chat_id,"dunno??")
def help(bot, update):
update.message.reply_text("Use /start to test this bot.")
def error(bot, update, error):
"""Log Errors caused by Updates."""
logger.warning('Update "%s" caused error "%s"', update, error)
def main():
# Create the Updater and pass it your bot's token.
updater = Updater(os.environ.get('TOKEN'))
updater.dispatcher.add_handler(CommandHandler('start', start))
updater.dispatcher.add_handler(CallbackQueryHandler(button))
updater.dispatcher.add_handler(CommandHandler('help', help))
updater.dispatcher.add_error_handler(error)
# Start the Bot
updater.start_polling()
# Run the bot until the user presses Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT
updater.idle()
if __name__ == '__main__':
main()