예제 #1
0
파일: bot.py 프로젝트: LoonCode/mau_mau_bot
def do_call_bluff(bot, player):
    """Handles the bluff calling"""
    game = player.game
    chat = game.chat

    if player.prev.bluffing:
        send_async(bot, chat.id,
                   text=__("Bluff called! Giving 4 cards to {name}",
                           multi=game.translate)
                   .format(name=player.prev.user.first_name))

        try:
            player.prev.draw()
        except DeckEmptyError:
            send_async(bot, player.game.chat.id,
                       text=__("There are no more cards in the deck.",
                               multi=game.translate))

    else:
        game.draw_counter += 2
        send_async(bot, chat.id,
                   text=__("{name1} didn't bluff! Giving 6 cards to {name2}",
                           multi=game.translate)
                   .format(name1=player.prev.user.first_name,
                           name2=player.user.first_name))
        try:
            player.draw()
        except DeckEmptyError:
            send_async(bot, player.game.chat.id,
                       text=__("There are no more cards in the deck.",
                               multi=game.translate))

    game.turn()
예제 #2
0
def process_result(bot, update, job_queue):
    """
    Handler for chosen inline results.
    Checks the players actions and acts accordingly.
    """
    try:
        user = update.chosen_inline_result.from_user
        player = gm.userid_current[user.id]
        game = player.game
        result_id = update.chosen_inline_result.result_id
        chat = game.chat
    except (KeyError, AttributeError):
        return

    logger.debug("Selected result: " + result_id)

    result_id, anti_cheat = result_id.split(':')
    last_anti_cheat = player.anti_cheat
    player.anti_cheat += 1

    if result_id in ('hand', 'gameinfo', 'nogame'):
        return
    elif result_id.startswith('mode_'):
        # First 5 characters are 'mode_', the rest is the gamemode.
        mode = result_id[5:]
        game.set_mode(mode)
        logger.info("Gamemode changed to {mode}".format(mode=mode))
        send_async(bot,
                   chat.id,
                   text=__("Gamemode changed to {mode}".format(mode=mode)))
        return
    elif len(result_id) == 36:  # UUID result
        return
    elif int(anti_cheat) != last_anti_cheat:
        send_async(bot,
                   chat.id,
                   text=__("Cheat attempt by {name}",
                           multi=game.translate).format(
                               name=display_name(player.user)))
        return
    elif result_id == 'call_bluff':
        reset_waiting_time(bot, player)
        do_call_bluff(bot, player)
    elif result_id == 'draw':
        reset_waiting_time(bot, player)
        do_draw(bot, player)
    elif result_id == 'pass':
        game.turn()
    elif result_id in c.COLORS:
        game.choose_color(result_id)
    else:
        reset_waiting_time(bot, player)
        do_play_card(bot, player, result_id)

    if game_is_running(game):
        send_async(bot,
                   chat.id,
                   text=__("Next player: {name}", multi=game.translate).format(
                       name=display_name(game.current_player.user)))
        start_player_countdown(bot, game, job_queue)
예제 #3
0
파일: bot.py 프로젝트: bay122/mau_mau_bot
def leave_game(bot, update):
    """Handler for the /leave command"""
    chat = update.message.chat
    user = update.message.from_user

    player = gm.player_for_user_in_chat(user, chat)

    if player is None:
        send_async(bot, chat.id, text=_("You are not playing in a game in "
                                        "this group."),
                   reply_to_message_id=update.message.message_id)
        return

    game = player.game
    user = update.message.from_user

    try:
        gm.leave_game(user, chat)

    except NoGameInChatError:
        send_async(bot, chat.id, text=_("You are not playing in a game in "
                                        "this group."),
                   reply_to_message_id=update.message.message_id)

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

    else:
        send_async(bot, chat.id,
                   text=__("Okay. Next Player: {name}",
                           multi=game.translate).format(
                       name=display_name(game.current_player.user)),
                   reply_to_message_id=update.message.message_id)
예제 #4
0
파일: bot.py 프로젝트: bay122/mau_mau_bot
def do_call_bluff(bot, player):
    """Handles the bluff calling"""
    game = player.game
    chat = game.chat

    if player.prev.bluffing:
        send_async(bot, chat.id,
                   text=__("Bluff called! Giving 4 cards to {name}",
                           multi=game.translate)
                   .format(name=player.prev.user.first_name))

        try:
            player.prev.draw()
        except DeckEmptyError:
            send_async(bot, player.game.chat.id,
                       text=__("There are no more cards in the deck.",
                               multi=game.translate))

    else:
        game.draw_counter += 2
        send_async(bot, chat.id,
                   text=__("{name1} didn't bluff! Giving 6 cards to {name2}",
                           multi=game.translate)
                   .format(name1=player.prev.user.first_name,
                           name2=player.user.first_name))
        try:
            player.draw()
        except DeckEmptyError:
            send_async(bot, player.game.chat.id,
                       text=__("There are no more cards in the deck.",
                               multi=game.translate))

    game.turn()
