Exemple #1
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=_("There is no running game in this chat."))
        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=__("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)
Exemple #2
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)
Exemple #3
0
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)
Exemple #4
0
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=_("kardi jatin bihari pruthi wali baat "
                          "Naya game bana /new "),
                   reply_to_message_id=update.message.message_id)
        return

    if not game.started:
        send_async(
            bot,
            chat.id,
            text=_(
                "kardi bihari wali baat, /join karke start kar aise /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=__("chalo hogaya aaj ka, back to bihar.",
                                   multi=game.translate))
                return

            send_async(bot,
                       chat.id,
                       text="{1} ne {0} ko bihar bhej diya".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. Agla Bihari: {name}".format(
                       name=display_name(me.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)