-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
44 lines (37 loc) · 1.71 KB
/
bot.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
import telegram
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
from time import sleep
import mensa
token = open('token').read()
bot = telegram.Bot(token = token)
def prtFood(today, type):
food = '*' + type + ':*\n'
for n, val in enumerate(today):
food += today[n]['Name'] + ':\n' + ' _' + today[n]['Price'] + '_\n'
return food
def start(bot, update):
bot.sendMessage(update.message.chat_id, text='Hi! You can use this bot to check the menue of the TU Mensa (Hardenbergstrasse).\n/food\n/starters\n/soups\n/salads\n/side_dishes\n/special\n/desserts')
def all(bot, update):
food(bot, update)
starters(bot, update)
soups(bot, update)
salads(bot, update)
side_dishes(bot, update)
special(bot, update)
desserts(bot, update)
def functionify(type, name):
return lambda bot, update: bot.sendMessage(update.message.chat_id, text=prtFood(mensa.today(type), name), parse_mode = telegram.ParseMode.MARKDOWN)
updater = Updater(token)
dp = updater.dispatcher
dp.add_handler(MessageHandler([Filters.text], all))
dp.add_handler(CommandHandler("start", start))
dp.add_handler(CommandHandler("food", functionify('food', 'Hauptgerichte')))
dp.add_handler(CommandHandler("starters", functionify('starters', 'Vorspeisen')))
dp.add_handler(CommandHandler("soups", functionify('soups', 'Suppen')))
dp.add_handler(CommandHandler("salads", functionify('salads', 'Salate')))
dp.add_handler(CommandHandler("side_dishes", functionify('side_dishes', 'Beilagen')))
dp.add_handler(CommandHandler("desserts", functionify('desserts', 'Nachspeisen')))
dp.add_handler(CommandHandler("special", functionify('special', 'Aktionsstand')))
dp.add_handler(CommandHandler("all", all))
updater.start_polling()
updater.idle()