예제 #5
0
파일: bot.py 프로젝트: LoonCode/mau_mau_bot
def leave_game(bot, update):
    """Handler for the /leave command"""
    chat = update.message.chat
    user = update.message.from_user

    player = gm.player_for_user_in_chat(user, chat)

    if player is None:
        send_async(bot, chat.id, text=_("You are not playing in a game in "
                                        "this group."),
                   reply_to_message_id=update.message.message_id)
        return

    game = player.game
    user = update.message.from_user

    try:
        gm.leave_game(user, chat)

    except NoGameInChatError:
        send_async(bot, chat.id, text=_("You are not playing in a game in "
                                        "this group."),
                   reply_to_message_id=update.message.message_id)

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

    else:
        send_async(bot, chat.id,
                   text=__("Okay. Next Player: {name}",
                           multi=game.translate).format(
                       name=display_name(game.current_player.user)),
                   reply_to_message_id=update.message.message_id)
예제 #6
0
def onText(bot, update):

    chat = update.message.chat
    user = update.message.from_user
    try:
        game = gm.chatid_games[chat.id][-1]
    except (KeyError, IndexError):
        return
    if game.started and game.last_card.value == c.SEVEN and not (
            update.message.text.startswith("Drawing")
            or update.message.text == "Pass"):
        send_async(bot,
                   chat.id,
                   text=__(
                       "{name} falou durante o 7 e comprou uma carta",
                       multi=game.translate).format(name=display_name(user)))
        player = gm.player_for_user_in_chat(user, chat)
        logger.info(
            "Add one card for {name}".format(name=display_name(player.user)))
        try:
            player.draw_serven()
        except DeckEmptyError:
            send_async(bot,
                       chat.id,
                       text=__("Não há mais cartas para compra",
                               multi=game.translate))
예제 #7
0
def leave_game(bot, update):
    """Handler for the /leave command"""
    chat = update.message.chat
    user = update.message.from_user

    player = gm.player_for_user_in_chat(user, chat)

    if player is None:
        send_async(bot,
                   chat.id,
                   text=_("You are not playing in a game in "
                          "this group."),
                   reply_to_message_id=update.message.message_id)
        return

    game = player.game
    user = update.message.from_user

    try:
        gm.leave_game(user, chat)

    except NoGameInChatError:
        send_async(bot,
                   chat.id,
                   text=_("You are not playing in a game in "
                          "this group."),
                   reply_to_message_id=update.message.message_id)

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

    else:
        if game.started:
            # send message to indicate the game has randomly choosen the color
            if game._randomed_color:
                send_async(bot,
                           chat.id,
                           text=__(
                               "Color randomly choosen to: {col}",
                               multi=game.translate).format(
                                   col=c.COLOR_ICONS[game.last_card.color]),
                           reply_to_message_id=update.message.message_id)
            send_async(
                bot,
                chat.id,
                text=__("Okay. Next Player: {name}",
                        multi=game.translate).format(
                            name=display_name(game.current_player.user)),
                reply_to_message_id=update.message.message_id)
        else:
            send_async(
                bot,
                chat.id,
                text=__("{name} left the game before it started.",
                        multi=game.translate).format(name=display_name(user)),
                reply_to_message_id=update.message.message_id)
예제 #8
0
def display_color_group(color, game):
    """ Convert a color code to actual color name """
    if color == "r":
        return __("{emoji} Red", game.translate).format(emoji='❤️')
    if color == "b":
        return __("{emoji} Blue", game.translate).format(emoji='💙')
    if color == "g":
        return __("{emoji} Green", game.translate).format(emoji='💚')
    if color == "y":
        return __("{emoji} Yellow", game.translate).format(emoji='💛')
예제 #9
0
def display_color_group(color, game):
    """ Convert a color code to actual color name """
    if color == "r":
        return __("{emoji} Rainbow", game.translate).format(emoji='🏳️‍🌈')
    if color == "b":
        return __("{emoji} Trans", game.translate).format(emoji='💙')
    if color == "g":
        return __("{emoji} Enby", game.translate).format(emoji='💜')
    if color == "y":
        return __("{emoji} Pan", game.translate).format(emoji='💛')
예제 #10
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

    last = player.game.last_card

    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:
        if len(player.cards) >= 1:
            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:            
            if last.special == c.CHOOSE or last.special == c.DRAW_FOUR:
                game.last_card.color = random.choice(c.COLORS)
                send_async(bot, chat.id,
                           text=__("Color randomly choosen to: {col}",
                                   multi=game.translate).format(
                               col=c.COLOR_ICONS[game.last_card.color]))
                
            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)
