Esempio n. 1
0
def removetag(update, context):
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message
    args = context.args
    user_id, reason = extract_user_and_text(message, args)
    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return
    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("I can't seem to find this user")
            return
        else:
            raise
    if user_id == context.bot.id:
        message.reply_text("how I supposed to tag or untag myself")
        return
    chat_id = str(chat.id)[1:]
    tagall_list = list(REDIS.sunion(f'tagall2_{chat_id}'))
    match_user = mention_html(member.user.id, member.user.first_name)
    if match_user not in tagall_list:
        message.reply_text("{} is doesn't exist in {}'s list!".format(
            mention_html(member.user.id, member.user.first_name), chat.title),
                           parse_mode=ParseMode.HTML)
        return
    member = chat.get_member(int(user_id))
    chat_id = str(chat.id)[1:]
    REDIS.srem(f'tagall2_{chat_id}',
               mention_html(member.user.id, member.user.first_name))
    message.reply_text("{} is successfully removed from {}'s list.".format(
        mention_html(member.user.id, member.user.first_name), chat.title),
                       parse_mode=ParseMode.HTML)
Esempio n. 2
0
def set_title(update, context):
    args = context.args
    chat = update.effective_chat
    message = update.effective_message

    user_id, title = extract_user_and_text(message, args)
    try:
        user_member = chat.get_member(user_id)
    except Exception:
        return

    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return

    if user_member.status == "creator":
        message.reply_text(
            "This person CREATED the chat, how can i set custom title for him?"
        )
        return

    if not user_member.status == "administrator":
        message.reply_text(
            "Can't set title for non-admins!\nPromote them first to set custom title!"
        )
        return

    if user_id == context.bot.id:
        message.reply_text(
            "I can't set my own title myself! Get the one who made me admin to do it for me."
        )
        return

    if not title:
        message.reply_text("Setting blank title doesn't do anything!")
        return

    if len(title) > 16:
        message.reply_text(
            "The title length is longer than 16 characters.\nTruncating it to 16 characters."
        )

    try:
        context.bot.set_chat_administrator_custom_title(
            chat.id, user_id, title)
        message.reply_text(
            "Sucessfully set title for <b>{}</b> to <code>{}</code>!".format(
                user_member.user.first_name or user_id, title[:16]),
            parse_mode=ParseMode.HTML,
        )

    except BadRequest:
        message.reply_text(
            "I can't set custom title for admins that I didn't promote!")
Esempio n. 3
0
def unban(update, context):
    message = update.effective_message  # type: Optional[Message]
    user = update.effective_user  # type: Optional[User]
    chat = update.effective_chat  # type: Optional[Chat]
    args = context.args

    if user_can_ban(chat, user, context.bot.id) is False:
        message.reply_text(
            "You don't have enough rights to unban people here!")
        return ""

    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return ""

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("I can't seem to find this user")
            return ""
        else:
            raise

    if user_id == context.bot.id:
        message.reply_text("How would I unban myself if I wasn't here...?")
        return ""

    if is_user_in_chat(chat, user_id):
        message.reply_text(
            "Why are you trying to unban someone who's already in this chat?")
        return ""

    chat.unban_member(user_id)
    message.reply_text("Done, they can join again!")

    log = ("<b>{}:</b>"
           "\n#UNBANNED"
           "\n<b>Admin:</b> {}"
           "\n<b>User:</b> {} (<code>{}</code>)".format(
               html.escape(chat.title),
               mention_html(user.id, user.first_name),
               mention_html(member.user.id, member.user.first_name),
               member.user.id,
           ))
    if reason:
        log += "\n<b>Reason:</b> {}".format(reason)

    return log
