forked from jh0ker/mau_mau_bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
results.py
229 lines (190 loc) · 6.75 KB
/
results.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Telegram bot to play UNO in group chats
# Copyright (c) 2016 Jannes Höke <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Defines helper functions to build the inline result list"""
from uuid import uuid4
from telegram import InlineQueryResultArticle, InputTextMessageContent, \
InlineQueryResultCachedSticker as Sticker
import card as c
from utils import display_color, display_color_group, display_name
from internationalization import _, __
def add_choose_color(results, game):
"""Add choose color options"""
for color in c.COLORS:
results.append(
InlineQueryResultArticle(
id=color,
title=_("Choose Color"),
description=display_color(color),
input_message_content=
InputTextMessageContent(display_color_group(color, game))
)
)
def add_other_cards(player, results, game):
"""Add hand cards when choosing colors"""
results.append(
InlineQueryResultArticle(
"hand",
title=_("Card (tap for game state):",
"Cards (tap for game state):",
len(player.cards)),
description=', '.join([repr(card) for card in player.cards]),
input_message_content=game_info(game)
)
)
def player_list(game):
"""Generate list of player strings"""
return [_("{name} ({number} card)",
"{name} ({number} cards)",
len(player.cards))
.format(name=player.user.first_name, number=len(player.cards))
for player in game.players]
def add_no_game(results):
"""Add text result if user is not playing"""
results.append(
InlineQueryResultArticle(
"nogame",
title=_("You are not playing"),
input_message_content=
InputTextMessageContent(_('Not playing right now. Use /new to '
'start a game or /join to join the '
'current game in this group'))
)
)
def add_not_started(results):
"""Add text result if the game has not yet started"""
results.append(
InlineQueryResultArticle(
"nogame",
title=_("The game wasn't started yet"),
input_message_content=
InputTextMessageContent(_('Start the game with /start'))
)
)
def add_mode_classic(results):
"""Change mode to classic"""
results.append(
InlineQueryResultArticle(
"mode_classic",
title=_("🎻 Classic mode"),
input_message_content=
InputTextMessageContent(_('Classic 🎻'))
)
)
def add_mode_fast(results):
"""Change mode to classic"""
results.append(
InlineQueryResultArticle(
"mode_fast",
title=_("🚀 Sanic mode"),
input_message_content=
InputTextMessageContent(_('Gotta go fast! 🚀'))
)
)
def add_mode_wild(results):
"""Change mode to classic"""
results.append(
InlineQueryResultArticle(
"mode_wild",
title=_("🐉 Wild mode"),
input_message_content=
InputTextMessageContent(_('Into the Wild~ 🐉'))
)
)
def add_mode_text(results):
"""Change mode to text"""
results.append(
InlineQueryResultArticle(
"mode_text",
title=_("✍️ Text mode"),
input_message_content=
InputTextMessageContent(_('Text ✍️'))
)
)
def add_draw(player, results):
"""Add option to draw"""
n = player.game.draw_counter or 1
results.append(
Sticker(
"draw", sticker_file_id=c.STICKERS['option_draw'],
input_message_content=
InputTextMessageContent(__('Drawing {number} card',
'Drawing {number} cards', n,
multi=player.game.translate)
.format(number=n))
)
)
def add_gameinfo(game, results):
"""Add option to show game info"""
results.append(
Sticker(
"gameinfo",
sticker_file_id=c.STICKERS['option_info'],
input_message_content=game_info(game)
)
)
def add_pass(results, game):
"""Add option to pass"""
results.append(
Sticker(
"pass", sticker_file_id=c.STICKERS['option_pass'],
input_message_content=InputTextMessageContent(
__('Pass', multi=game.translate)
)
)
)
def add_call_bluff(results, game):
"""Add option to call a bluff"""
results.append(
Sticker(
"call_bluff",
sticker_file_id=c.STICKERS['option_bluff'],
input_message_content=
InputTextMessageContent(__("I'm calling your bluff!",
multi=game.translate))
)
)
def add_card(game, card, results, can_play):
"""Add an option that represents a card"""
if can_play:
if game.mode != "text":
results.append(
Sticker(str(card), sticker_file_id=c.STICKERS[str(card)])
)
if game.mode == "text":
results.append(
Sticker(str(card), sticker_file_id=c.STICKERS[str(card)], input_message_content=InputTextMessageContent("Card Played: {card}".format(card=repr(card).replace('Draw Four', '+4').replace('Draw', '+2').replace('Colorchooser', 'Color Chooser')))
))
else:
results.append(
Sticker(str(uuid4()), sticker_file_id=c.STICKERS_GREY[str(card)],
input_message_content=game_info(game))
)
def game_info(game):
players = player_list(game)
return InputTextMessageContent(
_("Current player: {name}")
.format(name=display_name(game.current_player.user)) +
"\n" +
_("Last card: {card}").format(card=repr(game.last_card)) +
"\n" +
_("Player: {player_list}",
"Players: {player_list}",
len(players))
.format(player_list=" -> ".join(players))
)