예제 #11
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", multi=game.translate))
        if game.current_player.user.id == bot.id:
            print('escolheu')
            color = c.COLORS[random.randint(0, 3)]
            game.choose_color(color)
            send_async(bot, chat.id, text=display_color_group(color, game))

    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)
예제 #12
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))
        send_async(bot, chat.id, text=__("Game ended! Flawless Victory!"))

        if us.stats:
            # us.games_played += 1

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

        if game.mode == 'one':
            gm.end_game(chat, user)
        else:
            game.players_won += 1

        try:
            if game.mode != 'one':
                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
                us2.last_places += 1

            gm.end_game(chat, user)
예제 #13
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')
예제 #14
0
def do_skip(bot, player, job_queue=None):
    game = player.game
    chat = game.chat
    skipped_player = game.current_player
    next_player = game.current_player.next

    if skipped_player.waiting_time > 0:
        skipped_player.anti_cheat += 1
        skipped_player.waiting_time -= TIME_REMOVAL_AFTER_SKIP
        if (skipped_player.waiting_time < 0):
            skipped_player.waiting_time = 0

        try:
            skipped_player.draw()
        except DeckEmptyError:
            pass

        n = skipped_player.waiting_time
        send_async(bot, chat.id,
                   text=__("Ye khiladi {time} seconds ke"
                        "liye hilane gaya hain\n"
                        "Agla chu: {name}", multi=game.translate)
                   .format(time=n,
                           name=display_name(next_player.user))
        )
        logger.info("{player} was skipped! "
                    .format(player=display_name(player.user)))
        game.turn()
        if job_queue:
            start_player_countdown(bot, game, job_queue)

    else:
        try:
            gm.leave_game(skipped_player.user, chat)
            send_async(bot, chat.id,
                       text=__("{name1} ran out of time "
                            "and has been removed from the game!\n"
                            "Next player: {name2}", multi=game.translate)
                       .format(name1=display_name(skipped_player.user),
                               name2=display_name(next_player.user)))
            logger.info("{player} was skipped! "
                    .format(player=display_name(player.user)))
            if job_queue:
                start_player_countdown(bot, game, job_queue)

        except NotEnoughPlayersError:
            send_async(bot, chat.id,
                       text=__("{name} ran out of time "
                               "and has been removed from the game!\n"
                               "The game ended.", multi=game.translate)
                       .format(name=display_name(skipped_player.user)))

            gm.end_game(chat, skipped_player.user)
예제 #15
0
def process_result(bot, update):
    """
    Handler for chosen inline results.
    Checks the players actions and acts accordingly.
    """
    try:
        user = update.chosen_inline_result.from_user
        player = gm.userid_current[user.id]
        game = player.game
        result_id = update.chosen_inline_result.result_id
        chat = game.chat
    except (KeyError, AttributeError):
        return

    logger.debug("Selected result: " + result_id)

    result_id, anti_cheat = result_id.split(':')
    last_anti_cheat = player.anti_cheat
    player.anti_cheat += 1

    if result_id in ('hand', 'gameinfo', 'nogame'):
        return
    elif len(result_id) == 36:  # UUID result
        return
    elif int(anti_cheat) != last_anti_cheat:
        send_async(bot,
                   chat.id,
                   text=__("Cheat attempt by {name}",
                           multi=game.translate).format(
                               name=display_name(player.user)))
        return
    elif result_id == 'call_bluff':
        reset_waiting_time(bot, player)
        do_call_bluff(bot, player)
    elif result_id == 'draw':
        reset_waiting_time(bot, player)
        do_draw(bot, player)
    elif result_id == 'pass':
        game.turn()
    elif result_id in c.COLORS:
        try:
            game.choose_color(result_id)
        except:
            pass
    else:
        reset_waiting_time(bot, player)
        do_play_card(bot, player, result_id)

    if game in gm.chatid_games.get(chat.id, list()):
        send_async(bot,
                   chat.id,
                   text=__("Next player: {name}", multi=game.translate).format(
                       name=display_name(game.current_player.user)))
예제 #16
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')
예제 #17
0
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)
예제 #18
0
def kill_game(bot, update):
    """Handler for the /kill command"""
    chat = update.message.chat
    user = update.message.from_user
    games = gm.chatid_games.get(chat.id)

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

    if not games:
            send_async(bot, chat.id,
                       text=_("There is no running game in this chat."))
            return

    game = games[-1]

    if user.id in game.owner or user.id in get_admin_ids(bot, chat.id):

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

        except NoGameInChatError:
            send_async(bot, chat.id,
                       text=_("The game is not started yet. "
                              "Join the game with /join and start the game with /start"),
                       reply_to_message_id=update.message.message_id)

    else:
        send_async(bot, chat.id,
                  text=_("Only the game creator ({name}) and admin can do that.")
                  .format(name=game.starter.first_name),
                  reply_to_message_id=update.message.message_id)
