This repository has been archived on 2020-04-30. You can view files and clone it, but cannot push or open issues or pull requests.
Files
mau_mau_bot/simple_commands.py
2017-08-24 01:12:45 +08:00

125 lines
5.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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 telegram import ParseMode
from telegram.ext import CommandHandler
from user_setting import UserSetting
from utils import send_async
from shared_vars import dispatcher
from internationalization import _, user_locale
help_text = ("請跟隨以下指示:\n\n"
"1. 將這個機器人新增到群組\n"
"2. 輸入 /new 開始一個新遊戲或輸入 /join 加入一個運行中的遊戲\n"
"3. 當有兩個或以上的玩家加入,就可以用 /start 開始遊戲\n"
"4. 輸入 <code>@pluno_bot</code> 然後按<b>空白鍵</b>或點一下 "
"<code>via @pluno_bot</code> 或 <code>透過 @pluno_bot</code>,你便會看見你手上的牌或者是其他選項,例如:抽牌和"
"<b>?</b>(查看遊戲狀態)。然而<b>灰色的牌</b>就是<b>你現在不能使用的牌</b>,選擇其中一個"
"選項來執行對應的操作。\n"
"玩家可以在任何時間加入,如果想離開,請打 /leave 。如果玩家90秒後都沒有出牌"
",你可以用 /skip 跳過他。輸入 /notify_me 以讓我在本群組遊戲開始時私訊你\n"
"\n"
"<b>語言</b>和其他設定: /settings\n"
"遊戲創始人可以用以下的指令:\n"
"/close - 令其他人不可以中途加入\n"
"/open - 令其他人可以中途加入\n"
"<b>提醒:</b> 因為一些原因,您無法同時在不同的群組中遊玩。\n"
"如果你喜歡這個 bot你可以選擇買一副 UNO 牌來支持 UNO")
source_text = ("這個 bot 是一個免費的軟體,根據 AGPL 授權 \n"
"原始碼可以在這裡找到:\n"
"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
def help(bot, update):
"""Handler for the /help command"""
send_async(bot, update.message.chat_id, text=_(help_text),
parse_mode=ParseMode.HTML, disable_web_page_preview=True)
@user_locale
def source(bot, update):
"""Handler for the /help command"""
send_async(bot, update.message.chat_id, text=_(source_text) + '\n' +
_(attributions),
parse_mode=ParseMode.HTML, disable_web_page_preview=True)
@user_locale
def news(bot, update):
"""Handler for the /news command"""
send_async(bot, update.message.chat_id,
text=_("All news here: https://telegram.me/unobotupdates"),
disable_web_page_preview=True)
@user_locale
def stats(bot, update):
user = update.message.from_user
us = UserSetting.get(id=user.id)
if not us or not us.stats:
send_async(bot, update.message.chat_id,
text=_("您尚未啟用統計資料,請私我 "
"<code>/settings</code> 來啟用他", parse_mode=ParseMode.HTML))
else:
stats_text = list()
n = us.games_played
stats_text.append(
_("已遊玩 {number} 個遊戲",
"已遊玩 {number} 個遊戲",
n).format(number=n)
)
n = us.first_places
stats_text.append(
_("拿了 {number} 次第一名",
"拿了 {number} 次第一名",
n).format(number=n)
)
n = us.cards_played
stats_text.append(
_("已遊玩 {number} 張牌",
"已遊玩 {number} 張牌",
n).format(number=n)
)
send_async(bot, update.message.chat_id,
text='\n'.join(stats_text))
def register():
dispatcher.add_handler(CommandHandler('help', help))
dispatcher.add_handler(CommandHandler('source', source))
# dispatcher.add_handler(CommandHandler('news', news))
dispatcher.add_handler(CommandHandler('stats', stats))