change content from en_US to zh_TW
This commit is contained in:
142
bot.py
142
bot.py
@ -59,8 +59,7 @@ def notify_me(bot, update):
|
|||||||
if update.message.chat.type == 'private':
|
if update.message.chat.type == 'private':
|
||||||
send_async(bot,
|
send_async(bot,
|
||||||
chat_id,
|
chat_id,
|
||||||
text=_("Send this command in a group to be notified "
|
text=_("在群組中傳送這個指令以讓我在這個群組開始遊戲時私訊你"))
|
||||||
"when a new game is started there."))
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
gm.remind_dict[chat_id].add(update.message.from_user.id)
|
gm.remind_dict[chat_id].add(update.message.from_user.id)
|
||||||
@ -82,7 +81,7 @@ def new_game(bot, update):
|
|||||||
for user in gm.remind_dict[update.message.chat_id]:
|
for user in gm.remind_dict[update.message.chat_id]:
|
||||||
send_async(bot,
|
send_async(bot,
|
||||||
user,
|
user,
|
||||||
text=_("A new game has been started in {title}").format(
|
text=_("新遊戲已經在 {title} 中開始!").format(
|
||||||
title=update.message.chat.title))
|
title=update.message.chat.title))
|
||||||
|
|
||||||
del gm.remind_dict[update.message.chat_id]
|
del gm.remind_dict[update.message.chat_id]
|
||||||
@ -90,8 +89,7 @@ def new_game(bot, update):
|
|||||||
game = gm.new_game(update.message.chat)
|
game = gm.new_game(update.message.chat)
|
||||||
game.owner = update.message.from_user
|
game.owner = update.message.from_user
|
||||||
send_async(bot, chat_id,
|
send_async(bot, chat_id,
|
||||||
text=_("Created a new game! Join the game with /join "
|
text=_("已經開始新的遊戲! 用 /join 加入並用 /start 開始遊戲"))
|
||||||
"and start the game with /start"))
|
|
||||||
|
|
||||||
if botan:
|
if botan:
|
||||||
botan.track(update.message, 'New games')
|
botan.track(update.message, 'New games')
|
||||||
@ -110,29 +108,26 @@ def join_game(bot, update):
|
|||||||
gm.join_game(update.message.from_user, chat)
|
gm.join_game(update.message.from_user, chat)
|
||||||
|
|
||||||
except LobbyClosedError:
|
except LobbyClosedError:
|
||||||
send_async(bot, chat.id, text=_("The lobby is closed"))
|
send_async(bot, chat.id, text=_("這場遊戲不開放其他人加入"))
|
||||||
|
|
||||||
except NoGameInChatError:
|
except NoGameInChatError:
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=_("No game is running at the moment. "
|
text=_("目前沒有進行中的遊戲,輸入 /new 開始新的遊戲"),
|
||||||
"Create a new game with /new"),
|
|
||||||
reply_to_message_id=update.message.message_id)
|
reply_to_message_id=update.message.message_id)
|
||||||
|
|
||||||
except AlreadyJoinedError:
|
except AlreadyJoinedError:
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=_("You already joined the game. Start the game "
|
text=_("您已加入本局遊戲,輸入 /start 來開始遊戲"),
|
||||||
"with /start"),
|
|
||||||
reply_to_message_id=update.message.message_id)
|
reply_to_message_id=update.message.message_id)
|
||||||
|
|
||||||
except DeckEmptyError:
|
except DeckEmptyError:
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=_("There are not enough cards left in the deck for "
|
text=_("已經沒牌讓新玩家加入了"),
|
||||||
"new players to join."),
|
|
||||||
reply_to_message_id=update.message.message_id)
|
reply_to_message_id=update.message.message_id)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=_("Joined the game"),
|
text=_("已加入遊戲"),
|
||||||
reply_to_message_id=update.message.message_id)
|
reply_to_message_id=update.message.message_id)
|
||||||
|
|
||||||
|
|
||||||
@ -145,8 +140,7 @@ def leave_game(bot, update):
|
|||||||
player = gm.player_for_user_in_chat(user, chat)
|
player = gm.player_for_user_in_chat(user, chat)
|
||||||
|
|
||||||
if player is None:
|
if player is None:
|
||||||
send_async(bot, chat.id, text=_("You are not playing in a game in "
|
send_async(bot, chat.id, text=_("你目前沒有在此聊天室中遊玩"),
|
||||||
"this group."),
|
|
||||||
reply_to_message_id=update.message.message_id)
|
reply_to_message_id=update.message.message_id)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -157,17 +151,16 @@ def leave_game(bot, update):
|
|||||||
gm.leave_game(user, chat)
|
gm.leave_game(user, chat)
|
||||||
|
|
||||||
except NoGameInChatError:
|
except NoGameInChatError:
|
||||||
send_async(bot, chat.id, text=_("You are not playing in a game in "
|
send_async(bot, chat.id, text=_("你目前沒有在此聊天室中遊玩"),
|
||||||
"this group."),
|
|
||||||
reply_to_message_id=update.message.message_id)
|
reply_to_message_id=update.message.message_id)
|
||||||
|
|
||||||
except NotEnoughPlayersError:
|
except NotEnoughPlayersError:
|
||||||
gm.end_game(chat, user)
|
gm.end_game(chat, user)
|
||||||
send_async(bot, chat.id, text=__("Game ended!", multi=game.translate))
|
send_async(bot, chat.id, text=__("遊戲結束!", multi=game.translate))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=__("Okay. Next Player: {name}",
|
text=__("輪到:{name}",
|
||||||
multi=game.translate).format(
|
multi=game.translate).format(
|
||||||
name=display_name(game.current_player.user)),
|
name=display_name(game.current_player.user)),
|
||||||
reply_to_message_id=update.message.message_id)
|
reply_to_message_id=update.message.message_id)
|
||||||
@ -186,23 +179,22 @@ def select_game(bot, update):
|
|||||||
else:
|
else:
|
||||||
send_async(bot,
|
send_async(bot,
|
||||||
update.callback_query.message.chat_id,
|
update.callback_query.message.chat_id,
|
||||||
text=_("Game not found."))
|
text=_("找不到這場遊戲"))
|
||||||
return
|
return
|
||||||
|
|
||||||
@run_async
|
@run_async
|
||||||
def selected(bot):
|
def selected(bot):
|
||||||
back = [[InlineKeyboardButton(text=_("Back to last group"),
|
back = [[InlineKeyboardButton(text=_("回到上一個群組"),
|
||||||
switch_inline_query='')]]
|
switch_inline_query='')]]
|
||||||
bot.answerCallbackQuery(update.callback_query.id,
|
bot.answerCallbackQuery(update.callback_query.id,
|
||||||
text=_("Please switch to the group you selected!"),
|
text=_("請切換到你選擇的群組"),
|
||||||
show_alert=False,
|
show_alert=False,
|
||||||
timeout=TIMEOUT)
|
timeout=TIMEOUT)
|
||||||
|
|
||||||
bot.editMessageText(chat_id=update.callback_query.message.chat_id,
|
bot.editMessageText(chat_id=update.callback_query.message.chat_id,
|
||||||
message_id=update.callback_query.message.message_id,
|
message_id=update.callback_query.message.message_id,
|
||||||
text=_("Selected group: {group}\n"
|
text=_("已選擇的群組: {group}\n"
|
||||||
"<b>Make sure that you switch to the correct "
|
"<b>請確認你已經切換到目前遊玩中的群組!</b>").format(
|
||||||
"group!</b>").format(
|
|
||||||
group=gm.userid_current[user_id].game.chat.title),
|
group=gm.userid_current[user_id].game.chat.title),
|
||||||
reply_markup=InlineKeyboardMarkup(back),
|
reply_markup=InlineKeyboardMarkup(back),
|
||||||
parse_mode=ParseMode.HTML,
|
parse_mode=ParseMode.HTML,
|
||||||
@ -227,10 +219,10 @@ def status_update(bot, update):
|
|||||||
pass
|
pass
|
||||||
except NotEnoughPlayersError:
|
except NotEnoughPlayersError:
|
||||||
gm.end_game(chat, user)
|
gm.end_game(chat, user)
|
||||||
send_async(bot, chat.id, text=__("Game ended!",
|
send_async(bot, chat.id, text=__("遊戲結束!",
|
||||||
multi=game.translate))
|
multi=game.translate))
|
||||||
else:
|
else:
|
||||||
send_async(bot, chat.id, text=__("Removing {name} from the game",
|
send_async(bot, chat.id, text=__("將 {name} 從遊戲中踢除",
|
||||||
multi=game.translate)
|
multi=game.translate)
|
||||||
.format(name=display_name(user)))
|
.format(name=display_name(user)))
|
||||||
|
|
||||||
@ -247,26 +239,23 @@ def start_game(bot, update, args):
|
|||||||
game = gm.chatid_games[chat.id][-1]
|
game = gm.chatid_games[chat.id][-1]
|
||||||
except (KeyError, IndexError):
|
except (KeyError, IndexError):
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=_("There is no game running in this chat. Create "
|
text=_("此聊天室目前沒有遊戲進行中,使用 /new 開始新遊戲"))
|
||||||
"a new one with /new"))
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if game.started:
|
if game.started:
|
||||||
send_async(bot, chat.id, text=_("The game has already started"))
|
send_async(bot, chat.id, text=_("遊戲已經開始了!"))
|
||||||
|
|
||||||
elif len(game.players) < 2:
|
elif len(game.players) < 2:
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=_("At least two players must /join the game "
|
text=_("至少要有兩個人 /join 才能開始遊戲"))
|
||||||
"before you can start it"))
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
game.play_card(game.last_card)
|
game.play_card(game.last_card)
|
||||||
game.started = True
|
game.started = True
|
||||||
|
|
||||||
first_message = (
|
first_message = (
|
||||||
__("First player: {name}\n"
|
__("由 {name} 開始出牌\n"
|
||||||
"Use /close to stop people from joining the game.\n"
|
"輸入 /close 以防止新玩家加入此局遊戲",
|
||||||
"Enable multi-translations with /enable_translations",
|
|
||||||
multi=game.translate)
|
multi=game.translate)
|
||||||
.format(name=display_name(game.current_player.user)))
|
.format(name=display_name(game.current_player.user)))
|
||||||
|
|
||||||
@ -300,7 +289,7 @@ def start_game(bot, update, args):
|
|||||||
)
|
)
|
||||||
|
|
||||||
send_async(bot, update.message.chat_id,
|
send_async(bot, update.message.chat_id,
|
||||||
text=_('Please select the group you want to play in.'),
|
text=_("請選擇你要玩的群組"),
|
||||||
reply_markup=InlineKeyboardMarkup(groups))
|
reply_markup=InlineKeyboardMarkup(groups))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@ -316,20 +305,19 @@ def close_game(bot, update):
|
|||||||
|
|
||||||
if not games:
|
if not games:
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=_("There is no running game in this chat."))
|
text=_("此聊天室沒有正在進行的遊戲"))
|
||||||
return
|
return
|
||||||
|
|
||||||
game = games[-1]
|
game = games[-1]
|
||||||
|
|
||||||
if game.owner.id == user.id:
|
if game.owner.id == user.id:
|
||||||
game.open = False
|
game.open = False
|
||||||
send_async(bot, chat.id, text=_("Closed the lobby. "
|
send_async(bot, chat.id, text=_("已禁止其他人加入這場遊戲"))
|
||||||
"No more players can join this game."))
|
|
||||||
return
|
return
|
||||||
|
|
||||||
else:
|
else:
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=_("Only the game creator ({name}) can do that.")
|
text=_("只有創建遊戲的玩家({name})可以執行此指令")
|
||||||
.format(name=game.owner.first_name),
|
.format(name=game.owner.first_name),
|
||||||
reply_to_message_id=update.message.message_id)
|
reply_to_message_id=update.message.message_id)
|
||||||
return
|
return
|
||||||
@ -344,19 +332,18 @@ def open_game(bot, update):
|
|||||||
|
|
||||||
if not games:
|
if not games:
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=_("There is no running game in this chat."))
|
text=_("此聊天室目前沒有遊戲進行中"))
|
||||||
return
|
return
|
||||||
|
|
||||||
game = games[-1]
|
game = games[-1]
|
||||||
|
|
||||||
if game.owner.id == user.id:
|
if game.owner.id == user.id:
|
||||||
game.open = True
|
game.open = True
|
||||||
send_async(bot, chat.id, text=_("Opened the lobby. "
|
send_async(bot, chat.id, text=_("已開放其他人加入,現在可以 /join 本局遊戲"))
|
||||||
"New players may /join the game."))
|
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=_("Only the game creator ({name}) can do that")
|
text=_("只有創建遊戲的玩家({name})可以執行此指令")
|
||||||
.format(name=game.owner.first_name),
|
.format(name=game.owner.first_name),
|
||||||
reply_to_message_id=update.message.message_id)
|
reply_to_message_id=update.message.message_id)
|
||||||
return
|
return
|
||||||
@ -371,20 +358,20 @@ def enable_translations(bot, update):
|
|||||||
|
|
||||||
if not games:
|
if not games:
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=_("There is no running game in this chat."))
|
text=_("此聊天室目前沒有遊戲進行中"))
|
||||||
return
|
return
|
||||||
|
|
||||||
game = games[-1]
|
game = games[-1]
|
||||||
|
|
||||||
if game.owner.id == user.id:
|
if game.owner.id == user.id:
|
||||||
game.translate = True
|
game.translate = True
|
||||||
send_async(bot, chat.id, text=_("Enabled multi-translations. "
|
send_async(bot, chat.id, text=_("開啟翻譯(待移除)"
|
||||||
"Disable with /disable_translations"))
|
"Disable with /disable_translations"))
|
||||||
return
|
return
|
||||||
|
|
||||||
else:
|
else:
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=_("Only the game creator ({name}) can do that")
|
text=_("只有創建遊戲的玩家({name})可以執行此指令")
|
||||||
.format(name=game.owner.first_name),
|
.format(name=game.owner.first_name),
|
||||||
reply_to_message_id=update.message.message_id)
|
reply_to_message_id=update.message.message_id)
|
||||||
return
|
return
|
||||||
@ -399,21 +386,20 @@ def disable_translations(bot, update):
|
|||||||
|
|
||||||
if not games:
|
if not games:
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=_("There is no running game in this chat."))
|
text=_("此聊天室目前沒有遊戲進行中"))
|
||||||
return
|
return
|
||||||
|
|
||||||
game = games[-1]
|
game = games[-1]
|
||||||
|
|
||||||
if game.owner.id == user.id:
|
if game.owner.id == user.id:
|
||||||
game.translate = False
|
game.translate = False
|
||||||
send_async(bot, chat.id, text=_("Disabled multi-translations. "
|
send_async(bot, chat.id, text=_("關閉翻譯(待移除)"
|
||||||
"Enable them again with "
|
|
||||||
"/enable_translations"))
|
"/enable_translations"))
|
||||||
return
|
return
|
||||||
|
|
||||||
else:
|
else:
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=_("Only the game creator ({name}) can do that")
|
text=_("只有創建遊戲的玩家({name})可以執行此指令")
|
||||||
.format(name=game.owner.first_name),
|
.format(name=game.owner.first_name),
|
||||||
reply_to_message_id=update.message.message_id)
|
reply_to_message_id=update.message.message_id)
|
||||||
return
|
return
|
||||||
@ -429,7 +415,7 @@ def skip_player(bot, update):
|
|||||||
player = gm.player_for_user_in_chat(user, chat)
|
player = gm.player_for_user_in_chat(user, chat)
|
||||||
if not player:
|
if not player:
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=_("You are not playing in a game in this chat."))
|
text=_("你目前沒有在此聊天室中遊玩"))
|
||||||
return
|
return
|
||||||
|
|
||||||
game = player.game
|
game = player.game
|
||||||
@ -443,8 +429,8 @@ def skip_player(bot, update):
|
|||||||
if delta < skipped_player.waiting_time:
|
if delta < skipped_player.waiting_time:
|
||||||
n = skipped_player.waiting_time - delta
|
n = skipped_player.waiting_time - delta
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=_("Please wait {time} second",
|
text=_("請等待 {time} 秒",
|
||||||
"Please wait {time} seconds",
|
"請等待 {time} 秒",
|
||||||
n)
|
n)
|
||||||
.format(time=n),
|
.format(time=n),
|
||||||
reply_to_message_id=update.message.message_id)
|
reply_to_message_id=update.message.message_id)
|
||||||
@ -459,12 +445,10 @@ def skip_player(bot, update):
|
|||||||
|
|
||||||
n = skipped_player.waiting_time
|
n = skipped_player.waiting_time
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=__("Waiting time to skip this player has "
|
text=__("此玩家等待時間已經縮短為 {time} 秒\n"
|
||||||
"been reduced to {time} second.\n"
|
"輪到:{name}",
|
||||||
"Next player: {name}",
|
"此玩家等待時間已經縮短為 {time} 秒\n"
|
||||||
"Waiting time to skip this player has "
|
"輪到:{name}",
|
||||||
"been reduced to {time} seconds.\n"
|
|
||||||
"Next player: {name}",
|
|
||||||
n,
|
n,
|
||||||
multi=game.translate)
|
multi=game.translate)
|
||||||
.format(time=n,
|
.format(time=n,
|
||||||
@ -475,17 +459,15 @@ def skip_player(bot, update):
|
|||||||
try:
|
try:
|
||||||
gm.leave_game(skipped_player.user, chat)
|
gm.leave_game(skipped_player.user, chat)
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=__("{name1} was skipped four times in a row "
|
text=__("{name1} 被跳過 4 次,已從此局遊戲中移除\n"
|
||||||
"and has been removed from the game.\n"
|
"輪到:{name2}", multi=game.translate)
|
||||||
"Next player: {name2}", multi=game.translate)
|
|
||||||
.format(name1=display_name(skipped_player.user),
|
.format(name1=display_name(skipped_player.user),
|
||||||
name2=display_name(next_player.user)))
|
name2=display_name(next_player.user)))
|
||||||
|
|
||||||
except NotEnoughPlayersError:
|
except NotEnoughPlayersError:
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=__("{name} was skipped four times in a row "
|
text=__("{name} 被跳過 4 次,已從此局遊戲中移除\n"
|
||||||
"and has been removed from the game.\n"
|
"遊戲結束!", multi=game.translate)
|
||||||
"The game ended.", multi=game.translate)
|
|
||||||
.format(name=display_name(skipped_player.user)))
|
.format(name=display_name(skipped_player.user)))
|
||||||
|
|
||||||
gm.end_game(chat.id, skipped_player.user)
|
gm.end_game(chat.id, skipped_player.user)
|
||||||
@ -548,7 +530,7 @@ def reply_to_query(bot, update):
|
|||||||
result.id += ':%d' % player.anti_cheat
|
result.id += ':%d' % player.anti_cheat
|
||||||
|
|
||||||
if players and game and len(players) > 1:
|
if players and game and len(players) > 1:
|
||||||
switch = _('Current game: {game}').format(game=game.chat.title)
|
switch = _('目前遊戲:{group}').format(game=game.chat.title)
|
||||||
|
|
||||||
answer_async(bot, update.inline_query.id, results, cache_time=0,
|
answer_async(bot, update.inline_query.id, results, cache_time=0,
|
||||||
switch_pm_text=switch, switch_pm_parameter='select')
|
switch_pm_text=switch, switch_pm_parameter='select')
|
||||||
@ -582,7 +564,7 @@ def process_result(bot, update):
|
|||||||
return
|
return
|
||||||
elif int(anti_cheat) != last_anti_cheat:
|
elif int(anti_cheat) != last_anti_cheat:
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=__("Cheat attempt by {name}", multi=game.translate)
|
text=__("{name} 提出了作弊嫌疑", multi=game.translate)
|
||||||
.format(name=display_name(player.user)))
|
.format(name=display_name(player.user)))
|
||||||
return
|
return
|
||||||
elif result_id == 'call_bluff':
|
elif result_id == 'call_bluff':
|
||||||
@ -601,7 +583,7 @@ def process_result(bot, update):
|
|||||||
|
|
||||||
if game in gm.chatid_games.get(chat.id, list()):
|
if game in gm.chatid_games.get(chat.id, list()):
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=__("Next player: {name}", multi=game.translate)
|
text=__("輪到:{name}", multi=game.translate)
|
||||||
.format(name=display_name(game.current_player.user)))
|
.format(name=display_name(game.current_player.user)))
|
||||||
|
|
||||||
|
|
||||||
@ -612,8 +594,7 @@ def reset_waiting_time(bot, player):
|
|||||||
if player.waiting_time < 90:
|
if player.waiting_time < 90:
|
||||||
player.waiting_time = 90
|
player.waiting_time = 90
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=__("Waiting time for {name} has been reset to 90 "
|
text=__("{name} 的等待時間已重置為 90 秒", multi=player.game.translate)
|
||||||
"seconds", multi=player.game.translate)
|
|
||||||
.format(name=display_name(player.user)))
|
.format(name=display_name(player.user)))
|
||||||
|
|
||||||
|
|
||||||
@ -633,14 +614,14 @@ def do_play_card(bot, player, result_id):
|
|||||||
us.cards_played += 1
|
us.cards_played += 1
|
||||||
|
|
||||||
if game.choosing_color:
|
if game.choosing_color:
|
||||||
send_async(bot, chat.id, text=_("Please choose a color"))
|
send_async(bot, chat.id, text=_("請選擇一個顏色"))
|
||||||
|
|
||||||
if len(player.cards) == 1:
|
if len(player.cards) == 1:
|
||||||
send_async(bot, chat.id, text="UNO!")
|
send_async(bot, chat.id, text="UNO!")
|
||||||
|
|
||||||
if len(player.cards) == 0:
|
if len(player.cards) == 0:
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=__("{name} won!", multi=game.translate)
|
text=__("{name} 贏了!", multi=game.translate)
|
||||||
.format(name=user.first_name))
|
.format(name=user.first_name))
|
||||||
|
|
||||||
if us.stats:
|
if us.stats:
|
||||||
@ -655,7 +636,7 @@ def do_play_card(bot, player, result_id):
|
|||||||
gm.leave_game(user, chat)
|
gm.leave_game(user, chat)
|
||||||
except NotEnoughPlayersError:
|
except NotEnoughPlayersError:
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=__("Game ended!", multi=game.translate))
|
text=__("遊戲結束!", multi=game.translate))
|
||||||
|
|
||||||
us2 = UserSetting.get(id=game.current_player.user.id)
|
us2 = UserSetting.get(id=game.current_player.user.id)
|
||||||
if us2 and us2.stats:
|
if us2 and us2.stats:
|
||||||
@ -678,8 +659,7 @@ def do_draw(bot, player):
|
|||||||
player.draw()
|
player.draw()
|
||||||
except DeckEmptyError:
|
except DeckEmptyError:
|
||||||
send_async(bot, player.game.chat.id,
|
send_async(bot, player.game.chat.id,
|
||||||
text=__("There are no more cards in the deck.",
|
text=__("已經沒牌了", multi=game.translate))
|
||||||
multi=game.translate))
|
|
||||||
|
|
||||||
if (game.last_card.value == c.DRAW_TWO or
|
if (game.last_card.value == c.DRAW_TWO or
|
||||||
game.last_card.special == c.DRAW_FOUR) and \
|
game.last_card.special == c.DRAW_FOUR) and \
|
||||||
@ -694,7 +674,7 @@ def do_call_bluff(bot, player):
|
|||||||
|
|
||||||
if player.prev.bluffing:
|
if player.prev.bluffing:
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=__("Bluff called! Giving 4 cards to {name}",
|
text=__("作弊已確認!作為懲罰,給予 {name} 4 張牌",
|
||||||
multi=game.translate)
|
multi=game.translate)
|
||||||
.format(name=player.prev.user.first_name))
|
.format(name=player.prev.user.first_name))
|
||||||
|
|
||||||
@ -702,13 +682,12 @@ def do_call_bluff(bot, player):
|
|||||||
player.prev.draw()
|
player.prev.draw()
|
||||||
except DeckEmptyError:
|
except DeckEmptyError:
|
||||||
send_async(bot, player.game.chat.id,
|
send_async(bot, player.game.chat.id,
|
||||||
text=__("There are no more cards in the deck.",
|
text=__("已經沒牌了", multi=game.translate))
|
||||||
multi=game.translate))
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
game.draw_counter += 2
|
game.draw_counter += 2
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=__("{name1} didn't bluff! Giving 6 cards to {name2}",
|
text=__("{name1} 沒有作弊!作為懲罰,給予 {name2} 六張牌",
|
||||||
multi=game.translate)
|
multi=game.translate)
|
||||||
.format(name1=player.prev.user.first_name,
|
.format(name1=player.prev.user.first_name,
|
||||||
name2=player.user.first_name))
|
name2=player.user.first_name))
|
||||||
@ -716,8 +695,7 @@ def do_call_bluff(bot, player):
|
|||||||
player.draw()
|
player.draw()
|
||||||
except DeckEmptyError:
|
except DeckEmptyError:
|
||||||
send_async(bot, player.game.chat.id,
|
send_async(bot, player.game.chat.id,
|
||||||
text=__("There are no more cards in the deck.",
|
text=__("已經沒牌了", multi=game.translate))
|
||||||
multi=game.translate))
|
|
||||||
|
|
||||||
game.turn()
|
game.turn()
|
||||||
|
|
||||||
|
36
results.py
36
results.py
@ -36,7 +36,7 @@ def add_choose_color(results, game):
|
|||||||
results.append(
|
results.append(
|
||||||
InlineQueryResultArticle(
|
InlineQueryResultArticle(
|
||||||
id=color,
|
id=color,
|
||||||
title=_("Choose Color"),
|
title=_("選擇顏色"),
|
||||||
description=display_color(color),
|
description=display_color(color),
|
||||||
input_message_content=
|
input_message_content=
|
||||||
InputTextMessageContent(display_color_group(color, game))
|
InputTextMessageContent(display_color_group(color, game))
|
||||||
@ -50,8 +50,8 @@ def add_other_cards(player, results, game):
|
|||||||
results.append(
|
results.append(
|
||||||
InlineQueryResultArticle(
|
InlineQueryResultArticle(
|
||||||
"hand",
|
"hand",
|
||||||
title=_("Card (tap for game state):",
|
title=_("你的手牌(點一下以獲得遊戲狀態):",
|
||||||
"Cards (tap for game state):",
|
"你的手牌(點一下以獲得遊戲狀態):",
|
||||||
len(player.cards)),
|
len(player.cards)),
|
||||||
description=', '.join([repr(card) for card in player.cards]),
|
description=', '.join([repr(card) for card in player.cards]),
|
||||||
input_message_content=game_info(game)
|
input_message_content=game_info(game)
|
||||||
@ -61,8 +61,8 @@ def add_other_cards(player, results, game):
|
|||||||
|
|
||||||
def player_list(game):
|
def player_list(game):
|
||||||
"""Generate list of player strings"""
|
"""Generate list of player strings"""
|
||||||
return [_("{name} ({number} card)",
|
return [_("{name}(有 {number} 張牌)",
|
||||||
"{name} ({number} cards)",
|
"{name}(有 {number} 張牌)",
|
||||||
len(player.cards))
|
len(player.cards))
|
||||||
.format(name=player.user.first_name, number=len(player.cards))
|
.format(name=player.user.first_name, number=len(player.cards))
|
||||||
for player in game.players]
|
for player in game.players]
|
||||||
@ -73,11 +73,9 @@ def add_no_game(results):
|
|||||||
results.append(
|
results.append(
|
||||||
InlineQueryResultArticle(
|
InlineQueryResultArticle(
|
||||||
"nogame",
|
"nogame",
|
||||||
title=_("You are not playing"),
|
title=_("你沒有在遊戲中"),
|
||||||
input_message_content=
|
input_message_content=
|
||||||
InputTextMessageContent(_('Not playing right now. Use /new to '
|
InputTextMessageContent(_('你目前沒有在遊玩,使用 /new@unobot 開始新的遊戲或使用 /join@unobot 加入目前的遊戲'))
|
||||||
'start a game or /join to join the '
|
|
||||||
'current game in this group'))
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -87,9 +85,9 @@ def add_not_started(results):
|
|||||||
results.append(
|
results.append(
|
||||||
InlineQueryResultArticle(
|
InlineQueryResultArticle(
|
||||||
"nogame",
|
"nogame",
|
||||||
title=_("The game wasn't started yet"),
|
title=_("遊戲尚未開始"),
|
||||||
input_message_content=
|
input_message_content=
|
||||||
InputTextMessageContent(_('Start the game with /start'))
|
InputTextMessageContent(_('使用 /start 開始遊戲'))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -102,8 +100,8 @@ def add_draw(player, results):
|
|||||||
Sticker(
|
Sticker(
|
||||||
"draw", sticker_file_id=c.STICKERS['option_draw'],
|
"draw", sticker_file_id=c.STICKERS['option_draw'],
|
||||||
input_message_content=
|
input_message_content=
|
||||||
InputTextMessageContent(__('Drawing {number} card',
|
InputTextMessageContent(__('抽 {number} 張牌',
|
||||||
'Drawing {number} cards', n,
|
'抽 {number} 張牌', n,
|
||||||
multi=player.game.translate)
|
multi=player.game.translate)
|
||||||
.format(number=n))
|
.format(number=n))
|
||||||
)
|
)
|
||||||
@ -128,7 +126,7 @@ def add_pass(results, game):
|
|||||||
Sticker(
|
Sticker(
|
||||||
"pass", sticker_file_id=c.STICKERS['option_pass'],
|
"pass", sticker_file_id=c.STICKERS['option_pass'],
|
||||||
input_message_content=InputTextMessageContent(
|
input_message_content=InputTextMessageContent(
|
||||||
__('Pass', multi=game.translate)
|
__('Pass!下一位', multi=game.translate)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -141,7 +139,7 @@ def add_call_bluff(results, game):
|
|||||||
"call_bluff",
|
"call_bluff",
|
||||||
sticker_file_id=c.STICKERS['option_bluff'],
|
sticker_file_id=c.STICKERS['option_bluff'],
|
||||||
input_message_content=
|
input_message_content=
|
||||||
InputTextMessageContent(__("I'm calling your bluff!",
|
InputTextMessageContent(__("你作弊,一定還有其他牌可以出!",
|
||||||
multi=game.translate))
|
multi=game.translate))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -164,13 +162,13 @@ def add_card(game, card, results, can_play):
|
|||||||
def game_info(game):
|
def game_info(game):
|
||||||
players = player_list(game)
|
players = player_list(game)
|
||||||
return InputTextMessageContent(
|
return InputTextMessageContent(
|
||||||
_("Current player: {name}")
|
_("目前玩家:{name}")
|
||||||
.format(name=display_name(game.current_player.user)) +
|
.format(name=display_name(game.current_player.user)) +
|
||||||
"\n" +
|
"\n" +
|
||||||
_("Last card: {card}").format(card=repr(game.last_card)) +
|
_("最後的牌:{card}").format(card=repr(game.last_card)) +
|
||||||
"\n" +
|
"\n" +
|
||||||
_("Player: {player_list}",
|
_("玩家列表:{player_list}",
|
||||||
"Players: {player_list}",
|
"玩家列表:{player_list}",
|
||||||
len(players))
|
len(players))
|
||||||
.format(player_list=" -> ".join(players))
|
.format(player_list=" -> ".join(players))
|
||||||
)
|
)
|
19
settings.py
19
settings.py
@ -34,8 +34,7 @@ def show_settings(bot, update):
|
|||||||
|
|
||||||
if update.message.chat.type != 'private':
|
if update.message.chat.type != 'private':
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=_("Please edit your settings in a private chat with "
|
text=_("請私訊我來修改你的設定"))
|
||||||
"the bot."))
|
|
||||||
return
|
return
|
||||||
|
|
||||||
us = UserSetting.get(id=update.message.from_user.id)
|
us = UserSetting.get(id=update.message.from_user.id)
|
||||||
@ -44,12 +43,12 @@ def show_settings(bot, update):
|
|||||||
us = UserSetting(id=update.message.from_user.id)
|
us = UserSetting(id=update.message.from_user.id)
|
||||||
|
|
||||||
if not us.stats:
|
if not us.stats:
|
||||||
stats = Emoji.BAR_CHART + ' ' + _("Enable statistics")
|
stats = Emoji.BAR_CHART + ' ' + _("啟用統計資料")
|
||||||
else:
|
else:
|
||||||
stats = Emoji.CROSS_MARK + ' ' + _("Delete all statistics")
|
stats = Emoji.CROSS_MARK + ' ' + _("刪除所有統計資料")
|
||||||
|
|
||||||
kb = [[stats], [Emoji.EARTH_GLOBE_EUROPE_AFRICA + ' ' + _("Language")]]
|
kb = [[stats], [Emoji.EARTH_GLOBE_EUROPE_AFRICA + ' ' + _("語言")]]
|
||||||
send_async(bot, chat.id, text=Emoji.WRENCH + ' ' + _("Settings"),
|
send_async(bot, chat.id, text=Emoji.WRENCH + ' ' + _("設定"),
|
||||||
reply_markup=ReplyKeyboardMarkup(keyboard=kb,
|
reply_markup=ReplyKeyboardMarkup(keyboard=kb,
|
||||||
one_time_keyboard=True))
|
one_time_keyboard=True))
|
||||||
|
|
||||||
@ -63,13 +62,13 @@ def kb_select(bot, update, groups):
|
|||||||
if option == Emoji.BAR_CHART:
|
if option == Emoji.BAR_CHART:
|
||||||
us = UserSetting.get(id=user.id)
|
us = UserSetting.get(id=user.id)
|
||||||
us.stats = True
|
us.stats = True
|
||||||
send_async(bot, chat.id, text=_("Enabled statistics!"))
|
send_async(bot, chat.id, text=_("已啟用統計資料!"))
|
||||||
|
|
||||||
elif option == Emoji.EARTH_GLOBE_EUROPE_AFRICA:
|
elif option == Emoji.EARTH_GLOBE_EUROPE_AFRICA:
|
||||||
kb = [[locale + ' - ' + descr]
|
kb = [[locale + ' - ' + descr]
|
||||||
for locale, descr
|
for locale, descr
|
||||||
in sorted(available_locales.items())]
|
in sorted(available_locales.items())]
|
||||||
send_async(bot, chat.id, text=_("Select locale"),
|
send_async(bot, chat.id, text=_("選擇語言"),
|
||||||
reply_markup=ReplyKeyboardMarkup(keyboard=kb,
|
reply_markup=ReplyKeyboardMarkup(keyboard=kb,
|
||||||
one_time_keyboard=True))
|
one_time_keyboard=True))
|
||||||
|
|
||||||
@ -79,7 +78,7 @@ def kb_select(bot, update, groups):
|
|||||||
us.first_places = 0
|
us.first_places = 0
|
||||||
us.games_played = 0
|
us.games_played = 0
|
||||||
us.cards_played = 0
|
us.cards_played = 0
|
||||||
send_async(bot, chat.id, text=_("Deleted and disabled statistics!"))
|
send_async(bot, chat.id, text=_("已停用並刪除統計資料!"))
|
||||||
|
|
||||||
|
|
||||||
@user_locale
|
@user_locale
|
||||||
@ -92,7 +91,7 @@ def locale_select(bot, update, groups):
|
|||||||
us = UserSetting.get(id=user.id)
|
us = UserSetting.get(id=user.id)
|
||||||
us.lang = option
|
us.lang = option
|
||||||
_.push(option)
|
_.push(option)
|
||||||
send_async(bot, chat.id, text=_("Set locale!"))
|
send_async(bot, chat.id, text=_("已設定所選擇的語言"))
|
||||||
_.pop()
|
_.pop()
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,42 +25,31 @@ from utils import send_async
|
|||||||
from shared_vars import dispatcher
|
from shared_vars import dispatcher
|
||||||
from internationalization import _, user_locale
|
from internationalization import _, user_locale
|
||||||
|
|
||||||
help_text = ("Follow these steps:\n\n"
|
help_text = ("請跟隨以下指示:\n\n"
|
||||||
"1. Add this bot to a group\n"
|
"1. 將這個機器人新增到群組\n"
|
||||||
"2. In the group, start a new game with /new or join an already"
|
"2. 輸入 /new 開始一個新遊戲或輸入 /join 加入一個運行中的遊戲\n"
|
||||||
" running game with /join\n"
|
"3. 當有兩個或以上的玩家加入, 就可以用 /start 開始遊戲\n"
|
||||||
"3. After at least two players have joined, start the game with"
|
"4. 輸入 <code>@unobot</code> 然後按<b>空白鍵</b> 或點一下"
|
||||||
" /start\n"
|
"<code>via @unobot</code>。之後你會看見你手上的牌或者其他選項例如 DRAW(抽牌),和"
|
||||||
"4. Type <code>@unobot</code> into your chat box and hit "
|
"<b>?</b>看其他玩家狀態。但<b>灰色的牌</b>就是<b>你現在不能使用的牌</b>,選擇其中一個"
|
||||||
"<b>space</b>, or click the <code>via @unobot</code> text "
|
"選項來執行對應的操作。\n"
|
||||||
"next to messages. You will see your cards (some greyed out), "
|
"玩家可以在任何時間加入,如果想離開,請打 /leave 。如果玩家90秒後都沒有出牌"
|
||||||
"any extra options like drawing, and a <b>?</b> to see the "
|
",你可以用 /skip 跳過他。輸入 /notify_me 以讓我在本群組遊戲開始時私訊你\n"
|
||||||
"current game state. The <b>greyed out cards</b> are those you "
|
"\n"
|
||||||
"<b>can not play</b> at the moment. Tap an option to execute "
|
"<b>語言</b>和其他設定: /settings\n"
|
||||||
"the selected action.\n"
|
"遊戲創始人可以用以下的指令:\n"
|
||||||
"Players can join the game at any time. To leave a game, "
|
"/close - 令其他人不可以中途加入\n"
|
||||||
"use /leave. If a player takes more than 90 seconds to play, "
|
"/open - 令其他人可以中途加入\n"
|
||||||
"you can use /skip to skip that player. Use /notify_me to "
|
"<b>試驗功能:</b> 同時在不同的群組中遊玩 請選擇 <code>目前遊戲:...</code>"
|
||||||
"receive a private message when a new game is started.\n\n"
|
"然後選擇你想在哪個群組玩。\n"
|
||||||
"<b>Language</b> and other settings: /settings\n"
|
"如果你喜歡這個 bot,你可以選擇買一副 UNO 牌來支持 UNO!")
|
||||||
"Other commands (only game creator):\n"
|
|
||||||
"/close - Close lobby\n"
|
|
||||||
"/open - Open lobby\n"
|
|
||||||
"/enable_translations - Translate relevant texts into all "
|
|
||||||
"languages spoken in a game\n"
|
|
||||||
"/disable_translations - Use English for those texts\n\n"
|
|
||||||
"<b>Experimental:</b> Play in multiple groups at the same time. "
|
|
||||||
"Press the <code>Current game: ...</code> button and select the "
|
|
||||||
"group you want to play a card in.\n"
|
|
||||||
"If you enjoy this bot, "
|
|
||||||
"<a href=\"https://telegram.me/storebot?start=mau_mau_bot\">"
|
|
||||||
"rate me</a>, join the "
|
|
||||||
"<a href=\"https://telegram.me/unobotupdates\">update channel</a>"
|
|
||||||
" and buy an UNO card game.")
|
|
||||||
|
|
||||||
source_text = ("This bot is Free Software and licensed under the AGPL. "
|
source_text = ("這個 bot 是一個免費的軟體,根據 AGPL 授權 \n"
|
||||||
"The code is available here: \n"
|
"原始碼可以在這裡找到:\n"
|
||||||
"https://github.com/jh0ker/mau_mau_bot")
|
"https://github.com/PinLin/mau_mau_bot\n"
|
||||||
|
"I fork from:\n"
|
||||||
|
"https://github.com/jh0ker/mau_mau_bot\n"
|
||||||
|
"Thanks very much!")
|
||||||
attributions = ("Attributions:\n"
|
attributions = ("Attributions:\n"
|
||||||
'Draw icon by '
|
'Draw icon by '
|
||||||
'<a href="http://www.faithtoken.com/">Faithtoken</a>\n'
|
'<a href="http://www.faithtoken.com/">Faithtoken</a>\n'
|
||||||
@ -99,29 +88,29 @@ def stats(bot, update):
|
|||||||
us = UserSetting.get(id=user.id)
|
us = UserSetting.get(id=user.id)
|
||||||
if not us or not us.stats:
|
if not us or not us.stats:
|
||||||
send_async(bot, update.message.chat_id,
|
send_async(bot, update.message.chat_id,
|
||||||
text=_("You did not enable statistics. Use /settings in "
|
text=_("您尚未啟用統計資料,請私我 "
|
||||||
"a private chat with the bot to enable them."))
|
"<code>/settings</code> 來啟用他"))
|
||||||
else:
|
else:
|
||||||
stats_text = list()
|
stats_text = list()
|
||||||
|
|
||||||
n = us.games_played
|
n = us.games_played
|
||||||
stats_text.append(
|
stats_text.append(
|
||||||
_("{number} game played",
|
_("已遊玩 {number} 個遊戲",
|
||||||
"{number} games played",
|
"已遊玩 {number} 個遊戲",
|
||||||
n).format(number=n)
|
n).format(number=n)
|
||||||
)
|
)
|
||||||
|
|
||||||
n = us.first_places
|
n = us.first_places
|
||||||
stats_text.append(
|
stats_text.append(
|
||||||
_("{number} first place",
|
_("拿了 {number} 次第一名",
|
||||||
"{number} first places",
|
"拿了 {number} 次第一名",
|
||||||
n).format(number=n)
|
n).format(number=n)
|
||||||
)
|
)
|
||||||
|
|
||||||
n = us.cards_played
|
n = us.cards_played
|
||||||
stats_text.append(
|
stats_text.append(
|
||||||
_("{number} card played",
|
_("已遊玩 {number} 張牌",
|
||||||
"{number} cards played",
|
"已遊玩 {number} 張牌",
|
||||||
n).format(number=n)
|
n).format(number=n)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -132,5 +121,5 @@ def stats(bot, update):
|
|||||||
def register():
|
def register():
|
||||||
dispatcher.add_handler(CommandHandler('help', help))
|
dispatcher.add_handler(CommandHandler('help', help))
|
||||||
dispatcher.add_handler(CommandHandler('source', source))
|
dispatcher.add_handler(CommandHandler('source', source))
|
||||||
dispatcher.add_handler(CommandHandler('news', news))
|
# dispatcher.add_handler(CommandHandler('news', news))
|
||||||
dispatcher.add_handler(CommandHandler('stats', stats))
|
dispatcher.add_handler(CommandHandler('stats', stats))
|
||||||
|
16
utils.py
16
utils.py
@ -51,28 +51,28 @@ def display_name(user):
|
|||||||
def display_color(color):
|
def display_color(color):
|
||||||
""" Convert a color code to actual color name """
|
""" Convert a color code to actual color name """
|
||||||
if color == "r":
|
if color == "r":
|
||||||
return _("{emoji} Red").format(emoji=Emoji.HEAVY_BLACK_HEART)
|
return _("{emoji} 紅色").format(emoji=Emoji.HEAVY_BLACK_HEART)
|
||||||
if color == "b":
|
if color == "b":
|
||||||
return _("{emoji} Blue").format(emoji=Emoji.BLUE_HEART)
|
return _("{emoji} 藍色").format(emoji=Emoji.BLUE_HEART)
|
||||||
if color == "g":
|
if color == "g":
|
||||||
return _("{emoji} Green").format(emoji=Emoji.GREEN_HEART)
|
return _("{emoji} 綠色").format(emoji=Emoji.GREEN_HEART)
|
||||||
if color == "y":
|
if color == "y":
|
||||||
return _("{emoji} Yellow").format(emoji=Emoji.YELLOW_HEART)
|
return _("{emoji} 黃色").format(emoji=Emoji.YELLOW_HEART)
|
||||||
|
|
||||||
|
|
||||||
def display_color_group(color, game):
|
def display_color_group(color, game):
|
||||||
""" Convert a color code to actual color name """
|
""" Convert a color code to actual color name """
|
||||||
if color == "r":
|
if color == "r":
|
||||||
return __("{emoji} Red", game.translate).format(
|
return __("{emoji} 紅色", game.translate).format(
|
||||||
emoji=Emoji.HEAVY_BLACK_HEART)
|
emoji=Emoji.HEAVY_BLACK_HEART)
|
||||||
if color == "b":
|
if color == "b":
|
||||||
return __("{emoji} Blue", game.translate).format(
|
return __("{emoji} 藍色", game.translate).format(
|
||||||
emoji=Emoji.BLUE_HEART)
|
emoji=Emoji.BLUE_HEART)
|
||||||
if color == "g":
|
if color == "g":
|
||||||
return __("{emoji} Green", game.translate).format(
|
return __("{emoji} 綠色", game.translate).format(
|
||||||
emoji=Emoji.GREEN_HEART)
|
emoji=Emoji.GREEN_HEART)
|
||||||
if color == "y":
|
if color == "y":
|
||||||
return __("{emoji} Yellow", game.translate).format(
|
return __("{emoji} 黃色", game.translate).format(
|
||||||
emoji=Emoji.YELLOW_HEART)
|
emoji=Emoji.YELLOW_HEART)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user