예제 #19
0
def add_call_bluff(results, game):
    """Add option to call a bluff"""
    results.append(
        Sticker("call_bluff",
                sticker_file_id=c.STICKERS['option_bluff'],
                input_message_content=InputTextMessageContent(
                    __("I'm calling your bluff!", multi=game.translate))))
예제 #20
0
def do_draw(bot, player):
    """Does the drawing"""
    game = player.game
    draw_counter_before = game.draw_counter

    try:
        player.draw()
    except DeckEmptyError:
        send_async(bot,
                   player.game.chat.id,
                   text=__("There are no more cards in the deck.",
                           multi=game.translate))

    if (game.last_card.value == c.DRAW_TWO or
        game.last_card.special == c.DRAW_FOUR) and \
            draw_counter_before > 0:
        game.turn()
    else:
        playable = player.playable_cards()
        if len(playable) == 0:
            time.sleep(1)
            send_async(bot,
                       game.chat.id,
                       text='Passing for {name}'.format(
                           name=display_name(game.current_player.user)))
            game.turn()
예제 #21
0
def add_pass(results, game):
    """Add option to pass"""
    results.append(
        Sticker("pass",
                sticker_file_id=c.STICKERS['option_pass'],
                input_message_content=InputTextMessageContent(
                    __('Pass', multi=game.translate))))
예제 #22
0
파일: bot.py 프로젝트: bay122/mau_mau_bot
def process_result(bot, update):
    """
    Handler for chosen inline results.
    Checks the players actions and acts accordingly.
    """
    try:
        user = update.chosen_inline_result.from_user
        player = gm.userid_current[user.id]
        game = player.game
        result_id = update.chosen_inline_result.result_id
        chat = game.chat
    except (KeyError, AttributeError):
        return

    logger.debug("Selected result: " + result_id)

    result_id, anti_cheat = result_id.split(':')
    last_anti_cheat = player.anti_cheat
    player.anti_cheat += 1

    if result_id in ('hand', 'gameinfo', 'nogame'):
        return
    elif len(result_id) == 36:  # UUID result
        return
    elif int(anti_cheat) != last_anti_cheat:
        send_async(bot, chat.id,
                   text=__("Cheat attempt by {name}", multi=game.translate)
                   .format(name=display_name(player.user)))
        return
    elif result_id == 'call_bluff':
        reset_waiting_time(bot, player)
        do_call_bluff(bot, player)
    elif result_id == 'draw':
        reset_waiting_time(bot, player)
        do_draw(bot, player)
    elif result_id == 'pass':
        game.turn()
    elif result_id in c.COLORS:
        game.choose_color(result_id)
    else:
        reset_waiting_time(bot, player)
        do_play_card(bot, player, result_id)

    if game in gm.chatid_games.get(chat.id, list()):
        send_async(bot, chat.id,
                   text=__("Next player: {name}", multi=game.translate)
                   .format(name=display_name(game.current_player.user)))
예제 #23
0
def add_pass(results, game):
    """Add option to pass"""
    results.append(
        Sticker(
            "pass", sticker_file_id=c.STICKERS['option_pass'],
            input_message_content=InputTextMessageContent(
                __('Pass', multi=game.translate)
            )
        )
    )
예제 #24
0
파일: bot.py 프로젝트: LoonCode/mau_mau_bot
def reset_waiting_time(bot, player):
    """Resets waiting time for a player and sends a notice to the group"""
    chat = player.game.chat

    if player.waiting_time < 90:
        player.waiting_time = 90
        send_async(bot, chat.id,
                   text=__("Waiting time for {name} has been reset to 90 "
                           "seconds", multi=player.game.translate)
                   .format(name=display_name(player.user)))
예제 #25
0
파일: bot.py 프로젝트: bay122/mau_mau_bot
def reset_waiting_time(bot, player):
    """Resets waiting time for a player and sends a notice to the group"""
    chat = player.game.chat

    if player.waiting_time < 90:
        player.waiting_time = 90
        send_async(bot, chat.id,
                   text=__("Waiting time for {name} has been reset to 90 "
                           "seconds", multi=player.game.translate)
                   .format(name=display_name(player.user)))
예제 #26
0
def add_call_bluff(results, game):
    """Add option to call a bluff"""
    results.append(
        Sticker(
            "call_bluff",
            sticker_file_id=c.STICKERS['option_bluff'],
            input_message_content=
            InputTextMessageContent(__("I'm calling your bluff!",
                                       multi=game.translate))
        )
    )