Esempio n. 4
0
def addtag(update, context):
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message
    args = context.args
    user_id, reason = extract_user_and_text(message, args)
    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return
    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("I can't seem to find this user")
            return
        else:
            raise
    if user_id == context.bot.id:
        message.reply_text("how I supposed to tag myself")
        return

    chat_id = str(chat.id)[1:]
    tagall_list = list(REDIS.sunion(f'tagall2_{chat_id}'))
    match_user = mention_html(member.user.id, member.user.first_name)
    if match_user in tagall_list:
        message.reply_text("{} is already exist in {}'s tag list.".format(
            mention_html(member.user.id, member.user.first_name), chat.title),
                           parse_mode=ParseMode.HTML)
        return
    message.reply_text(
        "{} accept this, if you want to add yourself into {}'s tag list! or just simply decline this."
        .format(mention_html(member.user.id, member.user.first_name),
                chat.title),
        reply_markup=InlineKeyboardMarkup([[
            InlineKeyboardButton(text="Accept",
                                 callback_data=f"tagall_accept={user_id}"),
            InlineKeyboardButton(text="Decline",
                                 callback_data=f"tagall_dicline={user_id}")
        ]]),
        parse_mode=ParseMode.HTML)
Esempio n. 5
0
def warn_user(update, context):
    message = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    warner = update.effective_user  # type: Optional[User]
    args = context.args
    user_id, reason = extract_user_and_text(message, args)

    if user_id:
        if (
            message.reply_to_message
            and message.reply_to_message.from_user.id == user_id
        ):
            return warn(
                message.reply_to_message.from_user,
                chat,
                reason,
                message.reply_to_message,
                warner,
            )
        else:
            return warn(chat.get_member(user_id).user, chat, reason, message, warner)
    else:
        message.reply_text("No user was designated!")
    return ""
