#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # Telegram bot to play UNO in group chats # Copyright (c) 2016 Jannes Höke # # 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 . 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. 輸入 @unopl_bot 然後按空白鍵或點一下 " "via @unopl_bot透過 @unopl_bot,你便會看見你手上的牌或者是其他選項,例如:抽牌和" "?(查看遊戲狀態)。然而灰色的牌就是你現在不能使用的牌,選擇其中一個" "選項來執行對應的操作。\n" "玩家可以在任何時間加入,如果想離開,請打 /leave 。如果玩家90秒後都沒有出牌" ",你可以用 /skip 跳過他。輸入 /notify_me 以讓我在本群組遊戲開始時私訊你\n" "\n" "語言和其他設定: /settings\n" "遊戲創始人可以用以下的指令:\n" "/close - 令其他人不可以中途加入\n" "/open - 令其他人可以中途加入\n" "提醒: 因為一些原因,您無法同時在不同的群組中遊玩。\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 ' 'Faithtoken\n' 'Pass icon by ' 'Delapouite\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=_("您尚未啟用統計資料,請私我 " "/settings 來啟用他", 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))