예제 #27
0
파일: bot.py 프로젝트: LoonCode/mau_mau_bot
def status_update(bot, update):
    """Remove player from game if user leaves the group"""
    chat = update.message.chat

    if update.message.left_chat_member:
        user = update.message.left_chat_member

        try:
            game = gm.player_for_user_in_chat(user, chat).game
            gm.leave_game(user, chat)

        except NoGameInChatError:
            pass
        except NotEnoughPlayersError:
            gm.end_game(chat, user)
            send_async(bot, chat.id, text=__("Game ended!",
                                             multi=game.translate))
        else:
            send_async(bot, chat.id, text=__("Removing {name} from the game",
                                             multi=game.translate)
                       .format(name=display_name(user)))
예제 #28
0
파일: bot.py 프로젝트: bay122/mau_mau_bot
def status_update(bot, update):
    """Remove player from game if user leaves the group"""
    chat = update.message.chat

    if update.message.left_chat_member:
        user = update.message.left_chat_member

        try:
            gm.leave_game(user, chat)
            game = gm.player_for_user_in_chat(user, chat).game

        except NoGameInChatError:
            pass
        except NotEnoughPlayersError:
            gm.end_game(chat, user)
            send_async(bot, chat.id, text=__("Game ended!",
                                             multi=game.translate))
        else:
            send_async(bot, chat.id, text=__("Removing {name} from the game",
                                             multi=game.translate)
                       .format(name=display_name(user)))
예제 #29
0
def add_draw(player, results):
    """Add option to draw"""
    n = player.game.draw_counter or 1

    results.append(
        Sticker("draw",
                sticker_file_id=c.STICKERS['option_draw'],
                input_message_content=InputTextMessageContent(
                    __('Drawing {number} card',
                       'Drawing {number} cards',
                       n,
                       multi=player.game.translate).format(number=n))))
예제 #30
0
def add_draw(player, results):
    """Add option to draw"""
    n = player.game.draw_counter or 1

    results.append(
        Sticker(
            "draw", sticker_file_id=c.STICKERS['option_draw'],
            input_message_content=
            InputTextMessageContent(__('Drawing {number} card',
                                       'Drawing {number} cards', n,
                                       multi=player.game.translate)
                                    .format(number=n))
        )
    )
예제 #31
0
def do_call_bluff(bot, player):
    """Handles the bluff calling"""
    game = player.game
    chat = game.chat

    if player.prev.bluffing:
        send_async(bot,
                   chat.id,
                   text="{name} ne gaand di! Giving 4 cards".format(
                       name=player.prev.user.first_name))

        try:
            player.prev.draw()
        except DeckEmptyError:
            send_async(bot,
                       player.game.chat.id,
                       text=__("There are no more cards in the deck.",
                               multi=game.translate))

    else:
        game.draw_counter += 2
        send_async(
            bot,
            chat.id,
            text=
            "{name1} ne gaand nahi di, ab {name2} ki gaand marega. Dukaan ka investment lelo"
            .format(name1=player.prev.user.first_name,
                    name2=player.user.first_name))
        try:
            player.draw()
        except DeckEmptyError:
            send_async(bot,
                       player.game.chat.id,
                       text=__("There are no more cards in the deck.",
                               multi=game.translate))

    game.turn()
예제 #32
0
def do_draw(bot, player):
    """Does the drawing"""
    game = player.game
    draw_counter_before = game.draw_counter

    try:
        player.draw()
    except DeckEmptyError:
        send_async(bot, player.game.chat.id,
                   text=__("There are no more cards in the deck.",
                           multi=game.translate))

    if (game.last_card.value == c.DRAW_TWO or
        game.last_card.special == c.DRAW_FOUR) and \
            draw_counter_before > 0:
        game.turn()
예제 #33
0
파일: bot.py 프로젝트: bay122/mau_mau_bot
def do_draw(bot, player):
    """Does the drawing"""
    game = player.game
    draw_counter_before = game.draw_counter

    try:
        player.draw()
    except DeckEmptyError:
        send_async(bot, player.game.chat.id,
                   text=__("There are no more cards in the deck.",
                           multi=game.translate))

    if (game.last_card.value == c.DRAW_TWO or
        game.last_card.special == c.DRAW_FOUR) and \
            draw_counter_before > 0:
        game.turn()
예제 #34
0
def play_next(game, bot, chat, job_queue):
    if game_is_running(game):
        nextplayer_message = (__(
            "Next player: {name}", multi=game.translate).format(
                name=display_name(game.current_player.user)))
        choice = [[
            InlineKeyboardButton(text=_("Make your choice!"),
                                 switch_inline_query_current_chat='')
        ]]
        send_async(bot,
                   chat.id,
                   text=nextplayer_message,
                   reply_markup=InlineKeyboardMarkup(choice))
        start_player_countdown(bot, game, job_queue)

        if game.current_player.user.id == bot.id:
            playBot(game.current_player, bot, chat, game, job_queue)
