forked from test/mau_mau_bot
87 lines
2.3 KiB
Python
87 lines
2.3 KiB
Python
#!/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 logging
|
|
|
|
from flufl.i18n import registry
|
|
from flufl.i18n import PackageStrategy
|
|
|
|
from telegram import Emoji
|
|
import locales
|
|
|
|
strategy = PackageStrategy('unobot', locales)
|
|
application = registry.register(strategy)
|
|
_ = application._
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def __(string):
|
|
"""Translates text into all locales on the stack"""
|
|
translations = list()
|
|
locales = list()
|
|
|
|
while True:
|
|
translation = _(string)
|
|
|
|
if translation not in translations:
|
|
translations.append(translation)
|
|
|
|
l = _.code
|
|
_.pop()
|
|
|
|
if l is None:
|
|
break
|
|
else:
|
|
locales.append(l)
|
|
|
|
for l in reversed(locales):
|
|
_.push(l)
|
|
|
|
return '\n'.join(translations) # TODO
|
|
|
|
|
|
def list_subtract(list1, list2):
|
|
""" Helper function to subtract two lists and return the sorted result """
|
|
list1 = list1.copy()
|
|
|
|
for x in list2:
|
|
list1.remove(x)
|
|
|
|
return list(sorted(list1))
|
|
|
|
|
|
def display_name(user):
|
|
""" Get the current players name including their username, if possible """
|
|
user_name = user.first_name
|
|
if user.username:
|
|
user_name += ' (@' + user.username + ')'
|
|
return user_name
|
|
|
|
|
|
def display_color(color):
|
|
""" Convert a color code to actual color name """
|
|
if color == "r":
|
|
return Emoji.HEAVY_BLACK_HEART + " Red"
|
|
if color == "b":
|
|
return Emoji.BLUE_HEART + " Blue"
|
|
if color == "g":
|
|
return Emoji.GREEN_HEART + " Green"
|
|
if color == "y":
|
|
return Emoji.YELLOW_HEART + " Yellow"
|