Esempio n. 6
0
def gban(update, context):
    message = update.effective_message
    chat = update.effective_chat
    args = context.args
    user_id, reason = extract_user_and_text(message, args)
    if message.reply_to_message.photo:
        photo = context.bot.get_file(
            update.message.reply_to_message.photo[-1].file_id)
        evidence_img = photo.download(
            f'{str(update.message.from_user.id)}.jpg')
        evidence_img = upload_image(evidence_img)
    else:
        evidence = message.reply_to_message.text

    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return

    if user_id == OWNER_ID:
        message.reply_text("Nice try -_- but I'm never gonna gban him.")
        return

    if int(user_id) in SUDO_USERS:
        message.reply_text(
            "I spy, with my little eye... a sudo user war! Why are you guys turning on each other?"
        )
        return

    if int(user_id) in SUPPORT_USERS:
        message.reply_text(
            "OOOH someone's trying to gban a support user! *grabs popcorn*")
        return

    if user_id == context.bot.id:
        message.reply_text(
            "-_- So funny, lets gban myself why don't I? Nice try.")
        return

    try:
        user_chat = context.bot.get_chat(user_id)
    except BadRequest as excp:
        message.reply_text(excp.message)
        return

    if user_chat.type != "private":
        message.reply_text("That's not a user!")
        return

    if user_chat.first_name == "":
        message.reply_text(
            "This is a deleted account! no point to gban them...")
        return

    if not reason:
        message.reply_text(
            "Global Ban requires a reason to do so, why not send me one?")
        return
    if sql.is_user_gbanned(user_id):
        if not reason:
            message.reply_text(
                "This user is already gbanned; I'd change the reason, but you haven't given me one..."
            )
            return

        old_reason = sql.update_gban_reason(
            user_id, user_chat.username or user_chat.first_name, reason)
        user_id, new_reason = extract_user_and_text(message, args)

        if old_reason:
            banner = update.effective_user  # type: Optional[User]
            bannerid = banner.id
            bannername = banner.first_name
            new_reason = (
                f"{new_reason} // GBanned by {bannername} id {bannerid}")

            context.bot.sendMessage(
                GBAN_DUMP,
                "<b>Global Ban Reason Update</b>"
                "\n<b>Sudo Admin:</b> {}"
                "\n<b>User:</b> {}"
                "\n<b>ID:</b> <code>{}</code>"
                "\n<b>Previous Reason:</b> {}"
                "\n<b>New Reason:</b> {}".format(
                    mention_html(banner.id, banner.first_name),
                    mention_html(user_chat.id, user_chat.first_name
                                 or "Deleted Account"),
                    user_chat.id,
                    old_reason,
                    new_reason,
                ),
                parse_mode=ParseMode.HTML,
            )

            message.reply_text(
                "This user is already gbanned, for the following reason:\n"
                "<code>{}</code>\n"
                "I've gone and updated it with your new reason!".format(
                    html.escape(old_reason)),
                parse_mode=ParseMode.HTML,
            )

        else:
            message.reply_text(
                "This user is already gbanned, but had no reason set; I've gone and updated it!"
            )

        return

    banner = update.effective_user
    bannerid = banner.id
    bannername = banner.first_name
    reason = f"{reason} // GBanned by {bannername} id {bannerid}"

    if chat.type != 'private':
        chat_origin = "<b>{} ({})</b>".format(html.escape(chat.title), chat.id)
    else:
        chat_origin = "<b>{}</b>".format(chat.id)

    if message.reply_to_message.photo:
        evidence = f"<img src='{evidence_img}'>"
    else:
        evidence = evidence
    EVIDENSE_NEW_GBAN = f"<strong>New Global Ban</strong> \
                        \n<strong>Originated from:</strong> <code>{chat_origin}</code> \
                        \n<strong>Sudo Admin:</strong> {mention_html(banner.id, banner.first_name)} \
                        \n<strong>User:</strong> {mention_html(user_chat.id, user_chat.first_name)} \
                        \n<strong>ID:</strong> <code>{user_chat.id}</code> \
                        \n<strong>Reason:</strong> {reason} \
                        \n\n<strong>Evidence:</strong> <br>\n{evidence}"

    page = Shoko_gban.post(title=f"Erina-gban-{user_chat.id}",
                           author=f"{banner.first_name} ({banner.id})",
                           text=EVIDENSE_NEW_GBAN)
    evidence_link = page.get('url')
    evidence_link = "<a href='{}'>{}</a>".format(
        evidence_link, f"Erina GBanned // user_id: {user_chat.id}")

    message.reply_text(
        f"<b>Beginning of Global Ban for</b> {mention_html(user_chat.id, user_chat.first_name)}"
        f"\n<b>With ID</b>: <code>{user_chat.id}</code>"
        f"\n<b>Reason</b>: <code>{reason}</code>"
        f"\n<b>Evidence:</b> {evidence_link}",
        parse_mode=ParseMode.HTML,
        disable_web_page_preview=True,
    )
    starting_usermsg = f"""<b>You've been globally banned</b>\n<b>Reason:</b> {reason}\n<b>Global Ban log:</b> <a href="https://t.me/gban_dump">here</a>\n<b>Appeal:</b> <a href="https://t.me/AmSuraj">here</a>"""

    try:
        if chat.type != 'private':
            chat_origin = "<b>{} ({})</b>".format(html.escape(chat.title),
                                                  chat.id)
        else:
            chat_origin = "<b>{}</b>".format(chat.id)
        context.bot.sendMessage(
            GBAN_DUMP,
            "<b>New Global Ban</b>"
            f"\n<b>Originated from:</b> <code>{chat_origin}</code>"
            "\n<b>Sudo Admin:</b> {}"
            "\n<b>User:</b> {}"
            "\n<b>ID:</b> <code>{}</code>"
            "\n<b>Reason:</b> {}"
            "\n<b>Evidence:</b> {}".format(
                mention_html(banner.id, banner.first_name),
                mention_html(user_chat.id, user_chat.first_name),
                user_chat.id,
                reason,
                evidence_link,
            ),
            parse_mode=ParseMode.HTML,
            disable_web_page_preview=True,
        )

    except Exception:
        context.bot.send_message(ERROR_DUMP, "<b>[Error]</b>"
                                 "\nFailed to Log gban user.")

    try:
        context.bot.send_message(user_chat.id,
                                 starting_usermsg,
                                 parse_mode=ParseMode.HTML,
                                 disable_web_page_preview=True)
    except Exception:
        context.bot.send_message(ERROR_DUMP, f"<b>[Error]</b>\n"
                                 f"Failed to send Gban message to this user."
                                 f"\nID: <code>{user_chat.id}</code>",
                                 parse_mode=ParseMode.HTML)

    try:
        context.bot.kick_chat_member(chat.id, user_chat.id)
    except BadRequest as excp:
        if excp.message in GBAN_ERRORS:
            pass

    sql.gban_user(user_id, user_chat.username or user_chat.first_name, reason)