예제 #35
0
def kill_game(bot, update):
    """Handler for the /kill command"""
    chat = update.message.chat
    user = update.message.from_user
    games = gm.chatid_games.get(chat.id)

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

    if not games:
        send_async(bot, chat.id, text="Abe Bihari Game hi chalu nahi :|")
        return

    game = games[-1]

    if user_is_creator_or_admin(user, game, bot, chat):

        try:
            gm.end_game(chat, user)
            send_async(bot,
                       chat.id,
                       text=__("chalo hogaya aaj ka, back to bihar.",
                               multi=game.translate))

        except NoGameInChatError:
            send_async(
                bot,
                chat.id,
                text=_(
                    "Kardi na bihari wali baat "
                    "Join the game with /join and start the game with /start"),
                reply_to_message_id=update.message.message_id)

    else:
        send_async(
            bot,
            chat.id,
            text=_("Only the game creator ({name}) and admin can do that."
                   ).format(name=game.starter.first_name),
            reply_to_message_id=update.message.message_id)
예제 #36
0
파일: bot.py 프로젝트: matthi4s/mau_mau_bot
def process_auto(bot, game, job_queue):
    start_player = game.current_player

    if not game.choosing_color:
        playable = game.current_player.playable_cards()
        if len(playable) == 0 and game.draw_counter == 0:
            time.sleep(1)
            send_async(bot,
                       game.chat.id,
                       text='Drawing 1 card for {name}'.format(
                           name=display_name(game.current_player.user)))
            do_draw(bot, game.current_player)
            time.sleep(1)
            send_async(bot,
                       game.chat.id,
                       text=__(
                           "Next player: {name}", multi=game.translate).format(
                               name=display_name(game.current_player.user)))
            start_player_countdown(bot, game, job_queue)
            if (start_player != game.current_player):
                process_auto(bot, game, job_queue)
예제 #37
0
파일: bot.py 프로젝트: dvlwj/unorindo_bot
def start_game(bot, update, args, job_queue):
    """Handler for the /start command"""

    if update.message.chat.type != 'private':
        chat = update.message.chat

        try:
            game = gm.chatid_games[chat.id][-1]
        except (KeyError, IndexError):
            send_async(bot,
                       chat.id,
                       text=_("There is no game running in this chat. Create "
                              "a new one with /new"))
            return

        if game.started:
            send_async(bot, chat.id, text=_("The game has already started"))

        elif len(game.players) < MIN_PLAYERS:
            send_async(
                bot,
                chat.id,
                text=__(
                    "At least {minplayers} players must /join the game "
                    "before you can start it").format(minplayers=MIN_PLAYERS))

        else:
            # Set winning score
            player_num = len(game.players)
            if player_num == 2:
                game.win_score = SCORE_DUEL
            else:
                game.win_score = ADDITIONAL_POINT * player_num
            # Starting a game
            game.start()

            for player in game.players:
                player.draw_first_hand()

            first_message = (__(
                "First player: {name}\n"
                "Use /close to stop people from joining the game.\n"
                "Enable multi-translations with /enable_translations",
                multi=game.translate).format(
                    name=display_name(game.current_player.user)))

            @run_async
            def send_first():
                """Send the first card and player"""

                bot.sendSticker(chat.id,
                                sticker=c.STICKERS[str(game.last_card)],
                                timeout=TIMEOUT)

                bot.sendMessage(chat.id, text=first_message, timeout=TIMEOUT)

            send_first()
            start_player_countdown(bot, game, job_queue)

    elif len(args) and args[0] == 'select':
        players = gm.userid_players[update.message.from_user.id]

        groups = list()
        for player in players:
            title = player.game.chat.title

            if player is gm.userid_current[update.message.from_user.id]:
                title = '- %s -' % player.game.chat.title

            groups.append([
                InlineKeyboardButton(text=title,
                                     callback_data=str(player.game.chat.id))
            ])

        send_async(bot,
                   update.message.chat_id,
                   text=_('Please select the group you want to play in.'),
                   reply_markup=InlineKeyboardMarkup(groups))

    else:
        help_handler(bot, update)
