示例#1
0
def new_game(bot, update):
    """Handler for the /new command"""
    chat_id = update.message.chat_id

    if update.message.chat.type == 'private':
        help(bot, update)

    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=_("A new game has been started in {title}").format(
                        title=update.message.chat.title))

            del gm.remind_dict[update.message.chat_id]

        game = gm.new_game(update.message.chat)
        game.owner = update.message.from_user
        send_async(bot,
                   chat_id,
                   text=_("Created a new game! Join the game with /join "
                          "and start the game with /start"))

        if botan:
            botan.track(update.message, 'New games')
示例#2
0
文件: bot.py 项目: bay122/mau_mau_bot
def new_game(bot, update):
    """Handler for the /new command"""
    chat_id = update.message.chat_id

    if update.message.chat.type == 'private':
        help(bot, update)

    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=_("A new game has been started in {title}").format(
                                title=update.message.chat.title))

            del gm.remind_dict[update.message.chat_id]

        game = gm.new_game(update.message.chat)
        game.owner = update.message.from_user
        send_async(bot, chat_id,
                   text=_("Created a new game! Join the game with /join "
                          "and start the game with /start"))

        if botan:
            botan.track(update.message, 'New games')
示例#3
0
def do_play_card(bot, player, result_id):
    """Plays the selected card and sends an update to the group if needed"""
    card = c.from_str(result_id)
    player.play(card)
    game = player.game
    chat = game.chat
    user = player.user

    us = UserSetting.get(id=user.id)
    if not us:
        us = UserSetting(id=user.id)

    if us.stats:
        us.cards_played += 1

    if game.choosing_color:
        send_async(bot, chat.id, text=_("Please choose a color"))

    if len(player.cards) == 1:
        send_async(bot, chat.id, text="UNO!")

    if len(player.cards) == 0:
        send_async(bot,
                   chat.id,
                   text=__("{name} won!",
                           multi=game.translate).format(name=user.first_name))

        if us.stats:
            us.games_played += 1

            if game.players_won is 0:
                us.first_places += 1

        game.players_won += 1

        try:
            gm.leave_game(user, chat)
        except NotEnoughPlayersError:
            send_async(bot,
                       chat.id,
                       text=__("Game ended!", multi=game.translate))

            us2 = UserSetting.get(id=game.current_player.user.id)
            if us2 and us2.stats:
                us2.games_played += 1

            gm.end_game(chat, user)

    if botan:
        random_int = random.randrange(1, 999999999)
        botan.track(
            Message(random_int, user, datetime.now(), Chat(chat.id, 'group')),
            'Played cards')
示例#4
0
文件: bot.py 项目: bay122/mau_mau_bot
def do_play_card(bot, player, result_id):
    """Plays the selected card and sends an update to the group if needed"""
    card = c.from_str(result_id)
    player.play(card)
    game = player.game
    chat = game.chat
    user = player.user

    us = UserSetting.get(id=user.id)
    if not us:
        us = UserSetting(id=user.id)

    if us.stats:
        us.cards_played += 1

    if game.choosing_color:
        send_async(bot, chat.id, text=_("Please choose a color"))

    if len(player.cards) == 1:
        send_async(bot, chat.id, text="UNO!")

    if len(player.cards) == 0:
        send_async(bot, chat.id,
                   text=__("{name} won!", multi=game.translate)
                   .format(name=user.first_name))

        if us.stats:
            us.games_played += 1

            if game.players_won is 0:
                us.first_places += 1

        game.players_won += 1

        try:
            gm.leave_game(user, chat)
        except NotEnoughPlayersError:
            send_async(bot, chat.id,
                       text=__("Game ended!", multi=game.translate))

            us2 = UserSetting.get(id=game.current_player.user.id)
            if us2 and us2.stats:
                us2.games_played += 1

            gm.end_game(chat, user)

    if botan:
        botan.track(Message(randint(1, 1000000000), user, datetime.now(),
                            Chat(chat.id, 'group')),
                    'Played cards')
示例#5
0
def new_game(bot, update):
    """Handler for the /new command"""
    chat_id = update.message.chat_id

    if update.message.chat.type == 'private':
        help(bot, update)

    else:
        game = gm.new_game(update.message.chat)
        game.owner = update.message.from_user
        send_async(bot, chat_id,
                   text=_("Created a new game! Join the game with /join "
                          "and start the game with /start"))

        if botan:
            botan.track(update.message, 'New games')
示例#6
0
def new_game(bot, update):
    """Handler for the /new command"""
    chat_id = update.message.chat_id

    if update.message.chat.type == 'private':
        help(bot, update)

    else:
        game = gm.new_game(update.message.chat)
        game.owner = update.message.from_user
        send_async(bot, chat_id,
                   text=_("Created a new game! Join the game with /join "
                          "and start the game with /start"))

        if botan:
            botan.track(update.message, 'New games')