Esempio n. 7
0
def ungban(update, context):
    message = update.effective_message
    bot = context.bot
    args = context.args
    user_id, reason = extract_user_and_text(message, args)
    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return

    user_chat = context.bot.get_chat(user_id)
    if user_chat.type != "private":
        message.reply_text("That's not a user!")
        return

    if not sql.is_user_gbanned(user_id):
        message.reply_text("This user is not gbanned!")
        return

    if not reason:
        message.reply_text(
            "Removal of Global Ban requires a reason to do so, why not send me one?"
        )
        return

    unbanner = update.effective_user  # type: Optional[User]
    full_reason = html.escape(
        f"{reason} // Un-GBanned by {unbanner.first_name} id {unbanner.id}")

    message.reply_text(
        "<b>Regression of Global Ban</b>"
        "\n<b>Sudo Admin:</b> {}"
        "\n<b>User:</b> {}"
        "\n<b>ID:</b> <code>{}</code>"
        "\n<b>Reason:</b> {}".format(
            mention_html(unbanner.id, unbanner.first_name),
            mention_html(user_chat.id, user_chat.first_name),
            user_chat.id,
            full_reason,
        ),
        parse_mode=ParseMode.HTML,
    )
    try:
        context.bot.sendMessage(
            GBAN_DUMP,
            "<b>Regression of Global Ban</b>"
            "\n<b>Status:</b> <code>Ceased</code>"
            "\n<b>Sudo Admin:</b> {}"
            "\n<b>User:</b> {}"
            "\n<b>ID:</b> <code>{}</code>"
            "\n<b>Reason:</b> {}".format(
                mention_html(unbanner.id, unbanner.first_name),
                mention_html(user_chat.id, user_chat.first_name),
                user_chat.id,
                full_reason,
            ),
            parse_mode=ParseMode.HTML,
        )
    except Exception:
        bot.send_message(GBAN_DUMP, "<b>[Error]</b>"
                         "\nFailed to Log un-gban user.")
    try:
        ungban_strating_user = f"<b>You've been globally unbanned</b>\n<b>Reason:</b> {full_reason}"

        bot.send_message(user_chat.id,
                         ungban_strating_user,
                         parse_mode=ParseMode.HTML,
                         disable_web_page_preview=True)

        bot.send_message(user_chat.id,
                         "This user have been ungbanned succesfully, they might have to ask 'admins' of chats they were banned to unban manually due to global ban." \
                        "\n\nPlease forward this message to them or let them know about this.",
                        parse_mode=ParseMode.HTML,
                        disable_web_page_preview=True
                        )
    except Exception:
        bot.send_message(ERROR_DUMP, f"<b>[Error]</b>\n"
                         f"Failed to send Un-Gban message to this user."
                         f"\nID: <code>{user_chat.id}</code>",
                         parse_mode=ParseMode.HTML)

        message.reply_text("This user have been ungbanned succesfully, they might have to ask 'admins' of chats they were banned to unban manually due to global ban." \
                       "\n\nPlease forward this message to them or let them know about this.")

    sql.ungban_user(user_id)