예제 #38
0
파일: bot.py 프로젝트: dvlwj/unorindo_bot
def kick_player(bot, update):
    """Handler for the /kick command"""

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

    chat = update.message.chat
    user = update.message.from_user

    try:
        game = gm.chatid_games[chat.id][-1]

    except (KeyError, IndexError):
        send_async(bot,
                   chat.id,
                   text=_("No game is running at the moment. "
                          "Create a new game with /new"),
                   reply_to_message_id=update.message.message_id)
        return

    if not game.started:
        send_async(
            bot,
            chat.id,
            text=_("The game is not started yet. "
                   "Join the game with /join and start the game with /start"),
            reply_to_message_id=update.message.message_id)
        return

    if user_is_creator_or_admin(user, game, bot, chat):

        if update.message.reply_to_message:
            kicked = update.message.reply_to_message.from_user

            try:
                gm.leave_game(kicked, chat)

            except NoGameInChatError:
                send_async(
                    bot,
                    chat.id,
                    text=_("Player {name} is not found in the current game.".
                           format(name=display_name(kicked))),
                    reply_to_message_id=update.message.message_id)
                return

            except NotEnoughPlayersError:
                gm.end_game(chat, user)
                send_async(bot,
                           chat.id,
                           text=_("{0} was kicked by {1}".format(
                               display_name(kicked), display_name(user))))
                send_async(bot,
                           chat.id,
                           text=__("Game ended!", multi=game.translate))
                return

            send_async(bot,
                       chat.id,
                       text=_("{0} was kicked by {1}".format(
                           display_name(kicked), display_name(user))))

        else:
            send_async(
                bot,
                chat.id,
                text=
                _("Please reply to the person you want to kick and type /kick again."
                  ),
                reply_to_message_id=update.message.message_id)
            return

        send_async(bot,
                   chat.id,
                   text=__("Okay. Next Player: {name}",
                           multi=game.translate).format(
                               name=display_name(game.current_player.user)),
                   reply_to_message_id=update.message.message_id)

    else:
        send_async(
            bot,
            chat.id,
            text=_("Only the game creator ({name}) and admin can do that."
                   ).format(name=game.starter.first_name),
            reply_to_message_id=update.message.message_id)
예제 #39
0
def do_skip(bot, player, job_queue=None):
    game = player.game
    chat = game.chat
    skipped_player = game.current_player
    next_player = game.current_player.next

    if skipped_player.waiting_time > 0:
        skipped_player.anti_cheat += 1
        skipped_player.waiting_time -= TIME_REMOVAL_AFTER_SKIP
        if (skipped_player.waiting_time < 0):
            skipped_player.waiting_time = 0

        # skip drawing if current player should choose color
        # which means current player has played a card
        try:
            if not game.choosing_color:
                skipped_player.draw()
        except DeckEmptyError:
            pass

        n = skipped_player.waiting_time
        send_async(bot,
                   chat.id,
                   text=__(
                       "Waiting time to skip this player has "
                       "been reduced to {time} seconds.\n"
                       "Next player: {name}",
                       multi=game.translate).format(time=n,
                                                    name=display_name(
                                                        next_player.user)))
        logger.info(
            "{player} was skipped!. ".format(player=display_name(player.user)))
        game.turn()

        # send message to indicate the game has randomly choosen the color
        if game._randomed_color:
            send_async(bot,
                       chat.id,
                       text=__("Color randomly choosen to: {col}",
                               multi=game.translate).format(
                                   col=c.COLOR_ICONS[game.last_card.color]))

        if job_queue:
            start_player_countdown(bot, game, job_queue)

    else:
        try:
            gm.leave_game(skipped_player.user, chat)
            send_async(bot,
                       chat.id,
                       text=__(
                           "{name1} ran out of time "
                           "and has been removed from the game!\n"
                           "Next player: {name2}",
                           multi=game.translate).format(
                               name1=display_name(skipped_player.user),
                               name2=display_name(next_player.user)))
            logger.info("{player} was skipped!. ".format(
                player=display_name(player.user)))
            if job_queue:
                start_player_countdown(bot, game, job_queue)

        except NotEnoughPlayersError:
            send_async(bot,
                       chat.id,
                       text=__(
                           "{name} ran out of time "
                           "and has been removed from the game!\n"
                           "The game ended.",
                           multi=game.translate).format(
                               name=display_name(skipped_player.user)))

            gm.end_game(chat, skipped_player.user)
예제 #40
0
def skip_player(bot, update):
    """Handler for the /skip command"""
    chat = update.message.chat
    user = update.message.from_user

    player = gm.player_for_user_in_chat(user, chat)
    if not player:
        send_async(bot,
                   chat.id,
                   text=_("You are not playing in a game in this chat."))
        return

    game = player.game
    skipped_player = game.current_player
    next_player = game.current_player.next

    started = skipped_player.turn_started
    now = datetime.now()
    delta = (now - started).seconds

    if delta < skipped_player.waiting_time:
        n = skipped_player.waiting_time - delta
        send_async(bot,
                   chat.id,
                   text=_("Please wait {time} second",
                          "Please wait {time} seconds", n).format(time=n),
                   reply_to_message_id=update.message.message_id)

    elif skipped_player.waiting_time > 0:
        skipped_player.anti_cheat += 1
        skipped_player.waiting_time -= 30
        try:
            skipped_player.draw()
        except DeckEmptyError:
            pass

        n = skipped_player.waiting_time
        send_async(bot,
                   chat.id,
                   text=__(
                       "Waiting time to skip this player has "
                       "been reduced to {time} second.\n"
                       "Next player: {name}",
                       "Waiting time to skip this player has "
                       "been reduced to {time} seconds.\n"
                       "Next player: {name}",
                       n,
                       multi=game.translate).format(time=n,
                                                    name=display_name(
                                                        next_player.user)))
        game.turn()

    else:
        try:
            gm.leave_game(skipped_player.user, chat)
            send_async(bot,
                       chat.id,
                       text=__(
                           "{name1} was skipped four times in a row "
                           "and has been removed from the game.\n"
                           "Next player: {name2}",
                           multi=game.translate).format(
                               name1=display_name(skipped_player.user),
                               name2=display_name(next_player.user)))

        except NotEnoughPlayersError:
            send_async(bot,
                       chat.id,
                       text=__(
                           "{name} was skipped four times in a row "
                           "and has been removed from the game.\n"
                           "The game ended.",
                           multi=game.translate).format(
                               name=display_name(skipped_player.user)))

            gm.end_game(chat.id, skipped_player.user)
