forked from test/mau_mau_bot
final version?
This commit is contained in:
parent
4cdffffa5f
commit
ba47f4c19e
8 changed files with 142 additions and 9 deletions
21
bot.py
21
bot.py
|
@ -32,6 +32,7 @@ from start_bot import start_bot
|
||||||
from results import (add_call_bluff, add_choose_color, add_draw, add_gameinfo,
|
from results import (add_call_bluff, add_choose_color, add_draw, add_gameinfo,
|
||||||
add_no_game, add_not_started, add_other_cards, add_pass,
|
add_no_game, add_not_started, add_other_cards, add_pass,
|
||||||
add_card)
|
add_card)
|
||||||
|
from user_setting import UserSetting
|
||||||
from utils import display_name
|
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,
|
||||||
|
@ -474,7 +475,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)
|
add_choose_color(results, game)
|
||||||
add_other_cards(playable, player, results, game)
|
add_other_cards(playable, player, results, game)
|
||||||
else:
|
else:
|
||||||
if not player.drew:
|
if not player.drew:
|
||||||
|
@ -583,6 +584,12 @@ def do_play_card(bot, player, result_id):
|
||||||
chat = game.chat
|
chat = game.chat
|
||||||
user = player.user
|
user = player.user
|
||||||
|
|
||||||
|
us = UserSetting.get(id=user.id)
|
||||||
|
if not us:
|
||||||
|
us = UserSetting(id=user.id)
|
||||||
|
|
||||||
|
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=_("Please choose a color"))
|
||||||
|
|
||||||
|
@ -593,10 +600,22 @@ def do_play_card(bot, player, result_id):
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=__("{name} won!", game.translate)
|
text=__("{name} won!", game.translate)
|
||||||
.format(name=user.first_name))
|
.format(name=user.first_name))
|
||||||
|
|
||||||
|
if us.stats:
|
||||||
|
us.games_played += 1
|
||||||
|
|
||||||
|
if game.players_won is 0:
|
||||||
|
us.first_places += 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=__("Game ended!", game.translate))
|
||||||
|
|
||||||
|
us2 = UserSetting.get(id=game.current_player.next.user.id)
|
||||||
|
if us2 and us2.stats:
|
||||||
|
us2.games_played += 1
|
||||||
|
|
||||||
gm.end_game(chat, user)
|
gm.end_game(chat, user)
|
||||||
|
|
||||||
if botan:
|
if botan:
|
||||||
|
|
1
game.py
1
game.py
|
@ -35,6 +35,7 @@ class Game(object):
|
||||||
owner = None
|
owner = None
|
||||||
open = True
|
open = True
|
||||||
translate = False
|
translate = False
|
||||||
|
players_won = 0
|
||||||
|
|
||||||
def __init__(self, chat):
|
def __init__(self, chat):
|
||||||
self.chat = chat
|
self.chat = chat
|
||||||
|
|
|
@ -403,3 +403,40 @@ msgstr "Alle Statistiken gelöscht und deaktiviert!"
|
||||||
#: settings.py:94
|
#: settings.py:94
|
||||||
msgid "Set locale!"
|
msgid "Set locale!"
|
||||||
msgstr "Sprache gesetzt!"
|
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"
|
||||||
|
|
||||||
|
|
|
@ -345,3 +345,38 @@ msgstr ""
|
||||||
msgid "Set locale!"
|
msgid "Set locale!"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|
||||||
|
#: simple_commands.py
|
||||||
|
msgid "You did not enable statistics. Use /settings in "
|
||||||
|
"a private chat with the bot to enable them."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: simple_commands.py
|
||||||
|
msgid "{number} games played"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: simple_commands.py
|
||||||
|
msgid "{number} first places"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: simple_commands.py
|
||||||
|
msgid "{number} cards played"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
|
||||||
|
#: utils.py
|
||||||
|
msgid "{emoji} Green"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: utils.py
|
||||||
|
msgid "{emoji} Red"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: utils.py
|
||||||
|
msgid "{emoji} Blue"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: utils.py
|
||||||
|
msgid "{emoji} Yellow"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
|
|
@ -26,10 +26,11 @@ 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_name, list_subtract, _, __
|
from utils import display_color, display_color_group, display_name, \
|
||||||
|
list_subtract, _, __
|
||||||
|
|
||||||
|
|
||||||
def add_choose_color(results):
|
def add_choose_color(results, game):
|
||||||
"""Add choose color options"""
|
"""Add choose color options"""
|
||||||
for color in c.COLORS:
|
for color in c.COLORS:
|
||||||
results.append(
|
results.append(
|
||||||
|
@ -38,7 +39,7 @@ def add_choose_color(results):
|
||||||
title=_("Choose Color"),
|
title=_("Choose Color"),
|
||||||
description=display_color(color),
|
description=display_color(color),
|
||||||
input_message_content=
|
input_message_content=
|
||||||
InputTextMessageContent(display_color(color))
|
InputTextMessageContent(display_color_group(color, game))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ from shared_vars import dispatcher
|
||||||
|
|
||||||
available_locales = [['en_US', 'de_DE']]
|
available_locales = [['en_US', 'de_DE']]
|
||||||
|
|
||||||
|
|
||||||
@user_locale
|
@user_locale
|
||||||
def show_settings(bot, update):
|
def show_settings(bot, update):
|
||||||
chat = update.message.chat
|
chat = update.message.chat
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
from telegram import ParseMode
|
from telegram import ParseMode
|
||||||
from telegram.ext import CommandHandler
|
from telegram.ext import CommandHandler
|
||||||
|
|
||||||
|
from user_setting import UserSetting
|
||||||
from utils import _, send_async, user_locale
|
from utils import _, send_async, user_locale
|
||||||
from shared_vars import dispatcher
|
from shared_vars import dispatcher
|
||||||
|
|
||||||
|
@ -82,6 +83,28 @@ def news(bot, update):
|
||||||
disable_web_page_preview=True)
|
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=_("You did not enable statistics. Use /settings in "
|
||||||
|
"a private chat with the bot to enable them."))
|
||||||
|
else:
|
||||||
|
stats_text = list()
|
||||||
|
stats_text.append(
|
||||||
|
_("{number} games played").format(number=us.games_played))
|
||||||
|
stats_text.append(
|
||||||
|
_("{number} first places").format(number=us.first_places))
|
||||||
|
stats_text.append(
|
||||||
|
_("{number} cards played").format(number=us.cards_played))
|
||||||
|
|
||||||
|
send_async(bot, update.message.chat_id,
|
||||||
|
text='\n'.join(stats_text))
|
||||||
|
|
||||||
|
|
||||||
dispatcher.add_handler(CommandHandler('help', help))
|
dispatcher.add_handler(CommandHandler('help', help))
|
||||||
dispatcher.add_handler(CommandHandler('source', source))
|
dispatcher.add_handler(CommandHandler('source', source))
|
||||||
dispatcher.add_handler(CommandHandler('news', news))
|
dispatcher.add_handler(CommandHandler('news', news))
|
||||||
|
dispatcher.add_handler(CommandHandler('stats', stats))
|
||||||
|
|
26
utils.py
26
utils.py
|
@ -62,7 +62,7 @@ def __(string, multi_translate):
|
||||||
for l in reversed(locales):
|
for l in reversed(locales):
|
||||||
_.push(l)
|
_.push(l)
|
||||||
|
|
||||||
return '\n'.join(translations) # TODO
|
return '\n'.join(translations)
|
||||||
|
|
||||||
|
|
||||||
def list_subtract(list1, list2):
|
def list_subtract(list1, list2):
|
||||||
|
@ -86,13 +86,29 @@ 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.HEAVY_BLACK_HEART + " Red"
|
return _("{emoji} Red").format(emoji=Emoji.HEAVY_BLACK_HEART)
|
||||||
if color == "b":
|
if color == "b":
|
||||||
return Emoji.BLUE_HEART + " Blue"
|
return _("{emoji} Blue").format(emoji=Emoji.BLUE_HEART)
|
||||||
if color == "g":
|
if color == "g":
|
||||||
return Emoji.GREEN_HEART + " Green"
|
return _("{emoji} Green").format(emoji=Emoji.GREEN_HEART)
|
||||||
if color == "y":
|
if color == "y":
|
||||||
return Emoji.YELLOW_HEART + " Yellow"
|
return _("{emoji} Yellow").format(emoji=Emoji.YELLOW_HEART)
|
||||||
|
|
||||||
|
|
||||||
|
def display_color_group(color, game):
|
||||||
|
""" Convert a color code to actual color name """
|
||||||
|
if color == "r":
|
||||||
|
return __("{emoji} Red", game.translate).format(
|
||||||
|
emoji=Emoji.HEAVY_BLACK_HEART)
|
||||||
|
if color == "b":
|
||||||
|
return __("{emoji} Blue", game.translate).format(
|
||||||
|
emoji=Emoji.BLUE_HEART)
|
||||||
|
if color == "g":
|
||||||
|
return __("{emoji} Green", game.translate).format(
|
||||||
|
emoji=Emoji.GREEN_HEART)
|
||||||
|
if color == "y":
|
||||||
|
return __("{emoji} Yellow", game.translate).format(
|
||||||
|
emoji=Emoji.YELLOW_HEART)
|
||||||
|
|
||||||
|
|
||||||
def error(bot, update, error):
|
def error(bot, update, error):
|
||||||
|
|
Loading…
Reference in a new issue