Esempio n. 8
0
def temp_mute(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    args = context.args

    if user_can_ban(chat, user, context.bot.id) == False:
        message.reply_text(
            "You don't have enough rights to restrict someone from talking!")
        return ""

    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return ""

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("I can't seem to find this user")
            return ""
        else:
            raise

    if is_user_admin(chat, user_id, member):
        message.reply_text("I really wish I could mute admins.")
        return ""

    if user_id == context.bot.id:
        message.reply_text("I'm not gonna mute myself.")
        return ""

    if user_id == 777000 or user_id == 1087968824:
        message.reply_text(
            str(user_id) +
            " is an account reserved for telegram, I cannot mute it!")
        return ""

    if not reason:
        message.reply_text(
            "You haven't specified a time to mute this user for!")
        return ""

    split_reason = reason.split(None, 1)

    time_val = split_reason[0].lower()
    if len(split_reason) > 1:
        reason = split_reason[1]
    else:
        reason = ""

    mutetime = extract_time(message, time_val)

    if not mutetime:
        return ""

    log = ("<b>{}:</b>"
           "\n#TEMP MUTED"
           "\n<b>Admin:</b> {}"
           "\n<b>User:</b> {}"
           "\n<b>Time:</b> {}".format(
               html.escape(chat.title),
               mention_html(user.id, user.first_name),
               mention_html(member.user.id, member.user.first_name),
               time_val,
           ))
    if reason:
        log += "\n<b>Reason:</b> {}".format(reason)

    try:
        if member.can_send_messages is None or member.can_send_messages:
            context.bot.restrict_chat_member(
                chat.id,
                user_id,
                until_date=mutetime,
                permissions=ChatPermissions(can_send_messages=False),
            )
            reply_msg = "*{}* (`{}`) has been muted in *{}* for {}!.".format(
                member.user.first_name, member.user.id, chat.title, time_val)
            message.reply_text(reply_msg,
                               reply_markup=InlineKeyboardMarkup([[
                                   InlineKeyboardButton(
                                       text="Unmute",
                                       callback_data=f"muteb_mute={user_id}"),
                                   InlineKeyboardButton(
                                       text="Delete",
                                       callback_data=f"muteb_del")
                               ]]),
                               parse_mode=ParseMode.MARKDOWN)
            return log
        else:
            message.reply_text("This user is already muted.")

    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text("shut up! muted for {}!".format(time_val),
                               quote=False)
            return log
        else:
            LOGGER.warning(update)
            LOGGER.exception(
                "ERROR muting user %s in chat %s (%s) due to %s",
                user_id,
                chat.title,
                chat.id,
                excp.message,
            )
            message.reply_text("Well damn, I can't mute that user.")

    return ""
Esempio n. 9
0
def ban(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    args = context.args

    if user_can_ban(chat, user, context.bot.id) is False:
        message.reply_text("You don't have enough rights to ban users!")
        return ""

    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return ""

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("I can't seem to find this user")
            return ""
        else:
            raise

    if is_user_ban_protected(chat, user_id, member):
        message.reply_text(
            "I'm not gonna ban an admin, don't make fun of yourself!")
        return ""

    if user_id == context.bot.id:
        message.reply_text(
            "I'm not gonna ban myself, that's pretty dumb idea!")
        return ""

    if user_id == 777000 or user_id == 1087968824:
        message.reply_text(
            str(user_id) +
            " is an account reserved for telegram, I cannot ban it!")
        return ""

    log = ("<b>{}:</b>"
           "\n#BANNED"
           "\n<b>Admin:</b> {}"
           "\n<b>User:</b> {} (<code>{}</code>)".format(
               html.escape(chat.title),
               mention_html(user.id, user.first_name),
               mention_html(member.user.id, member.user.first_name),
               member.user.id,
           ))
    if reason:
        log += "\n<b>Reason:</b> {}".format(reason)

    try:
        chat.kick_member(user_id)
        context.bot.sendMessage(
            chat.id,
            "Admin {} has successfully banned {} in <b>{}</b>!.".format(
                mention_html(user.id, user.first_name),
                mention_html(member.user.id, member.user.first_name),
                html.escape(chat.title)),
            parse_mode=ParseMode.HTML,
        )
        return log

    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text("Banned!", quote=False)
            return log
        else:
            LOGGER.warning(update)
            LOGGER.exception(
                "ERROR banning user %s in chat %s (%s) due to %s",
                user_id,
                chat.title,
                chat.id,
                excp.message,
            )
            message.reply_text("Well damn, I can't ban that user.")

    return ""
Esempio n. 10
0
def kick(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    args = context.args

    if user_can_ban(chat, user, context.bot.id) is False:
        message.reply_text("You don't have enough rights to kick users!")
        return ""

    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return ""

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("I can't seem to find this user")
            return ""
        else:
            raise

    if is_user_ban_protected(chat, user_id):
        message.reply_text("Yeahh... let's start kicking admins?")
        return ""

    if user_id == context.bot.id:
        message.reply_text("Yeahhh I'm not gonna do that")
        return ""

    if user_id == 777000 or user_id == 1087968824:
        message.reply_text(
            str(user_id) +
            " is an account reserved for telegram, I cannot kick it!")
        return ""

    res = chat.unban_member(user_id)  # unban on current user = kick
    if res:

        context.bot.sendMessage(
            chat.id,
            "Admin {} has successfully kicked {} in <b>{}</b>!".format(
                mention_html(user.id, user.first_name),
                mention_html(member.user.id, member.user.first_name),
                html.escape(chat.title)),
            parse_mode=ParseMode.HTML,
        )
        log = ("<b>{}:</b>"
               "\n#KICKED"
               "\n<b>Admin:</b> {}"
               "\n<b>User:</b> {} (<code>{}</code>)".format(
                   html.escape(chat.title),
                   mention_html(user.id, user.first_name),
                   mention_html(member.user.id, member.user.first_name),
                   member.user.id,
               ))
        if reason:
            log += "\n<b>Reason:</b> {}".format(reason)

        return log

    else:
        message.reply_text("Get Out!.")

    return ""
Esempio n. 11
0
def temp_ban(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    args = context.args

    if user_can_ban(chat, user, context.bot.id) is False:
        message.reply_text(
            "You don't have enough rights to temporarily ban someone!")
        return ""

    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return ""

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("I can't seem to find this user")
            return ""
        else:
            raise

    if is_user_ban_protected(chat, user_id, member):
        message.reply_text("Wow! let's start banning Admins themselves?...")
        return ""

    if user_id == context.bot.id:
        message.reply_text("I'm not gonna BAN myself, are you crazy or wot?")
        return ""

    if user_id == 777000 or user_id == 1087968824:
        message.reply_text(
            str(user_id) +
            " is an account reserved for telegram, I cannot ban it!")
        return ""

    if not reason:
        message.reply_text(
            "You haven't specified a time to ban this user for!")
        return ""

    split_reason = reason.split(None, 1)

    time_val = split_reason[0].lower()
    if len(split_reason) > 1:
        reason = split_reason[1]
    else:
        reason = ""

    bantime = extract_time(message, time_val)

    if not bantime:
        return ""

    log = ("<b>{}:</b>"
           "\n#TEMP BANNED"
           "\n<b>Admin:</b> {}"
           "\n<b>User:</b> {} (<code>{}</code>)"
           "\n<b>Time:</b> {}".format(
               html.escape(chat.title),
               mention_html(user.id, user.first_name),
               mention_html(member.user.id, member.user.first_name),
               member.user.id,
               time_val,
           ))
    if reason:
        log += "\n<b>Reason:</b> {}".format(reason)

    try:
        chat.kick_member(user_id, until_date=bantime)

        message.reply_text(
            "Admin {} has successfully banned {} in <b>{}</b> for {}!".format(
                mention_html(user.id, user.first_name),
                mention_html(member.user.id, member.user.first_name),
                html.escape(chat.title), time_val),
            quote=False,
            parse_mode=ParseMode.HTML)
        return log

    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text(
                "Goodbye.. we'll meet after {}.".format(time_val), quote=False)
            return log
        else:
            LOGGER.warning(update)
            LOGGER.exception(
                "ERROR banning user %s in chat %s (%s) due to %s",
                user_id,
                chat.title,
                chat.id,
                excp.message,
            )
            message.reply_text("Well damn, I can't ban that user.")

    return ""