Compare commits
86 Commits
Author | SHA1 | Date | |
---|---|---|---|
d72991f43e | |||
f2957c0b4f | |||
122cb1dc93 | |||
21553fd289 | |||
66973d4e95 | |||
aa6dbb8f63 | |||
a6bd0bc42b | |||
27b97fe9d7 | |||
ab20bedd5a | |||
e74f7b2854 | |||
ce12df9bd1 | |||
01640d1df9 | |||
284eb91633 | |||
bd307b6195 | |||
82ecec2d45 | |||
e1d559e546 | |||
2abdc46ad1 | |||
3dad1dfebb | |||
192bbf4b27 | |||
c3a35e739e | |||
58555f5f21 | |||
b2ff307964 | |||
35f0e9308e | |||
09319faf94 | |||
eae0a1a1b7 | |||
22b046e961 | |||
9d2524da5a | |||
7d499b21aa | |||
b2f78fdbaa | |||
9c74d408b7 | |||
f1b241d808 | |||
ba81ab614a | |||
b0ca73a3c9 | |||
ede3aba641 | |||
d64d8c00a9 | |||
d78f8dcac6 | |||
a5eefdc1d0 | |||
8fe190133f | |||
b136bdf997 | |||
e28bcc58ad | |||
2a710145f6 | |||
7f15aac773 | |||
2a52f6e36c | |||
ad2ae0a752 | |||
fe98147377 | |||
91947abce0 | |||
8dcd05dbb2 | |||
5c87e74ae2 | |||
beaa46f8e4 | |||
b8e8a7e5de | |||
569850fade | |||
87251eeb2e | |||
0f72532825 | |||
cafa398ec8 | |||
cc88876c69 | |||
d8d31604e3 | |||
e53c45ed2f | |||
857c17b3d4 | |||
fea63f764a | |||
9e98de41c8 | |||
9f88f7ff32 | |||
6877063a2c | |||
fb86f6df05 | |||
5a71cbaae0 | |||
f43cfc2190 | |||
7672e1b47a | |||
7c250c6f79 | |||
bcaea68ef9 | |||
3ba225e7a5 | |||
6901e7f4d0 | |||
c54ffd83e5 | |||
2041e3cb1f | |||
72515e37ed | |||
d5cac440ec | |||
23adfe2cb6 | |||
de177e1137 | |||
962f550f96 | |||
06ae098a5f | |||
4a51c7bfb6 | |||
7fd3c662a5 | |||
ecc0b3adc7 | |||
e7e3fbf4ce | |||
0c3f623cd9 | |||
0e680c6e30 | |||
c7b6649438 | |||
c477701b75 |
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,3 +1,9 @@
|
|||||||
|
# macOS
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
# Pyenv
|
||||||
|
.python-version
|
||||||
|
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
|
@ -7,5 +7,6 @@
|
|||||||
The following wonderful people contributed directly or indirectly to this project:
|
The following wonderful people contributed directly or indirectly to this project:
|
||||||
|
|
||||||
- [imlonghao](https://github.com/imlonghao)
|
- [imlonghao](https://github.com/imlonghao)
|
||||||
|
- [qubitnerd](https://github.com/qubitnerd)
|
||||||
|
|
||||||
Please add yourself here alphabetically when you submit your first pull request.
|
Please add yourself here alphabetically when you submit your first pull request.
|
18
README.md
18
README.md
@ -1,10 +1,20 @@
|
|||||||
# UNO Bot
|
# UNO Bot (zh_TW)
|
||||||
Telegram Bot that allows you to play the popular card game UNO via inline queries. The bot currently runs as [@mau_mau_bot](http://telegram.me/mau_mau_bot)
|
|
||||||
|
[](./LICENSE)
|
||||||
|
|
||||||
|
forked from [jh0ker/mau_mau_bot](https://github.com/jh0ker/mau_mau_bot)
|
||||||
|
|
||||||
|
Telegram Bot that allows you to play the popular card game UNO via inline queries.
|
||||||
|
|
||||||
To run the bot yourself, you will need:
|
To run the bot yourself, you will need:
|
||||||
- Python (tested with 3.4 and 3.5)
|
- Python (tested with 3.4 and 3.5)
|
||||||
- The [python-telegram-bot](https://github.com/python-telegram-bot/python-telegram-bot) module version 4.1.1
|
- The [python-telegram-bot](https://github.com/python-telegram-bot/python-telegram-bot) module version 5.0.0
|
||||||
|
- [Pony ORM](https://ponyorm.com/)
|
||||||
|
|
||||||
Get a bot token from [@BotFather](http://telegram.me/BotFather), place it in `credentials.py` and run the bot with `python3 bot.py`
|
## Setup
|
||||||
|
- Get a bot token from [@BotFather](http://telegram.me/BotFather) and place it in `credentials.py`
|
||||||
|
- Use `/setinline` and `/setinlinefeedback` with BotFather for your bot
|
||||||
|
|
||||||
|
Then run the bot with `python3 bot.py`
|
||||||
|
|
||||||
Code documentation is minimal but there
|
Code documentation is minimal but there
|
||||||
|
16
TRANSLATORS.md
Normal file
16
TRANSLATORS.md
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# Translators
|
||||||
|
|
||||||
|
The following awesome people contributed to this project by translating it:
|
||||||
|
|
||||||
|
| Locale | Translators |
|
||||||
|
|--------|----------------------------------------------------------------------|
|
||||||
|
| de_DE | [Jannes Höke](https://github.com/jh0ker) |
|
||||||
|
| es_ES | [Ricardo Valverde Hernández](https://telegram.me/rivh1), Victor, Yuga|
|
||||||
|
| id_ID | [Erwin Guo](https://www.facebook.com/erwinfransiscus) |
|
||||||
|
| it_IT | Carola Mariano, ɳick |
|
||||||
|
| pt_BR | [João Rodrigo Couto de Oliveira](http://twitter.com/JoaoRodrigoJR) |
|
||||||
|
| zh_CN | [imlonghao](https://github.com/imlonghao) |
|
||||||
|
| zh_HK | [Jed Cheng](https://www.facebook.com/profile.php?id=100002258388821) |
|
||||||
|
| zh_TW | [Eugene Lam](https://www.facebook.com/eugenelam1118) |
|
||||||
|
|
||||||
|
Please add yourself here alphabetically when you submit your first translation.
|
240
bot.py
240
bot.py
@ -37,20 +37,36 @@ from utils import display_name
|
|||||||
import card as c
|
import card as c
|
||||||
from errors import (NoGameInChatError, LobbyClosedError, AlreadyJoinedError,
|
from errors import (NoGameInChatError, LobbyClosedError, AlreadyJoinedError,
|
||||||
NotEnoughPlayersError, DeckEmptyError)
|
NotEnoughPlayersError, DeckEmptyError)
|
||||||
from utils import _, __, send_async, answer_async, user_locale, game_locales, \
|
from utils import send_async, answer_async, error, TIMEOUT
|
||||||
error, TIMEOUT
|
|
||||||
from shared_vars import botan, gm, updater, dispatcher
|
from shared_vars import botan, gm, updater, dispatcher
|
||||||
|
from internationalization import _, __, user_locale, game_locales
|
||||||
|
import simple_commands
|
||||||
|
import settings
|
||||||
|
|
||||||
import simple_commands, settings
|
|
||||||
from simple_commands import help
|
from simple_commands import help
|
||||||
|
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||||
level=logging.DEBUG)
|
level=logging.INFO)
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@user_locale
|
||||||
|
def notify_me(bot, update):
|
||||||
|
"""Handler for /notify_me command, pm people for next game"""
|
||||||
|
chat_id = update.message.chat_id
|
||||||
|
if update.message.chat.type == 'private':
|
||||||
|
send_async(bot,
|
||||||
|
chat_id,
|
||||||
|
text=_("在群組中傳送這個指令以讓我在這個群組開始遊戲時私訊你"))
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
gm.remind_dict[chat_id].add(update.message.from_user.id)
|
||||||
|
except KeyError:
|
||||||
|
gm.remind_dict[chat_id] = {update.message.from_user.id}
|
||||||
|
|
||||||
|
|
||||||
@user_locale
|
@user_locale
|
||||||
def new_game(bot, update):
|
def new_game(bot, update):
|
||||||
"""Handler for the /new command"""
|
"""Handler for the /new command"""
|
||||||
@ -60,11 +76,20 @@ def new_game(bot, update):
|
|||||||
help(bot, update)
|
help(bot, update)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
|
if update.message.chat_id in gm.remind_dict:
|
||||||
|
for user in gm.remind_dict[update.message.chat_id]:
|
||||||
|
send_async(bot,
|
||||||
|
user,
|
||||||
|
text=_("新遊戲已經在 {title} 中開始!").format(
|
||||||
|
title=update.message.chat.title))
|
||||||
|
|
||||||
|
del gm.remind_dict[update.message.chat_id]
|
||||||
|
|
||||||
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')
|
||||||
@ -83,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)
|
||||||
|
|
||||||
|
|
||||||
@ -118,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
|
||||||
|
|
||||||
@ -130,22 +151,21 @@ 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!", 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}", game.translate).format(
|
text=__("輪到:{name}",
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
@run_async
|
|
||||||
def select_game(bot, update):
|
def select_game(bot, update):
|
||||||
"""Handler for callback queries to select the current game"""
|
"""Handler for callback queries to select the current game"""
|
||||||
|
|
||||||
@ -157,28 +177,30 @@ def select_game(bot, update):
|
|||||||
gm.userid_current[user_id] = player
|
gm.userid_current[user_id] = player
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
bot.sendMessage(update.callback_query.message.chat_id,
|
send_async(bot,
|
||||||
text=_("Game not found."),
|
update.callback_query.message.chat_id,
|
||||||
timeout=TIMEOUT)
|
text=_("找不到這場遊戲"))
|
||||||
return
|
return
|
||||||
|
|
||||||
back = [[InlineKeyboardButton(text=_("Back to last group"),
|
@run_async
|
||||||
switch_inline_query='')]]
|
def selected(bot):
|
||||||
|
back = [[InlineKeyboardButton(text=_("回到上一個群組"),
|
||||||
|
switch_inline_query='')]]
|
||||||
|
bot.answerCallbackQuery(update.callback_query.id,
|
||||||
|
text=_("請切換到你選擇的群組"),
|
||||||
|
show_alert=False,
|
||||||
|
timeout=TIMEOUT)
|
||||||
|
|
||||||
bot.answerCallbackQuery(update.callback_query.id,
|
bot.editMessageText(chat_id=update.callback_query.message.chat_id,
|
||||||
text=_("Please switch to the group you selected!"),
|
message_id=update.callback_query.message.message_id,
|
||||||
show_alert=False,
|
text=_("已選擇的群組: {group}\n"
|
||||||
|
"<b>請確認你已經切換到目前遊玩中的群組!</b>").format(
|
||||||
|
group=gm.userid_current[user_id].game.chat.title),
|
||||||
|
reply_markup=InlineKeyboardMarkup(back),
|
||||||
|
parse_mode=ParseMode.HTML,
|
||||||
timeout=TIMEOUT)
|
timeout=TIMEOUT)
|
||||||
|
|
||||||
bot.editMessageText(chat_id=update.callback_query.message.chat_id,
|
selected(bot)
|
||||||
message_id=update.callback_query.message.message_id,
|
|
||||||
text=_("Selected group: {group}\n"
|
|
||||||
"<b>Make sure that you switch to the correct "
|
|
||||||
"group!</b>").format(
|
|
||||||
group=gm.userid_current[user_id].game.chat.title),
|
|
||||||
reply_markup=InlineKeyboardMarkup(back),
|
|
||||||
parse_mode=ParseMode.HTML,
|
|
||||||
timeout=TIMEOUT)
|
|
||||||
|
|
||||||
|
|
||||||
@game_locales
|
@game_locales
|
||||||
@ -197,10 +219,11 @@ 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!", game.translate))
|
send_async(bot, chat.id, text=__("遊戲結束!",
|
||||||
|
multi=game.translate))
|
||||||
else:
|
else:
|
||||||
send_async(bot, chat.id, text=__("Removing {name} from the game",
|
send_async(bot, chat.id, text=__("將 {name} 從遊戲中踢除",
|
||||||
game.translate)
|
multi=game.translate)
|
||||||
.format(name=display_name(user)))
|
.format(name=display_name(user)))
|
||||||
|
|
||||||
|
|
||||||
@ -216,27 +239,24 @@ 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)
|
||||||
game.translate)
|
|
||||||
.format(name=display_name(game.current_player.user)))
|
.format(name=display_name(game.current_player.user)))
|
||||||
|
|
||||||
@run_async
|
@run_async
|
||||||
@ -269,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:
|
||||||
@ -285,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
|
||||||
@ -313,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
|
||||||
@ -340,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
|
||||||
@ -368,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
|
||||||
@ -398,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
|
||||||
@ -410,9 +427,12 @@ def skip_player(bot, update):
|
|||||||
delta = (now - started).seconds
|
delta = (now - started).seconds
|
||||||
|
|
||||||
if delta < skipped_player.waiting_time:
|
if delta < skipped_player.waiting_time:
|
||||||
|
n = skipped_player.waiting_time - delta
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=_("Please wait {time} seconds")
|
text=_("請等待 {time} 秒",
|
||||||
.format(time=(skipped_player.waiting_time - delta)),
|
"請等待 {time} 秒",
|
||||||
|
n)
|
||||||
|
.format(time=n),
|
||||||
reply_to_message_id=update.message.message_id)
|
reply_to_message_id=update.message.message_id)
|
||||||
|
|
||||||
elif skipped_player.waiting_time > 0:
|
elif skipped_player.waiting_time > 0:
|
||||||
@ -423,11 +443,15 @@ def skip_player(bot, update):
|
|||||||
except DeckEmptyError:
|
except DeckEmptyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
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} seconds.\n"
|
"輪到:{name}",
|
||||||
"Next player: {name}", game.translate)
|
"此玩家等待時間已經縮短為 {time} 秒\n"
|
||||||
.format(time=skipped_player.waiting_time,
|
"輪到:{name}",
|
||||||
|
n,
|
||||||
|
multi=game.translate)
|
||||||
|
.format(time=n,
|
||||||
name=display_name(next_player.user)))
|
name=display_name(next_player.user)))
|
||||||
game.turn()
|
game.turn()
|
||||||
|
|
||||||
@ -435,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}", 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.", 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)
|
||||||
@ -459,7 +481,6 @@ def reply_to_query(bot, update):
|
|||||||
Builds the result list for inline queries and answers to the client.
|
Builds the result list for inline queries and answers to the client.
|
||||||
"""
|
"""
|
||||||
results = list()
|
results = list()
|
||||||
playable = list()
|
|
||||||
switch = None
|
switch = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -476,7 +497,7 @@ def reply_to_query(bot, update):
|
|||||||
elif user_id == game.current_player.user.id:
|
elif user_id == game.current_player.user.id:
|
||||||
if game.choosing_color:
|
if game.choosing_color:
|
||||||
add_choose_color(results, game)
|
add_choose_color(results, game)
|
||||||
add_other_cards(playable, player, results, game)
|
add_other_cards(player, results, game)
|
||||||
else:
|
else:
|
||||||
if not player.drew:
|
if not player.drew:
|
||||||
add_draw(player, results)
|
add_draw(player, results)
|
||||||
@ -496,6 +517,8 @@ def reply_to_query(bot, update):
|
|||||||
str(card) not in added_ids))
|
str(card) not in added_ids))
|
||||||
added_ids.append(str(card))
|
added_ids.append(str(card))
|
||||||
|
|
||||||
|
add_gameinfo(game, results)
|
||||||
|
|
||||||
elif user_id != game.current_player.user.id or not game.started:
|
elif user_id != game.current_player.user.id or not game.started:
|
||||||
for card in sorted(player.cards):
|
for card in sorted(player.cards):
|
||||||
add_card(game, card, results, can_play=False)
|
add_card(game, card, results, can_play=False)
|
||||||
@ -507,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')
|
||||||
@ -526,7 +549,7 @@ def process_result(bot, update):
|
|||||||
game = player.game
|
game = player.game
|
||||||
result_id = update.chosen_inline_result.result_id
|
result_id = update.chosen_inline_result.result_id
|
||||||
chat = game.chat
|
chat = game.chat
|
||||||
except KeyError:
|
except (KeyError, AttributeError):
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.debug("Selected result: " + result_id)
|
logger.debug("Selected result: " + result_id)
|
||||||
@ -541,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}", 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':
|
||||||
@ -560,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}", game.translate)
|
text=__("輪到:{name}", multi=game.translate)
|
||||||
.format(name=display_name(game.current_player.user)))
|
.format(name=display_name(game.current_player.user)))
|
||||||
|
|
||||||
|
|
||||||
@ -571,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", player.game.translate)
|
|
||||||
.format(name=display_name(player.user)))
|
.format(name=display_name(player.user)))
|
||||||
|
|
||||||
|
|
||||||
@ -588,17 +610,18 @@ def do_play_card(bot, player, result_id):
|
|||||||
if not us:
|
if not us:
|
||||||
us = UserSetting(id=user.id)
|
us = UserSetting(id=user.id)
|
||||||
|
|
||||||
us.cards_played += 1
|
if us.stats:
|
||||||
|
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!", game.translate)
|
text=__("{name} 贏了!", multi=game.translate)
|
||||||
.format(name=user.first_name))
|
.format(name=user.first_name))
|
||||||
|
|
||||||
if us.stats:
|
if us.stats:
|
||||||
@ -607,12 +630,15 @@ def do_play_card(bot, player, result_id):
|
|||||||
if game.players_won is 0:
|
if game.players_won is 0:
|
||||||
us.first_places += 1
|
us.first_places += 1
|
||||||
|
|
||||||
|
game.players_won += 1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
gm.leave_game(user, chat)
|
gm.leave_game(user, chat)
|
||||||
except NotEnoughPlayersError:
|
except NotEnoughPlayersError:
|
||||||
send_async(bot, chat.id, text=__("Game ended!", game.translate))
|
send_async(bot, chat.id,
|
||||||
|
text=__("遊戲結束!", multi=game.translate))
|
||||||
|
|
||||||
us2 = UserSetting.get(id=game.current_player.next.user.id)
|
us2 = UserSetting.get(id=game.current_player.user.id)
|
||||||
if us2 and us2.stats:
|
if us2 and us2.stats:
|
||||||
us2.games_played += 1
|
us2.games_played += 1
|
||||||
|
|
||||||
@ -633,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))
|
||||||
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 \
|
||||||
@ -649,30 +674,28 @@ 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 張牌",
|
||||||
game.translate)
|
multi=game.translate)
|
||||||
.format(name=player.prev.user.first_name))
|
.format(name=player.prev.user.first_name))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
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))
|
||||||
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} 六張牌",
|
||||||
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))
|
||||||
try:
|
try:
|
||||||
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))
|
||||||
game.translate))
|
|
||||||
|
|
||||||
game.turn()
|
game.turn()
|
||||||
|
|
||||||
@ -687,11 +710,14 @@ dispatcher.add_handler(CommandHandler('join', join_game))
|
|||||||
dispatcher.add_handler(CommandHandler('leave', leave_game))
|
dispatcher.add_handler(CommandHandler('leave', leave_game))
|
||||||
dispatcher.add_handler(CommandHandler('open', open_game))
|
dispatcher.add_handler(CommandHandler('open', open_game))
|
||||||
dispatcher.add_handler(CommandHandler('close', close_game))
|
dispatcher.add_handler(CommandHandler('close', close_game))
|
||||||
dispatcher.add_handler(CommandHandler('enable_translations',
|
# dispatcher.add_handler(CommandHandler('enable_translations',
|
||||||
enable_translations))
|
# enable_translations))
|
||||||
dispatcher.add_handler(CommandHandler('disable_translations',
|
# dispatcher.add_handler(CommandHandler('disable_translations',
|
||||||
disable_translations))
|
# disable_translations))
|
||||||
dispatcher.add_handler(CommandHandler('skip', skip_player))
|
dispatcher.add_handler(CommandHandler('skip', skip_player))
|
||||||
|
dispatcher.add_handler(CommandHandler('notify_me', notify_me))
|
||||||
|
simple_commands.register()
|
||||||
|
settings.register()
|
||||||
dispatcher.add_handler(MessageHandler([Filters.status_update], status_update))
|
dispatcher.add_handler(MessageHandler([Filters.status_update], status_update))
|
||||||
dispatcher.add_error_handler(error)
|
dispatcher.add_error_handler(error)
|
||||||
|
|
||||||
|
4
card.py
4
card.py
@ -116,8 +116,8 @@ STICKERS = {
|
|||||||
'y_reverse': 'BQADBAADQQIAAl9XmQABZdQFahGG6UQC',
|
'y_reverse': 'BQADBAADQQIAAl9XmQABZdQFahGG6UQC',
|
||||||
'draw_four': 'BQADBAAD9QEAAl9XmQABVlkSNfhn76cC',
|
'draw_four': 'BQADBAAD9QEAAl9XmQABVlkSNfhn76cC',
|
||||||
'colorchooser': 'BQADBAAD8wEAAl9XmQABl9rUOPqx4E4C',
|
'colorchooser': 'BQADBAAD8wEAAl9XmQABl9rUOPqx4E4C',
|
||||||
'option_draw': 'BQADBAADzAIAAl9XmQABTkPaOqA5HIMC',
|
'option_draw': 'BQADBAAD-AIAAl9XmQABxEjEcFM-VHIC',
|
||||||
'option_pass': 'BQADBAADzgIAAl9XmQABWSDq3RIg3c0C',
|
'option_pass': 'BQADBAAD-gIAAl9XmQABcEkAAbaZ4SicAg',
|
||||||
'option_bluff': 'BQADBAADygIAAl9XmQABJoLfB9ntI2UC',
|
'option_bluff': 'BQADBAADygIAAl9XmQABJoLfB9ntI2UC',
|
||||||
'option_info': 'BQADBAADxAIAAl9XmQABC5v3Z77VLfEC'
|
'option_info': 'BQADBAADxAIAAl9XmQABC5v3Z77VLfEC'
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,8 @@ class GameManager(object):
|
|||||||
self.chatid_games = dict()
|
self.chatid_games = dict()
|
||||||
self.userid_players = dict()
|
self.userid_players = dict()
|
||||||
self.userid_current = dict()
|
self.userid_current = dict()
|
||||||
|
self.remind_dict = dict()
|
||||||
|
|
||||||
self.logger = logging.getLogger(__name__)
|
self.logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def new_game(self, chat):
|
def new_game(self, chat):
|
||||||
@ -47,6 +49,11 @@ class GameManager(object):
|
|||||||
if chat_id not in self.chatid_games:
|
if chat_id not in self.chatid_games:
|
||||||
self.chatid_games[chat_id] = list()
|
self.chatid_games[chat_id] = list()
|
||||||
|
|
||||||
|
# remove old games
|
||||||
|
for g in list(self.chatid_games[chat_id]):
|
||||||
|
if not g.players:
|
||||||
|
self.chatid_games[chat_id].remove(g)
|
||||||
|
|
||||||
self.chatid_games[chat_id].append(game)
|
self.chatid_games[chat_id].append(game)
|
||||||
return game
|
return game
|
||||||
|
|
||||||
@ -80,6 +87,11 @@ class GameManager(object):
|
|||||||
except NotEnoughPlayersError:
|
except NotEnoughPlayersError:
|
||||||
self.end_game(chat, user)
|
self.end_game(chat, user)
|
||||||
|
|
||||||
|
if user.id not in self.userid_players:
|
||||||
|
self.userid_players[user.id] = list()
|
||||||
|
|
||||||
|
players = self.userid_players[user.id]
|
||||||
|
|
||||||
player = Player(game, user)
|
player = Player(game, user)
|
||||||
|
|
||||||
players.append(player)
|
players.append(player)
|
||||||
@ -92,7 +104,17 @@ class GameManager(object):
|
|||||||
players = self.userid_players.get(user.id, list())
|
players = self.userid_players.get(user.id, list())
|
||||||
|
|
||||||
if not player:
|
if not player:
|
||||||
raise NoGameInChatError
|
games = self.chatid_games[chat.id]
|
||||||
|
for g in games:
|
||||||
|
for p in g.players:
|
||||||
|
if p.user.id == user.id:
|
||||||
|
if p is g.current_player:
|
||||||
|
g.turn()
|
||||||
|
|
||||||
|
p.leave()
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
raise NoGameInChatError
|
||||||
|
|
||||||
game = player.game
|
game = player.game
|
||||||
|
|
||||||
@ -130,14 +152,29 @@ class GameManager(object):
|
|||||||
|
|
||||||
# Clear game
|
# Clear game
|
||||||
for player_in_game in game.players:
|
for player_in_game in game.players:
|
||||||
this_users_players = self.userid_players[player_in_game.user.id]
|
this_users_players = \
|
||||||
this_users_players.remove(player_in_game)
|
self.userid_players.get(player_in_game.user.id, list())
|
||||||
|
|
||||||
|
try:
|
||||||
|
this_users_players.remove(player_in_game)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
if this_users_players:
|
if this_users_players:
|
||||||
self.userid_current[player.user.id] = this_users_players[0]
|
try:
|
||||||
|
self.userid_current[player_in_game.user.id] = this_users_players[0]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
del self.userid_players[player_in_game.user.id]
|
try:
|
||||||
del self.userid_current[player_in_game.user.id]
|
del self.userid_players[player_in_game.user.id]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
del self.userid_current[player_in_game.user.id]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
self.chatid_games[chat.id].remove(game)
|
self.chatid_games[chat.id].remove(game)
|
||||||
if not self.chatid_games[chat.id]:
|
if not self.chatid_games[chat.id]:
|
||||||
|
BIN
images/png/option_draw2.png
Normal file
BIN
images/png/option_draw2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 39 KiB |
BIN
images/png/option_pass2.png
Normal file
BIN
images/png/option_pass2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
171
internationalization.py
Normal file
171
internationalization.py
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Telegram bot to play UNO in group chats
|
||||||
|
# Copyright (c) 2016 Jannes Höke <uno@jhoeke.de>
|
||||||
|
#
|
||||||
|
# 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/>.
|
||||||
|
|
||||||
|
|
||||||
|
import gettext
|
||||||
|
from functools import wraps
|
||||||
|
|
||||||
|
from locales import available_locales
|
||||||
|
from database import db_session
|
||||||
|
from user_setting import UserSetting
|
||||||
|
from shared_vars import gm
|
||||||
|
|
||||||
|
GETTEXT_DOMAIN = 'unobot'
|
||||||
|
GETTEXT_DIR = 'locales'
|
||||||
|
|
||||||
|
|
||||||
|
class _Underscore(object):
|
||||||
|
"""Class to emulate flufl.i18n behaviour, but with plural support"""
|
||||||
|
def __init__(self):
|
||||||
|
self.translators = {
|
||||||
|
locale: gettext.GNUTranslations(
|
||||||
|
open(gettext.find(
|
||||||
|
GETTEXT_DOMAIN, GETTEXT_DIR, languages=[locale]
|
||||||
|
), 'rb')
|
||||||
|
)
|
||||||
|
for locale
|
||||||
|
in available_locales.keys()
|
||||||
|
if locale != 'zh_TW' # No translation file for zh_TW
|
||||||
|
}
|
||||||
|
self.locale_stack = list()
|
||||||
|
|
||||||
|
def push(self, locale):
|
||||||
|
self.locale_stack.append(locale)
|
||||||
|
|
||||||
|
def pop(self):
|
||||||
|
if self.locale_stack:
|
||||||
|
return self.locale_stack.pop()
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def code(self):
|
||||||
|
if self.locale_stack:
|
||||||
|
return self.locale_stack[-1]
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def __call__(self, singular, plural=None, n=1, locale=None):
|
||||||
|
if not locale:
|
||||||
|
locale = self.locale_stack[-1]
|
||||||
|
|
||||||
|
if locale not in self.translators.keys():
|
||||||
|
if n is 1:
|
||||||
|
return singular
|
||||||
|
else:
|
||||||
|
return plural
|
||||||
|
|
||||||
|
translator = self.translators[locale]
|
||||||
|
|
||||||
|
if plural is None:
|
||||||
|
return translator.gettext(singular)
|
||||||
|
else:
|
||||||
|
return translator.ngettext(singular, plural, n)
|
||||||
|
|
||||||
|
_ = _Underscore()
|
||||||
|
|
||||||
|
|
||||||
|
def __(singular, plural=None, n=1, multi=False):
|
||||||
|
"""Translates text into all locales on the stack"""
|
||||||
|
translations = list()
|
||||||
|
|
||||||
|
if not multi and len(set(_.locale_stack)) >= 1:
|
||||||
|
translations.append(_(singular, plural, n, 'zh_TW'))
|
||||||
|
|
||||||
|
else:
|
||||||
|
for locale in _.locale_stack:
|
||||||
|
translation = _(singular, plural, n, locale)
|
||||||
|
|
||||||
|
if translation not in translations:
|
||||||
|
translations.append(translation)
|
||||||
|
|
||||||
|
return '\n'.join(translations)
|
||||||
|
|
||||||
|
|
||||||
|
def user_locale(func):
|
||||||
|
@wraps(func)
|
||||||
|
@db_session
|
||||||
|
def wrapped(bot, update, *pargs, **kwargs):
|
||||||
|
user, chat = _user_chat_from_update(update)
|
||||||
|
|
||||||
|
with db_session:
|
||||||
|
us = UserSetting.get(id=user.id)
|
||||||
|
|
||||||
|
if us and us.lang != 'en':
|
||||||
|
_.push(us.lang)
|
||||||
|
else:
|
||||||
|
_.push('zh_TW')
|
||||||
|
|
||||||
|
result = func(bot, update, *pargs, **kwargs)
|
||||||
|
_.pop()
|
||||||
|
return result
|
||||||
|
return wrapped
|
||||||
|
|
||||||
|
|
||||||
|
def game_locales(func):
|
||||||
|
@wraps(func)
|
||||||
|
@db_session
|
||||||
|
def wrapped(bot, update, *pargs, **kwargs):
|
||||||
|
user, chat = _user_chat_from_update(update)
|
||||||
|
player = gm.player_for_user_in_chat(user, chat)
|
||||||
|
locales = list()
|
||||||
|
|
||||||
|
if player:
|
||||||
|
for player in player.game.players:
|
||||||
|
us = UserSetting.get(id=player.user.id)
|
||||||
|
|
||||||
|
if us and us.lang != 'en':
|
||||||
|
loc = us.lang
|
||||||
|
else:
|
||||||
|
loc = 'zh_TW'
|
||||||
|
|
||||||
|
if loc in locales:
|
||||||
|
continue
|
||||||
|
|
||||||
|
_.push(loc)
|
||||||
|
locales.append(loc)
|
||||||
|
|
||||||
|
result = func(bot, update, *pargs, **kwargs)
|
||||||
|
|
||||||
|
while _.code:
|
||||||
|
_.pop()
|
||||||
|
|
||||||
|
return result
|
||||||
|
return wrapped
|
||||||
|
|
||||||
|
|
||||||
|
def _user_chat_from_update(update):
|
||||||
|
|
||||||
|
try:
|
||||||
|
user = update.message.from_user
|
||||||
|
chat = update.message.chat
|
||||||
|
except (NameError, AttributeError):
|
||||||
|
try:
|
||||||
|
user = update.inline_query.from_user
|
||||||
|
chat = gm.userid_current[user.id].game.chat
|
||||||
|
except KeyError:
|
||||||
|
chat = None
|
||||||
|
except (NameError, AttributeError):
|
||||||
|
try:
|
||||||
|
user = update.chosen_inline_result.from_user
|
||||||
|
chat = gm.userid_current[user.id].game.chat
|
||||||
|
except (NameError, AttributeError, KeyError):
|
||||||
|
chat = None
|
||||||
|
|
||||||
|
return user, chat
|
@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Telegram bot to play UNO in group chats
|
||||||
|
# Copyright (c) 2016 Jannes Höke <uno@jhoeke.de>
|
||||||
|
#
|
||||||
|
# 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/>.
|
||||||
|
|
||||||
|
|
||||||
|
from .available import available_locales
|
30
locales/available.py
Normal file
30
locales/available.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Telegram bot to play UNO in group chats
|
||||||
|
# Copyright (c) 2016 Jannes Höke <uno@jhoeke.de>
|
||||||
|
#
|
||||||
|
# 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 a dict of all available locales to the language name"""
|
||||||
|
|
||||||
|
OFFSET = 127462 - ord('A')
|
||||||
|
|
||||||
|
|
||||||
|
def flag(code):
|
||||||
|
return chr(ord(code[0]) + OFFSET) + chr(ord(code[1]) + OFFSET)
|
||||||
|
|
||||||
|
|
||||||
|
available_locales = {'zh_TW': flag('TW') + ' 中文(台灣)'}
|
@ -1,442 +0,0 @@
|
|||||||
# Telegram bot to play UNO in group chats
|
|
||||||
# Copyright (c) 2016 Jannes Höke <uno@jhoeke.de>
|
|
||||||
#
|
|
||||||
# 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/>.
|
|
||||||
# Jannes Höke <uno@jhoeke.de>, 2016.
|
|
||||||
#
|
|
||||||
#: bot.py:224
|
|
||||||
msgid ""
|
|
||||||
msgstr ""
|
|
||||||
"Project-Id-Version: uno_bot 0.1\n"
|
|
||||||
"Report-Msgid-Bugs-To: uno@jhoeke.de\n"
|
|
||||||
"POT-Creation-Date: 2016-05-19 22:38+0200\n"
|
|
||||||
"PO-Revision-Date: 2016-05-21 21:16+0200\n"
|
|
||||||
"Last-Translator: Jannes Höke <uno@jhoeke.de>\n"
|
|
||||||
"Language-Team: Deutsch <uno@jhoeke.de>\n"
|
|
||||||
"Language: de_DE\n"
|
|
||||||
"MIME-Version: 1.0\n"
|
|
||||||
"Content-Type: text/plain; charset=UTF-8\n"
|
|
||||||
"Content-Transfer-Encoding: 8bit\n"
|
|
||||||
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
|
||||||
"X-Generator: Gtranslator 2.91.6\n"
|
|
||||||
|
|
||||||
#: bot.py:60
|
|
||||||
msgid "Follow these steps:\n"
|
|
||||||
"\n"
|
|
||||||
"1. Add this bot to a group\n"
|
|
||||||
"2. In the group, start a new game with /new or join an already running game "
|
|
||||||
"with /join\n"
|
|
||||||
"3. After at least two players have joined, start the game with /start\n"
|
|
||||||
"4. Type <code>@mau_mau_bot</code> into your chat box and hit <b>space</b>, "
|
|
||||||
"or click the <code>via @mau_mau_bot</code> text next to messages. You will "
|
|
||||||
"see your cards (some greyed out), any extra options like drawing, and a <b>?"
|
|
||||||
"</b> to see the current game state. The <b>greyed out cards</b> are those "
|
|
||||||
"you <b>can not play</b> at the moment. Tap an option to execute the selected "
|
|
||||||
"action.\n"
|
|
||||||
"Players can join the game at any time. To leave a game, use /leave. If a "
|
|
||||||
"player takes more than 90 seconds to play, you can use /skip to skip that "
|
|
||||||
"player.\n"
|
|
||||||
"\n"
|
|
||||||
"<b>Language</b> and other settings: /settings\n"
|
|
||||||
"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."
|
|
||||||
msgstr ""
|
|
||||||
"Folge den folgenden Schritten:\n"
|
|
||||||
"\n"
|
|
||||||
"1. Füge diesen Bot einer Gruppe hinzu\n"
|
|
||||||
"2. In einer Gruppe kannst du mit /new ein neues Spiel erstellen und mit /"
|
|
||||||
"join einem bestehenden Spiel beitreten\n"
|
|
||||||
"3. Nachdem mindestens zwei Spieler beigetreten sind, starte das Spiel mit /"
|
|
||||||
"start\n"
|
|
||||||
"3. Gib <code>@mau_mau_bot</code> in deine Chatbox ein und drücke die "
|
|
||||||
"<b>Leertaste</b>, oder tippe auf den <code>via @mau_mau_bot</code>-Text "
|
|
||||||
"neben oder über den Nachrichten. Du siehst deine Karten (einige in grau), "
|
|
||||||
"zusätzliche Optionen wie z. B. Ziehen, und ein <b>?</b> um den Infos über "
|
|
||||||
"das laufende Spiel anzuzeigen. Die <b>grauen Karten</b> kannst du gerade "
|
|
||||||
"<b>nicht spielen</b>. Tippe eine der Optionen oder Karten an, um diese "
|
|
||||||
"Aktion auszuführen bzw. die Karte zu spielen. \n"
|
|
||||||
"Spieler können dem Spiel jederzeit beitreten. Um das Spiel zu verlassen, "
|
|
||||||
"benutze /leave. Wenn ein Spieler länger als 90 Sekunden braucht, kannst du "
|
|
||||||
"ihn mit /skip überspringen.\n"
|
|
||||||
"\n"
|
|
||||||
"<b>Sprache</b> und andere Einstellungen: /settings\n"
|
|
||||||
"Weitere Kommandos (nur Spiel-Ersteller):\n"
|
|
||||||
"/close - Lobby schließen\n"
|
|
||||||
"/open - Lobby öffnen\n"
|
|
||||||
"/enable_translations - Übersetze relevante Texte in alle im Spiel gesprochenen"
|
|
||||||
" Sprachen\n"
|
|
||||||
"/disable_translations - Verwende Englisch für diese Texte\n"
|
|
||||||
"\n"
|
|
||||||
"<b>Experimentell</b>: Spiele in mehreren Gruppen gleichzeitig. Um die "
|
|
||||||
"Gruppe, in der du deine Karte spielen willst, auszuwählen, tippe auf den "
|
|
||||||
"<code>Aktuelles Spiel: ...</code>-Button.\n"
|
|
||||||
"Wenn dir dieser Bot gefällt, <a href=\"https://telegram.me/storebot?"
|
|
||||||
"start=mau_mau_bot\">bewerte ihn</a>, tritt dem <a href=\"https://telegram.me/"
|
|
||||||
"unobotupdates\">News-Channel</a> bei und kaufe ein UNO Kartenspiel."
|
|
||||||
|
|
||||||
#: bot.py:88
|
|
||||||
msgid ""
|
|
||||||
"This bot is Free Software and licensed under the AGPL. The code is available "
|
|
||||||
"here: \n"
|
|
||||||
"https://github.com/jh0ker/mau_mau_bot"
|
|
||||||
msgstr ""
|
|
||||||
"Dieser Bot ist Freie Software und lizenziert unter der AGPL. Der Quellcode "
|
|
||||||
"ist hier verfügbar:\n"
|
|
||||||
"https://github.com/jh0ker/mau_mau_bot"
|
|
||||||
|
|
||||||
#: bot.py:133
|
|
||||||
msgid ""
|
|
||||||
"Created a new game! Join the game with /join and start the game with /start"
|
|
||||||
msgstr ""
|
|
||||||
"Neues Spiel erstellt! Tritt dem Spiel mit /join bei und starte es mit /start"
|
|
||||||
|
|
||||||
#: bot.py:152
|
|
||||||
msgid "The lobby is closed"
|
|
||||||
msgstr "Die Lobby ist geschlossen"
|
|
||||||
|
|
||||||
#: bot.py:156
|
|
||||||
msgid "No game is running at the moment. Create a new game with /new"
|
|
||||||
msgstr "Zur Zeit läuft kein Spiel. Erstelle ein neues mit /new"
|
|
||||||
|
|
||||||
#: bot.py:162
|
|
||||||
msgid "You already joined the game. Start the game with /start"
|
|
||||||
msgstr "Du bist dem Spiel bereits beigetreten. Starte es mit /start"
|
|
||||||
|
|
||||||
#: bot.py:167
|
|
||||||
msgid "Joined the game"
|
|
||||||
msgstr "Spiel beigetreten"
|
|
||||||
|
|
||||||
#: bot.py:179 bot.py:191
|
|
||||||
msgid "You are not playing in a game in this group."
|
|
||||||
msgstr "Du spielst in keinem Spiel in dieser Gruppe."
|
|
||||||
|
|
||||||
#: bot.py:197 bot.py:258 bot.py:595
|
|
||||||
msgid "Game ended!"
|
|
||||||
msgstr "Spiel beendet!"
|
|
||||||
|
|
||||||
#: bot.py:201
|
|
||||||
msgid "Okay. Next Player: {name}"
|
|
||||||
msgstr "Okay. Nächster Spieler: {name}"
|
|
||||||
|
|
||||||
#: bot.py:219
|
|
||||||
msgid "Game not found."
|
|
||||||
msgstr "Spiel nicht gefunden."
|
|
||||||
|
|
||||||
#: bot.py:223
|
|
||||||
msgid "Back to last group"
|
|
||||||
msgstr "Zurück zur letzten Gruppe"
|
|
||||||
|
|
||||||
#: bot.py:227
|
|
||||||
msgid "Please switch to the group you selected!"
|
|
||||||
msgstr "Bitte wechsele zu der Gruppe, die du gewählt hast!"
|
|
||||||
|
|
||||||
#: bot.py:233
|
|
||||||
#, python-format
|
|
||||||
msgid ""
|
|
||||||
"Selected group: {group}\n"
|
|
||||||
"<b>Make sure that you switch to the correct group!</b>"
|
|
||||||
msgstr ""
|
|
||||||
"Ausgewählte Gruppe: {group}\n"
|
|
||||||
"<b>Stell sicher, dass du in die richtige Gruppe wechselst!</b>"
|
|
||||||
|
|
||||||
#: bot.py:260
|
|
||||||
#, python-format
|
|
||||||
msgid "Removing {name} from the game"
|
|
||||||
msgstr "Entferne {name} aus dem Spiel"
|
|
||||||
|
|
||||||
#: bot.py:273
|
|
||||||
msgid "There is no game running in this chat. Create a new one with /new"
|
|
||||||
msgstr ""
|
|
||||||
"In dieser Gruppe gibt es kein laufendes Spiel. Erstelle ein neues mit /new"
|
|
||||||
|
|
||||||
#: bot.py:278
|
|
||||||
msgid "The game has already started"
|
|
||||||
msgstr "Das Spiel hat bereits begonnen"
|
|
||||||
|
|
||||||
#: bot.py:281
|
|
||||||
msgid "At least two players must /join the game before you can start it"
|
|
||||||
msgstr "Es müssen mindestens zwei Spieler dem Spiel beitreten, bevor du es "
|
|
||||||
"starten kannst"
|
|
||||||
|
|
||||||
#: bot.py:297
|
|
||||||
#, python-format, fuzzy
|
|
||||||
msgid "First player: {name}\n"
|
|
||||||
"Use /close to stop people from joining the game.\n"
|
|
||||||
"Enable multi-translations with /enable_translations"
|
|
||||||
msgstr ""
|
|
||||||
"Erster Spieler: {name}\n"
|
|
||||||
"Benutze /close, um zu verhindern, dass weitere Spieler beitreten."
|
|
||||||
|
|
||||||
#: bot.py:321
|
|
||||||
msgid "Please select the group you want to play in."
|
|
||||||
msgstr "Bitte wähle die Gruppe, in der du spielen willst."
|
|
||||||
|
|
||||||
#: bot.py:335 bot.py:361
|
|
||||||
msgid "There is no running game in this chat."
|
|
||||||
msgstr "In dieser Gruppe läuft gerade kein Spiel."
|
|
||||||
|
|
||||||
#: bot.py:342
|
|
||||||
msgid "Closed the lobby. No more players can join this game."
|
|
||||||
msgstr ""
|
|
||||||
"Lobby geschlossen. Diesem Spiel können keine weiteren Spieler beitreten."
|
|
||||||
|
|
||||||
#: bot.py:348 bot.py:373
|
|
||||||
#, python-format
|
|
||||||
msgid "Only the game creator ({name}) can do that."
|
|
||||||
msgstr "Dies kann nur der Ersteller des Spiels ({name}) tun."
|
|
||||||
|
|
||||||
#: bot.py:349
|
|
||||||
#, python-format
|
|
||||||
msgid "Enabled multi-translations. Disable with /disable_translations"
|
|
||||||
msgstr "Multi-Übersetzungen aktiviert. Deaktivieren mit /disable_translations"
|
|
||||||
|
|
||||||
#: bot.py:377
|
|
||||||
#, python-format
|
|
||||||
msgid "Disabled multi-translations. Enable them again with /enable_translations"
|
|
||||||
msgstr "Multi-Übersetzungen deaktiviert. Aktiviere sie wieder mit "
|
|
||||||
"/enable_translations"
|
|
||||||
|
|
||||||
#: bot.py:368
|
|
||||||
msgid "Opened the lobby. New players may /join the game."
|
|
||||||
msgstr "Lobby geöffnet. Neue Spieler können nun beitreten."
|
|
||||||
|
|
||||||
#: bot.py:386
|
|
||||||
msgid "You are not playing in a game in this chat."
|
|
||||||
msgstr "Du spielst kein Spiel in dieser Gruppe."
|
|
||||||
|
|
||||||
#: bot.py:400
|
|
||||||
#, python-format
|
|
||||||
msgid "Please wait {time} seconds"
|
|
||||||
msgstr "Bitte warte {time} Sekunden"
|
|
||||||
|
|
||||||
#: bot.py:413
|
|
||||||
#, python-format
|
|
||||||
msgid ""
|
|
||||||
"Waiting time to skip this player has been reduced to {time} seconds.\n"
|
|
||||||
"Next player: {name}"
|
|
||||||
msgstr ""
|
|
||||||
"Die Wartezeit um diesen Spieler zu überspringen wurde auf {time} Sekunden "
|
|
||||||
"reduziert.\n"
|
|
||||||
"Nächster Spieler: {name}"
|
|
||||||
|
|
||||||
#: bot.py:424
|
|
||||||
#, python-format
|
|
||||||
msgid ""
|
|
||||||
"{name1} was skipped four times in a row and has been removed from the game.\n"
|
|
||||||
"Next player: {name2}"
|
|
||||||
msgstr ""
|
|
||||||
"{name1} wurde vier Mal hintereinander übersprungen und daher aus dem Spiel "
|
|
||||||
"entfernt.\n"
|
|
||||||
"Nächster Spieler: {name2}"
|
|
||||||
|
|
||||||
#: bot.py:432
|
|
||||||
#, python-format
|
|
||||||
msgid ""
|
|
||||||
"{name} was skipped four times in a row and has been removed from the game.\n"
|
|
||||||
"The game ended."
|
|
||||||
msgstr ""
|
|
||||||
"{name1} wurde vier Mal hintereinander übersprungen und daher aus dem Spiel "
|
|
||||||
"entfernt.\n"
|
|
||||||
"Das Spiel wurde beendet."
|
|
||||||
|
|
||||||
#: bot.py:455
|
|
||||||
msgid "All news here: https://telegram.me/unobotupdates"
|
|
||||||
msgstr "Alle News hier: https://telegram.me/unobotupdates"
|
|
||||||
|
|
||||||
#: bot.py:513
|
|
||||||
#, python-format
|
|
||||||
msgid "Current game: %s"
|
|
||||||
msgstr "Aktuelles Spiel: {game}"
|
|
||||||
|
|
||||||
#: bot.py:545
|
|
||||||
#, python-format
|
|
||||||
msgid "Cheat attempt by %s"
|
|
||||||
msgstr "{name} hat versucht zu schummeln!"
|
|
||||||
|
|
||||||
#: bot.py:562
|
|
||||||
msgid "Next player: {name}"
|
|
||||||
msgstr "Nächster Spieler: {name}"
|
|
||||||
|
|
||||||
#: bot.py:572
|
|
||||||
#, python-format
|
|
||||||
msgid "Waiting time for {name} has been reset to 90 seconds"
|
|
||||||
msgstr "Die Wartezeit für {name} wurde auf 90 Sekunden zurückgesetzt."
|
|
||||||
|
|
||||||
#: bot.py:585
|
|
||||||
msgid "Please choose a color"
|
|
||||||
msgstr "Bitte wähle eine Farbe"
|
|
||||||
|
|
||||||
#: bot.py:591
|
|
||||||
#, python-format
|
|
||||||
msgid "{name} won!"
|
|
||||||
msgstr "{name} hat gewonnen!"
|
|
||||||
|
|
||||||
#: bot.py:613 bot.py:635 bot.py:647
|
|
||||||
msgid "There are no more cards in the deck."
|
|
||||||
msgstr "Es sind keine Karten mehr im Deck."
|
|
||||||
|
|
||||||
#: bot.py:627
|
|
||||||
#, python-format
|
|
||||||
msgid "Bluff called! Giving 4 cards to {name}"
|
|
||||||
msgstr "Bluff gecalled! {name} bekommt 4 Karten."
|
|
||||||
|
|
||||||
#: bot.py:639
|
|
||||||
#, python-format
|
|
||||||
msgid "{name1} didn't bluff! Giving 6 cards to {name2}"
|
|
||||||
msgstr "{name1} hat nicht geblufft! {name2} bekommt 6 Karten."
|
|
||||||
|
|
||||||
#: results.py:38
|
|
||||||
msgid "Choose Color"
|
|
||||||
msgstr "Wähle Farbe"
|
|
||||||
|
|
||||||
#: results.py:56
|
|
||||||
msgid "Cards (tap for game state):"
|
|
||||||
msgstr "Karten (tippe für Spielinfo):"
|
|
||||||
|
|
||||||
#: results.py:60 results.py:123 results.py:165
|
|
||||||
msgid "Current player: {name}"
|
|
||||||
msgstr "Aktueller Spieler: {name}"
|
|
||||||
|
|
||||||
#: results.py:61 results.py:124 results.py:167
|
|
||||||
msgid "Last card: {card}"
|
|
||||||
msgstr "Letzte Karte: {card}"
|
|
||||||
|
|
||||||
#: results.py:62 results.py:125 results.py:168
|
|
||||||
msgid "Players: {player_list}"
|
|
||||||
msgstr "Spieler: {player_list}"
|
|
||||||
|
|
||||||
#: results.py:72
|
|
||||||
#, python-format
|
|
||||||
msgid "{name} ({number} cards)"
|
|
||||||
msgstr "{name} ({number} Karten)"
|
|
||||||
|
|
||||||
#: results.py:81
|
|
||||||
msgid "You are not playing"
|
|
||||||
msgstr "Du spielst gerade nicht"
|
|
||||||
|
|
||||||
#: results.py:83
|
|
||||||
msgid ""
|
|
||||||
"Not playing right now. Use /new to start a game or /join to join the current "
|
|
||||||
"game in this group"
|
|
||||||
msgstr ""
|
|
||||||
"Du spielst gerade nicht. Benutze /new um ein neues Spiel zu starten oder /"
|
|
||||||
"join, um einem bestehenden Spiel beizutreten."
|
|
||||||
|
|
||||||
#: results.py:95
|
|
||||||
msgid "The game wasn't started yet"
|
|
||||||
msgstr "Das Spiel wurde noch nicht gestartet."
|
|
||||||
|
|
||||||
#: results.py:97
|
|
||||||
msgid "Start the game with /start"
|
|
||||||
msgstr "Starte das Spiel mit /start"
|
|
||||||
|
|
||||||
#: results.py:108
|
|
||||||
#, python-format
|
|
||||||
msgid "Drawing 1 card"
|
|
||||||
msgstr "Zieht 1 Karte"
|
|
||||||
|
|
||||||
msgid "Drawing {number} cards"
|
|
||||||
msgstr "Zieht {number} Karten"
|
|
||||||
|
|
||||||
#: results.py:136
|
|
||||||
msgid "Pass"
|
|
||||||
msgstr "Passe"
|
|
||||||
|
|
||||||
#: results.py:148
|
|
||||||
msgid "I'm calling your bluff!"
|
|
||||||
msgstr "Ich glaube du bluffst!"
|
|
||||||
|
|
||||||
#: settings.py:39
|
|
||||||
msgid "Please edit your settings in a private chat with the bot."
|
|
||||||
msgstr "Bitte ändere deine Einstellungen in einem privaten Chat mit dem Bot."
|
|
||||||
|
|
||||||
#: settings.py:49
|
|
||||||
msgid "Enable statistics"
|
|
||||||
msgstr "Statistiken aktivieren"
|
|
||||||
|
|
||||||
#: settings.py:51
|
|
||||||
msgid "Delete all statistics"
|
|
||||||
msgstr "Alle Statistiken löschen"
|
|
||||||
|
|
||||||
#: settings.py:53
|
|
||||||
msgid "Language"
|
|
||||||
msgstr "Sprache"
|
|
||||||
|
|
||||||
#: settings.py:54
|
|
||||||
msgid "Settings"
|
|
||||||
msgstr "Einstellungen"
|
|
||||||
|
|
||||||
#: settings.py:68
|
|
||||||
msgid "Enabled statistics!"
|
|
||||||
msgstr "Statistiken aktiviert!"
|
|
||||||
|
|
||||||
#: settings.py:70
|
|
||||||
msgid "Select locale"
|
|
||||||
msgstr "Bitte Sprache auswählen"
|
|
||||||
|
|
||||||
#: settings.py:81
|
|
||||||
msgid "Deleted and disabled statistics!"
|
|
||||||
msgstr "Alle Statistiken gelöscht und deaktiviert!"
|
|
||||||
|
|
||||||
#: settings.py:94
|
|
||||||
msgid "Set locale!"
|
|
||||||
msgstr "Sprache gesetzt!"
|
|
||||||
|
|
||||||
|
|
||||||
#: simple_commands.py
|
|
||||||
msgid "You did not enable statistics. Use /settings in "
|
|
||||||
"a private chat with the bot to enable them."
|
|
||||||
msgstr "Du hast die Spiel-Statistiken nicht aktiviert. Aktiviere sie, mit dem "
|
|
||||||
"/settings-Kommando in einem privaten Chat mit dem Bot."
|
|
||||||
|
|
||||||
#: simple_commands.py
|
|
||||||
msgid "{number} games played"
|
|
||||||
msgstr "{number} gespielte Spiele"
|
|
||||||
|
|
||||||
#: simple_commands.py
|
|
||||||
msgid "{number} first places"
|
|
||||||
msgstr "{number}x 1. Platz"
|
|
||||||
|
|
||||||
#: simple_commands.py
|
|
||||||
msgid "{number} cards played"
|
|
||||||
msgstr "{number} gespielte Karten"
|
|
||||||
|
|
||||||
|
|
||||||
#: utils.py
|
|
||||||
msgid "{emoji} Green"
|
|
||||||
msgstr "{emoji} Grün"
|
|
||||||
|
|
||||||
#: utils.py
|
|
||||||
msgid "{emoji} Red"
|
|
||||||
msgstr "{emoji} Rot"
|
|
||||||
|
|
||||||
#: utils.py
|
|
||||||
msgid "{emoji} Blue"
|
|
||||||
msgstr "{emoji} Blau"
|
|
||||||
|
|
||||||
#: utils.py
|
|
||||||
msgid "{emoji} Yellow"
|
|
||||||
msgstr "{emoji} Gelb"
|
|
||||||
|
|
@ -29,6 +29,7 @@ msgstr ""
|
|||||||
"MIME-Version: 1.0\n"
|
"MIME-Version: 1.0\n"
|
||||||
"Content-Type: text/plain; charset=utf-8\n"
|
"Content-Type: text/plain; charset=utf-8\n"
|
||||||
"Content-Transfer-Encoding: utf-8\n"
|
"Content-Transfer-Encoding: utf-8\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
|
||||||
|
|
||||||
#: bot.py:60
|
#: bot.py:60
|
||||||
@ -39,15 +40,16 @@ msgid "Follow these steps:\n"
|
|||||||
"2. In the group, start a new game with /new or join an already running game "
|
"2. In the group, start a new game with /new or join an already running game "
|
||||||
"with /join\n"
|
"with /join\n"
|
||||||
"3. After at least two players have joined, start the game with /start\n"
|
"3. After at least two players have joined, start the game with /start\n"
|
||||||
"4. Type <code>@mau_mau_bot</code> into your chat box and hit <b>space</b>, "
|
"4. Type <code>@unobot</code> into your chat box and hit <b>space</b>, "
|
||||||
"or click the <code>via @mau_mau_bot</code> text next to messages. You will "
|
"or click the <code>via @unobot</code> text next to messages. You will "
|
||||||
"see your cards (some greyed out), any extra options like drawing, and a <b>?"
|
"see your cards (some greyed out), any extra options like drawing, and a <b>?"
|
||||||
"</b> to see the current game state. The <b>greyed out cards</b> are those "
|
"</b> to see the current game state. The <b>greyed out cards</b> are those "
|
||||||
"you <b>can not play</b> at the moment. Tap an option to execute the selected "
|
"you <b>can not play</b> at the moment. Tap an option to execute the selected "
|
||||||
"action.\n"
|
"action.\n"
|
||||||
"Players can join the game at any time. To leave a game, use /leave. If a "
|
"Players can join the game at any time. To leave a game, use /leave. If a "
|
||||||
"player takes more than 90 seconds to play, you can use /skip to skip that "
|
"player takes more than 90 seconds to play, you can use /skip to skip that "
|
||||||
"player.\n"
|
"player. "
|
||||||
|
"Use /notify_me to receive a private message when a new game is started.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"<b>Language</b> and other settings: /settings\n"
|
"<b>Language</b> and other settings: /settings\n"
|
||||||
"Other commands (only game creator):\n"
|
"Other commands (only game creator):\n"
|
||||||
@ -74,6 +76,14 @@ msgstr ""
|
|||||||
msgid "Created a new game! Join the game with /join and start the game with /start"
|
msgid "Created a new game! Join the game with /join and start the game with /start"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: bot.py
|
||||||
|
msgid "Send this command in a group to be notified when a new game is started there."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: bot.py
|
||||||
|
msgid "A new game has been started in {title}"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#: bot.py:152
|
#: bot.py:152
|
||||||
msgid "The lobby is closed"
|
msgid "The lobby is closed"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
@ -184,14 +194,19 @@ msgstr ""
|
|||||||
|
|
||||||
#: bot.py:400
|
#: bot.py:400
|
||||||
#, python-format
|
#, python-format
|
||||||
msgid "Please wait {time} seconds"
|
msgid "Please wait {time} second"
|
||||||
msgstr ""
|
msgid_plural "Please wait {time} seconds"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
#: bot.py:413
|
#: bot.py:413
|
||||||
#, python-format
|
#, python-format
|
||||||
msgid "Waiting time to skip this player has been reduced to {time} seconds.\n"
|
msgid "Waiting time to skip this player has been reduced to {time} second.\n"
|
||||||
"Next player: {name}"
|
"Next player: {name}"
|
||||||
msgstr ""
|
msgid_plural "Waiting time to skip this player has been reduced to {time} seconds.\n"
|
||||||
|
"Next player: {name}"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
#: bot.py:424
|
#: bot.py:424
|
||||||
#, python-format
|
#, python-format
|
||||||
@ -256,8 +271,10 @@ msgid "Choose Color"
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: results.py:56
|
#: results.py:56
|
||||||
msgid "Cards (tap for game state):"
|
msgid "Last card (tap for game state):"
|
||||||
msgstr ""
|
msgid_plural "Cards (tap for game state):"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
#: results.py:60 results.py:123 results.py:165
|
#: results.py:60 results.py:123 results.py:165
|
||||||
msgid "Current player: {name}"
|
msgid "Current player: {name}"
|
||||||
@ -268,13 +285,17 @@ msgid "Last card: {card}"
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: results.py:62 results.py:125 results.py:168
|
#: results.py:62 results.py:125 results.py:168
|
||||||
msgid "Players: {player_list}"
|
msgid "Player: {player_list}"
|
||||||
msgstr ""
|
msgid_plural "Players: {player_list}"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
#: results.py:72
|
#: results.py:72
|
||||||
#, python-format
|
#, python-format
|
||||||
msgid "{name} ({number} cards)"
|
msgid "{name} ({number} card)"
|
||||||
msgstr ""
|
msgid_plural "{name} ({number} cards)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
#: results.py:81
|
#: results.py:81
|
||||||
msgid "You are not playing"
|
msgid "You are not playing"
|
||||||
@ -295,11 +316,10 @@ msgstr ""
|
|||||||
|
|
||||||
#: results.py:108
|
#: results.py:108
|
||||||
#, python-format
|
#, python-format
|
||||||
msgid "Drawing 1 card"
|
msgid "Drawing {number} card"
|
||||||
msgstr ""
|
msgid_plural "Drawing {number} cards"
|
||||||
|
msgstr[0] ""
|
||||||
msgid "Drawing {number} cards"
|
msgstr[1] ""
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: results.py:136
|
#: results.py:136
|
||||||
msgid "Pass"
|
msgid "Pass"
|
||||||
@ -352,16 +372,22 @@ msgid "You did not enable statistics. Use /settings in "
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: simple_commands.py
|
#: simple_commands.py
|
||||||
msgid "{number} games played"
|
msgid "{number} game played"
|
||||||
msgstr ""
|
msgid_plural "{number} games played"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
#: simple_commands.py
|
#: simple_commands.py
|
||||||
msgid "{number} first places"
|
msgid "{number} first place"
|
||||||
msgstr ""
|
msgid_plural "{number} first places"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
#: simple_commands.py
|
#: simple_commands.py
|
||||||
msgid "{number} cards played"
|
msgid "{number} card played"
|
||||||
msgstr ""
|
msgid_plural "{number} cards played"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
|
||||||
#: utils.py
|
#: utils.py
|
||||||
@ -379,4 +405,3 @@ msgstr ""
|
|||||||
#: utils.py
|
#: utils.py
|
||||||
msgid "{emoji} Yellow"
|
msgid "{emoji} Yellow"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
python-telegram-bot==5
|
||||||
|
pony
|
55
results.py
55
results.py
@ -26,8 +26,8 @@ from telegram import InlineQueryResultArticle, InputTextMessageContent, \
|
|||||||
InlineQueryResultCachedSticker as Sticker
|
InlineQueryResultCachedSticker as Sticker
|
||||||
|
|
||||||
import card as c
|
import card as c
|
||||||
from utils import display_color, display_color_group, display_name, \
|
from utils import display_color, display_color_group, display_name
|
||||||
list_subtract, _, __
|
from internationalization import _, __
|
||||||
|
|
||||||
|
|
||||||
def add_choose_color(results, game):
|
def add_choose_color(results, game):
|
||||||
@ -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))
|
||||||
@ -44,17 +44,16 @@ def add_choose_color(results, game):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def add_other_cards(playable, player, results, game):
|
def add_other_cards(player, results, game):
|
||||||
"""Add hand cards when choosing colors"""
|
"""Add hand cards when choosing colors"""
|
||||||
if not playable:
|
|
||||||
playable = list()
|
|
||||||
|
|
||||||
results.append(
|
results.append(
|
||||||
InlineQueryResultArticle(
|
InlineQueryResultArticle(
|
||||||
"hand",
|
"hand",
|
||||||
title=_("Cards (tap for game state):"),
|
title=_("你的手牌(點一下以獲得遊戲狀態):",
|
||||||
description=', '.join([repr(card) for card in
|
"你的手牌(點一下以獲得遊戲狀態):",
|
||||||
list_subtract(player.cards, playable)]),
|
len(player.cards)),
|
||||||
|
description=', '.join([repr(card) for card in player.cards]),
|
||||||
input_message_content=game_info(game)
|
input_message_content=game_info(game)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -62,7 +61,9 @@ def add_other_cards(playable, player, results, game):
|
|||||||
|
|
||||||
def player_list(game):
|
def player_list(game):
|
||||||
"""Generate list of player strings"""
|
"""Generate list of player strings"""
|
||||||
return [_("{name} ({number} cards)")
|
return [_("{name}(有 {number} 張牌)",
|
||||||
|
"{name}(有 {number} 張牌)",
|
||||||
|
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]
|
||||||
|
|
||||||
@ -72,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 開始新的遊戲或使用 /join 加入目前的遊戲'))
|
||||||
'start a game or /join to join the '
|
|
||||||
'current game in this group'))
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -86,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 開始遊戲'))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -101,10 +100,9 @@ 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 1 card', player.game.translate)
|
InputTextMessageContent(__('抽 {number} 張牌',
|
||||||
if n == 1 else
|
'抽 {number} 張牌', n,
|
||||||
__('Drawing {number} cards',
|
multi=player.game.translate)
|
||||||
player.game.translate)
|
|
||||||
.format(number=n))
|
.format(number=n))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -127,8 +125,9 @@ def add_pass(results, game):
|
|||||||
results.append(
|
results.append(
|
||||||
Sticker(
|
Sticker(
|
||||||
"pass", sticker_file_id=c.STICKERS['option_pass'],
|
"pass", sticker_file_id=c.STICKERS['option_pass'],
|
||||||
input_message_content=InputTextMessageContent(__('Pass',
|
input_message_content=InputTextMessageContent(
|
||||||
game.translate))
|
__('Pass!下一位', multi=game.translate)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -140,8 +139,8 @@ 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(__("你作弊,一定還有其他牌可以出!",
|
||||||
game.translate))
|
multi=game.translate))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -163,11 +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" +
|
||||||
_("Players: {player_list}")
|
_("玩家列表:{player_list}",
|
||||||
|
"玩家列表:{player_list}",
|
||||||
|
len(players))
|
||||||
.format(player_list=" -> ".join(players))
|
.format(player_list=" -> ".join(players))
|
||||||
)
|
)
|
48
settings.py
48
settings.py
@ -18,17 +18,14 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from telegram import ReplyKeyboardMarkup, Emoji
|
from telegram import ReplyKeyboardMarkup, Emoji
|
||||||
from telegram.ext import CommandHandler, RegexHandler
|
from telegram.ext import CommandHandler, RegexHandler
|
||||||
|
|
||||||
from utils import send_async
|
from utils import send_async
|
||||||
from user_setting import UserSetting
|
from user_setting import UserSetting
|
||||||
from utils import _, user_locale
|
|
||||||
from shared_vars import dispatcher
|
from shared_vars import dispatcher
|
||||||
|
from locales import available_locales
|
||||||
available_locales = [['en_US', 'de_DE']]
|
from internationalization import _, user_locale
|
||||||
|
|
||||||
|
|
||||||
@user_locale
|
@user_locale
|
||||||
@ -37,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)
|
||||||
@ -47,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))
|
||||||
|
|
||||||
@ -66,11 +62,14 @@ 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:
|
||||||
send_async(bot, chat.id, text=_("Select locale"),
|
kb = [[locale + ' - ' + descr]
|
||||||
reply_markup=ReplyKeyboardMarkup(keyboard=available_locales,
|
for locale, descr
|
||||||
|
in sorted(available_locales.items())]
|
||||||
|
send_async(bot, chat.id, text=_("選擇語言"),
|
||||||
|
reply_markup=ReplyKeyboardMarkup(keyboard=kb,
|
||||||
one_time_keyboard=True))
|
one_time_keyboard=True))
|
||||||
|
|
||||||
elif option == Emoji.CROSS_MARK:
|
elif option == Emoji.CROSS_MARK:
|
||||||
@ -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
|
||||||
@ -88,18 +87,19 @@ def locale_select(bot, update, groups):
|
|||||||
user = update.message.from_user
|
user = update.message.from_user
|
||||||
option = groups[0]
|
option = groups[0]
|
||||||
|
|
||||||
if option in [locale for row in available_locales for locale in row]:
|
if option in available_locales:
|
||||||
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()
|
||||||
|
|
||||||
|
|
||||||
dispatcher.add_handler(CommandHandler('settings', show_settings))
|
def register():
|
||||||
dispatcher.add_handler(RegexHandler('^([' + Emoji.BAR_CHART +
|
dispatcher.add_handler(CommandHandler('settings', show_settings))
|
||||||
Emoji.EARTH_GLOBE_EUROPE_AFRICA +
|
dispatcher.add_handler(RegexHandler('^([' + Emoji.BAR_CHART +
|
||||||
Emoji.CROSS_MARK + ']) .+$',
|
Emoji.EARTH_GLOBE_EUROPE_AFRICA +
|
||||||
kb_select, pass_groups=True))
|
Emoji.CROSS_MARK + ']) .+$',
|
||||||
dispatcher.add_handler(RegexHandler(r'^(\w\w_\w\w)$',
|
kb_select, pass_groups=True))
|
||||||
locale_select, pass_groups=True))
|
dispatcher.add_handler(RegexHandler(r'^(\w\w_\w\w) - .*',
|
||||||
|
locale_select, pass_groups=True))
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
|
|
||||||
from telegram.ext import Updater
|
from telegram.ext import Updater
|
||||||
from telegram.utils.botan import Botan
|
from telegram.contrib.botan import Botan
|
||||||
|
|
||||||
from game_manager import GameManager
|
from game_manager import GameManager
|
||||||
from database import db
|
from database import db
|
||||||
|
@ -21,44 +21,41 @@ from telegram import ParseMode
|
|||||||
from telegram.ext import CommandHandler
|
from telegram.ext import CommandHandler
|
||||||
|
|
||||||
from user_setting import UserSetting
|
from user_setting import UserSetting
|
||||||
from utils import _, send_async, user_locale
|
from utils import send_async
|
||||||
from shared_vars import dispatcher
|
from shared_vars import dispatcher
|
||||||
|
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>@unopl_bot</code> 然後按<b>空白鍵</b>或點一下 "
|
||||||
" /start\n"
|
"<code>via @unopl_bot</code> 或 <code>透過 @unopl_bot</code>,你便會看見你手上的牌或者是其他選項,例如:抽牌和"
|
||||||
"4. Type <code>@mau_mau_bot</code> into your chat box and hit "
|
"<b>?</b>(查看遊戲狀態)。然而<b>灰色的牌</b>就是<b>你現在不能使用的牌</b>,選擇其中一個"
|
||||||
"<b>space</b>, or click the <code>via @mau_mau_bot</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.\n\n"
|
"<b>提醒:</b> 因為一些原因,您無法同時在不同的群組中遊玩。\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"
|
||||||
|
'Draw icon by '
|
||||||
|
'<a href="http://www.faithtoken.com/">Faithtoken</a>\n'
|
||||||
|
'Pass icon by '
|
||||||
|
'<a href="http://delapouite.com/">Delapouite</a>\n'
|
||||||
|
"Originals available on http://game-icons.net\n"
|
||||||
|
"Icons edited by ɳick")
|
||||||
|
|
||||||
|
|
||||||
@user_locale
|
@user_locale
|
||||||
@ -71,7 +68,8 @@ def help(bot, update):
|
|||||||
@user_locale
|
@user_locale
|
||||||
def source(bot, update):
|
def source(bot, update):
|
||||||
"""Handler for the /help command"""
|
"""Handler for the /help command"""
|
||||||
send_async(bot, update.message.chat_id, text=_(source_text),
|
send_async(bot, update.message.chat_id, text=_(source_text) + '\n' +
|
||||||
|
_(attributions),
|
||||||
parse_mode=ParseMode.HTML, disable_web_page_preview=True)
|
parse_mode=ParseMode.HTML, disable_web_page_preview=True)
|
||||||
|
|
||||||
|
|
||||||
@ -89,22 +87,38 @@ 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> 來啟用他", parse_mode=ParseMode.HTML))
|
||||||
else:
|
else:
|
||||||
stats_text = list()
|
stats_text = list()
|
||||||
|
|
||||||
|
n = us.games_played
|
||||||
stats_text.append(
|
stats_text.append(
|
||||||
_("{number} games played").format(number=us.games_played))
|
_("已遊玩 {number} 個遊戲",
|
||||||
|
"已遊玩 {number} 個遊戲",
|
||||||
|
n).format(number=n)
|
||||||
|
)
|
||||||
|
|
||||||
|
n = us.first_places
|
||||||
stats_text.append(
|
stats_text.append(
|
||||||
_("{number} first places").format(number=us.first_places))
|
_("拿了 {number} 次第一名",
|
||||||
|
"拿了 {number} 次第一名",
|
||||||
|
n).format(number=n)
|
||||||
|
)
|
||||||
|
|
||||||
|
n = us.cards_played
|
||||||
stats_text.append(
|
stats_text.append(
|
||||||
_("{number} cards played").format(number=us.cards_played))
|
_("已遊玩 {number} 張牌",
|
||||||
|
"已遊玩 {number} 張牌",
|
||||||
|
n).format(number=n)
|
||||||
|
)
|
||||||
|
|
||||||
send_async(bot, update.message.chat_id,
|
send_async(bot, update.message.chat_id,
|
||||||
text='\n'.join(stats_text))
|
text='\n'.join(stats_text))
|
||||||
|
|
||||||
|
|
||||||
dispatcher.add_handler(CommandHandler('help', help))
|
def register():
|
||||||
dispatcher.add_handler(CommandHandler('source', source))
|
dispatcher.add_handler(CommandHandler('help', help))
|
||||||
dispatcher.add_handler(CommandHandler('news', news))
|
dispatcher.add_handler(CommandHandler('source', source))
|
||||||
dispatcher.add_handler(CommandHandler('stats', stats))
|
# dispatcher.add_handler(CommandHandler('news', news))
|
||||||
|
dispatcher.add_handler(CommandHandler('stats', stats))
|
||||||
|
@ -138,6 +138,7 @@ class Test(unittest.TestCase):
|
|||||||
|
|
||||||
def test_bluffing(self):
|
def test_bluffing(self):
|
||||||
p = Player(self.game, "Player 0")
|
p = Player(self.game, "Player 0")
|
||||||
|
Player(self.game, "Player 01")
|
||||||
|
|
||||||
self.game.last_card = c.Card(c.RED, '1')
|
self.game.last_card = c.Card(c.RED, '1')
|
||||||
|
|
||||||
@ -156,4 +157,8 @@ class Test(unittest.TestCase):
|
|||||||
c.Card(None, None, c.CHOOSE)]
|
c.Card(None, None, c.CHOOSE)]
|
||||||
|
|
||||||
p.playable_cards()
|
p.playable_cards()
|
||||||
self.assertFalse(p.bluffing)
|
|
||||||
|
p.play(c.Card(None, None, c.DRAW_FOUR))
|
||||||
|
self.game.choose_color(c.GREEN)
|
||||||
|
|
||||||
|
self.assertFalse(self.game.current_player.prev.bluffing)
|
||||||
|
@ -24,7 +24,7 @@ from database import db, Optional, Required, PrimaryKey, db_session
|
|||||||
class UserSetting(db.Entity):
|
class UserSetting(db.Entity):
|
||||||
|
|
||||||
id = PrimaryKey(int, auto=False, size=64) # Telegram User ID
|
id = PrimaryKey(int, auto=False, size=64) # Telegram User ID
|
||||||
lang = Optional(str, default='en') # The language setting for this user
|
lang = Optional(str, default='') # The language setting for this user
|
||||||
stats = Optional(bool, default=False) # Opt-in to keep game statistics
|
stats = Optional(bool, default=False) # Opt-in to keep game statistics
|
||||||
first_places = Optional(int, default=0) # Nr. of games won in first place
|
first_places = Optional(int, default=0) # Nr. of games won in first place
|
||||||
games_played = Optional(int, default=0) # Nr. of games completed
|
games_played = Optional(int, default=0) # Nr. of games completed
|
||||||
|
127
utils.py
127
utils.py
@ -19,52 +19,17 @@
|
|||||||
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from functools import wraps
|
|
||||||
|
|
||||||
from flufl.i18n import registry
|
|
||||||
from flufl.i18n import PackageStrategy
|
|
||||||
|
|
||||||
from telegram import Emoji
|
from telegram import Emoji
|
||||||
from telegram.ext.dispatcher import run_async
|
from telegram.ext.dispatcher import run_async
|
||||||
import locales
|
|
||||||
from database import db_session
|
|
||||||
from user_setting import UserSetting
|
|
||||||
from shared_vars import gm
|
|
||||||
|
|
||||||
strategy = PackageStrategy('unobot', locales)
|
from internationalization import _, __
|
||||||
application = registry.register(strategy)
|
|
||||||
_ = application._
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
TIMEOUT = 2.5
|
TIMEOUT = 2.5
|
||||||
|
|
||||||
|
|
||||||
def __(string, multi_translate):
|
|
||||||
"""Translates text into all locales on the stack"""
|
|
||||||
translations = list()
|
|
||||||
locales = list()
|
|
||||||
|
|
||||||
if not multi_translate:
|
|
||||||
_.push('en_US')
|
|
||||||
translations.append(_(string))
|
|
||||||
_.pop()
|
|
||||||
|
|
||||||
else:
|
|
||||||
while _.code:
|
|
||||||
translation = _(string)
|
|
||||||
|
|
||||||
if translation not in translations:
|
|
||||||
translations.append(translation)
|
|
||||||
|
|
||||||
locales.append(_.code)
|
|
||||||
_.pop()
|
|
||||||
|
|
||||||
for l in reversed(locales):
|
|
||||||
_.push(l)
|
|
||||||
|
|
||||||
return '\n'.join(translations)
|
|
||||||
|
|
||||||
|
|
||||||
def list_subtract(list1, list2):
|
def list_subtract(list1, list2):
|
||||||
""" Helper function to subtract two lists and return the sorted result """
|
""" Helper function to subtract two lists and return the sorted result """
|
||||||
list1 = list1.copy()
|
list1 = list1.copy()
|
||||||
@ -86,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)
|
||||||
|
|
||||||
|
|
||||||
@ -138,75 +103,3 @@ def answer_async(bot, *args, **kwargs):
|
|||||||
bot.answerInlineQuery(*args, **kwargs)
|
bot.answerInlineQuery(*args, **kwargs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error(None, None, e)
|
error(None, None, e)
|
||||||
|
|
||||||
|
|
||||||
def user_locale(func):
|
|
||||||
@wraps(func)
|
|
||||||
@db_session
|
|
||||||
def wrapped(bot, update, *pargs, **kwargs):
|
|
||||||
user, chat = _user_chat_from_update(update)
|
|
||||||
|
|
||||||
with db_session:
|
|
||||||
us = UserSetting.get(id=user.id)
|
|
||||||
|
|
||||||
if us:
|
|
||||||
_.push(us.lang)
|
|
||||||
else:
|
|
||||||
_.push('en_US')
|
|
||||||
|
|
||||||
result = func(bot, update, *pargs, **kwargs)
|
|
||||||
_.pop()
|
|
||||||
return result
|
|
||||||
return wrapped
|
|
||||||
|
|
||||||
|
|
||||||
def game_locales(func):
|
|
||||||
@wraps(func)
|
|
||||||
@db_session
|
|
||||||
def wrapped(bot, update, *pargs, **kwargs):
|
|
||||||
user, chat = _user_chat_from_update(update)
|
|
||||||
player = gm.player_for_user_in_chat(user, chat)
|
|
||||||
locales = list()
|
|
||||||
|
|
||||||
if player:
|
|
||||||
for player in player.game.players:
|
|
||||||
us = UserSetting.get(id=player.user.id)
|
|
||||||
|
|
||||||
if us:
|
|
||||||
loc = us.lang
|
|
||||||
else:
|
|
||||||
loc = 'en_US'
|
|
||||||
|
|
||||||
if loc in locales:
|
|
||||||
continue
|
|
||||||
|
|
||||||
_.push(loc)
|
|
||||||
locales.append(loc)
|
|
||||||
|
|
||||||
result = func(bot, update, *pargs, **kwargs)
|
|
||||||
|
|
||||||
for i in locales:
|
|
||||||
_.pop()
|
|
||||||
return result
|
|
||||||
return wrapped
|
|
||||||
|
|
||||||
|
|
||||||
def _user_chat_from_update(update):
|
|
||||||
|
|
||||||
try:
|
|
||||||
user = update.message.from_user
|
|
||||||
chat = update.message.chat
|
|
||||||
except (NameError, AttributeError):
|
|
||||||
try:
|
|
||||||
user = update.inline_query.from_user
|
|
||||||
chat = gm.userid_current[user.id].game.chat
|
|
||||||
except KeyError:
|
|
||||||
chat = None
|
|
||||||
except (NameError, AttributeError):
|
|
||||||
try:
|
|
||||||
user = update.chosen_inline_result.from_user
|
|
||||||
chat = gm.userid_current[user.id].game.chat
|
|
||||||
except (NameError, AttributeError):
|
|
||||||
chat = None
|
|
||||||
|
|
||||||
return user, chat
|
|
||||||
|
Reference in New Issue
Block a user