예제 #41
0
파일: bot.py 프로젝트: bay122/mau_mau_bot
def start_game(bot, update, args):
    """Handler for the /start command"""

    if update.message.chat.type != 'private':
        chat = update.message.chat

        try:
            game = gm.chatid_games[chat.id][-1]
        except (KeyError, IndexError):
            send_async(bot, chat.id,
                       text=_("There is no game running in this chat. Create "
                              "a new one with /new"))
            return

        if game.started:
            send_async(bot, chat.id, text=_("The game has already started"))

        elif len(game.players) < 2:
            send_async(bot, chat.id,
                       text=_("At least two players must /join the game "
                              "before you can start it"))

        else:
            game.play_card(game.last_card)
            game.started = True

            first_message = (
                __("First player: {name}\n"
                   "Use /close to stop people from joining the game.\n"
                   "Enable multi-translations with /enable_translations",
                   multi=game.translate)
                .format(name=display_name(game.current_player.user)))

            @run_async
            def send_first():
                """Send the first card and player"""

                bot.sendSticker(chat.id,
                                sticker=c.STICKERS[str(game.last_card)],
                                timeout=TIMEOUT)

                bot.sendMessage(chat.id,
                                text=first_message,
                                timeout=TIMEOUT)

            send_first()

    elif len(args) and args[0] == 'select':
        players = gm.userid_players[update.message.from_user.id]

        groups = list()
        for player in players:
            title = player.game.chat.title

            if player is gm.userid_current[update.message.from_user.id]:
                title = '- %s -' % player.game.chat.title

            groups.append(
                [InlineKeyboardButton(text=title,
                                      callback_data=str(player.game.chat.id))]
            )

        send_async(bot, update.message.chat_id,
                   text=_('Please select the group you want to play in.'),
                   reply_markup=InlineKeyboardMarkup(groups))

    else:
        help(bot, update)
예제 #42
0
파일: bot.py 프로젝트: bay122/mau_mau_bot
def skip_player(bot, update):
    """Handler for the /skip command"""
    chat = update.message.chat
    user = update.message.from_user

    player = gm.player_for_user_in_chat(user, chat)
    if not player:
        send_async(bot, chat.id,
                   text=_("You are not playing in a game in this chat."))
        return

    game = player.game
    skipped_player = game.current_player
    next_player = game.current_player.next

    started = skipped_player.turn_started
    now = datetime.now()
    delta = (now - started).seconds

    if delta < skipped_player.waiting_time:
        n = skipped_player.waiting_time - delta
        send_async(bot, chat.id,
                   text=_("Please wait {time} second",
                          "Please wait {time} seconds",
                          n)
                   .format(time=n),
                   reply_to_message_id=update.message.message_id)

    elif skipped_player.waiting_time > 0:
        skipped_player.anti_cheat += 1
        skipped_player.waiting_time -= 30
        try:
            skipped_player.draw()
        except DeckEmptyError:
            pass

        n = skipped_player.waiting_time
        send_async(bot, chat.id,
                   text=__("Waiting time to skip this player has "
                           "been reduced to {time} second.\n"
                           "Next player: {name}",
                           "Waiting time to skip this player has "
                           "been reduced to {time} seconds.\n"
                           "Next player: {name}",
                           n,
                           multi=game.translate)
                   .format(time=n,
                           name=display_name(next_player.user)))
        game.turn()

    else:
        try:
            gm.leave_game(skipped_player.user, chat)
            send_async(bot, chat.id,
                       text=__("{name1} was skipped four times in a row "
                               "and has been removed from the game.\n"
                               "Next player: {name2}", multi=game.translate)
                       .format(name1=display_name(skipped_player.user),
                               name2=display_name(next_player.user)))

        except NotEnoughPlayersError:
            send_async(bot, chat.id,
                       text=__("{name} was skipped four times in a row "
                               "and has been removed from the game.\n"
                               "The game ended.", multi=game.translate)
                       .format(name=display_name(skipped_player.user)))

            gm.end_game(chat.id, skipped_player.user)