-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
49 lines (41 loc) · 1.38 KB
/
server.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
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
from telegram import ReplyKeyboardMarkup, ReplyKeyboardRemove
import logging
import yaml
import actions as action
from imset import load_imsets
from objectdict import ObjectDict
no_keyboard = ReplyKeyboardRemove()
action_keyboard = ReplyKeyboardMarkup([['/make', '/guess']], resize_keyboard=True)
with open('config.yaml') as f:
config = yaml.load(f, Loader=yaml.FullLoader)
config['keyboard'] = {
'action': action_keyboard,
'empty': no_keyboard
}
config = ObjectDict(config)
load_imsets(config)
action.use_config(config)
updater = Updater(token=config.token, use_context=True)
dispatcher = updater.dispatcher
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
action_dict = {
'start': action.start,
'help': action.help,
'team': action.team,
'name': action.name,
'stat': action.stat,
'make': action.make,
'guess': action.guess
}
for name, func in action_dict.items():
dispatcher.add_handler(CommandHandler(name, func))
def text_back(update, context):
if context.chat_data.get('make'):
action.make_answer(update, context)
elif context.chat_data.get('guess'):
action.guess_answer(update, context)
text_handler = MessageHandler(Filters.text, text_back)
dispatcher.add_handler(text_handler)
updater.start_polling()