-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
86 lines (74 loc) · 3.63 KB
/
main.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from telegram.ext import Updater
from telegram import InlineKeyboardMarkup, InlineKeyboardButton
from settings import Settings
from strings import Strings
from bot import enqueue, send_message, send_group_message, add_handler, run
from game import Game
game = Game()
join_message = None
def hello(bot, update):
update.message.reply_text('hello, {}'.format(update.message.from_user.first_name))
def new(bot, update):
global join_message
global join_reply_markup
if update.message.chat.id == Settings.CHAT_ID:
game.new(update.message.from_user)
update.message.reply_text(Strings.NEW)
join_message = bot.send_message(Settings.CHAT_ID, Strings.ADMIN_JOIN.format('@' + update.message.from_user.username),
reply_markup = InlineKeyboardMarkup([[
InlineKeyboardButton(Strings.JOIN_BUTTON, url = Settings.BOT_URL + '?start=join')]]))
def join(bot, update):
if update.message.chat.type == 'private':
if update.message.text == '/start join':
status = game.status
game.add_player(update.message.from_user, update.message.chat)
enqueue(update.message.reply_text, Strings.JOINED)
send_group_message(Strings.NAMED_JOINED.format('@' + update.message.from_user.username))
if status is game.Status.PREPARING and game.status is game.Status.OPEN:
enqueue(join_message.edit_text, Strings.JOIN,
reply_markup = InlineKeyboardMarkup([[
InlineKeyboardButton(Strings.JOIN_BUTTON, url = Settings.BOT_URL + '?start=join'),
InlineKeyboardButton(Strings.WATCH_BUTTON, url = Settings.BOT_URL + '?start=watch')]]))
send_message(update.message.chat.id, Strings.START,
reply_markup = InlineKeyboardMarkup([[
InlineKeyboardButton(Strings.START_BUTTON, callback_data = 'start')]]))
elif update.message.text == '/start watch':
game.add_audience(update.message.from_user, update.message.chat)
enqueue(update.message.reply_text, Strings.WATCHED)
send_group_message(Strings.NAMED_WATCHED.format('@' + update.message.from_user.username))
else:
raise
def abort(bot, update):
if update.message.chat.id == Settings.CHAT_ID:
game.abort(update.message.from_user)
enqueue(update.message.reply_text, Strings.ABORT)
def quit(bot, update):
game.quit(update.message.from_user)
send_group_message(Strings.QUIT.format('@' + update.message.from_user.username))
def start(bot, update):
game.start(update.callback_query.from_user)
enqueue(join_message.edit_reply_markup)
enqueue(update.callback_query.edit_message_reply_markup)
send_group_message(Strings.STARTED)
game.next()
def rule(bot, update):
enqueue(update.message.reply_text, Strings.RULE, parse_mode = 'Markdown')
def discharge(bot, update):
game.discharge(update.callback_query.from_user, int(update.callback_query.data[-1]))
enqueue(update.callback_query.edit_message_reply_markup)
def choose(bot, update):
game.choose(update.callback_query.from_user, int(update.callback_query.data[-1]))
enqueue(update.callback_query.edit_message_reply_markup)
def resume(bot, update):
return
add_handler('command', hello)
add_handler('command', new)
add_handler('command', abort)
add_handler('command', join, 'start')
add_handler('command', quit)
add_handler('callback_query', start)
add_handler('command', rule)
add_handler('callback_query', discharge, '^discharge \d$')
add_handler('callback_query', choose, '^choose \d$')
add_handler('command', resume)
run()