Example #1
0
def add_fvrtsticker(update, context):
    bot = context.bot
    message = update.effective_message
    chat = update.effective_chat
    user = update.effective_user
    args = context.args
    query = " ".join(args)
    if message.reply_to_message and message.reply_to_message.sticker:
        get_s_name = message.reply_to_message.sticker.set_name
        if not query:
            get_s_name_title = get_s_name
        else:
            get_s_name_title = query
        if get_s_name is None:
            message.reply_text("Sticker is invalid!")
        sticker_url = f"https://t.me/addstickers/{get_s_name}"
        sticker_m = "<a href='{}'>{}</a>".format(sticker_url, get_s_name_title)
        check_pack = REDIS.hexists(f'fvrt_stickers2_{user.id}',
                                   get_s_name_title)
        if check_pack == False:
            REDIS.hset(f'fvrt_stickers2_{user.id}', get_s_name_title,
                       sticker_m)
            message.reply_text(
                f"<code>{sticker_m}</code> has been succesfully added into your favorite sticker packs list!",
                parse_mode=ParseMode.HTML)
        else:
            message.reply_text(
                f"<code>{sticker_m}</code> is already exist in your favorite sticker packs list!",
                parse_mode=ParseMode.HTML)

    else:
        message.reply_text('Reply to any sticker!')
Example #2
0
def tagg_all_button(update, context):
    query = update.callback_query
    chat = update.effective_chat  
    splitter = query.data.split('=')
    query_match = splitter[0]
    user_id = splitter[1]
    if query_match == "tagall_accept":
        if query.from_user.id == int(user_id):
            member = chat.get_member(int(user_id))
            chat_id = str(chat.id)[1:]
            REDIS.sadd(f'tagall2_{chat_id}', mention_html(member.user.id, member.user.first_name))
            query.message.edit_text(
                "{} is accepted! to add yourself {}'s tag list.".format(mention_html(member.user.id, member.user.first_name),
                                                                        chat.title),
                parse_mode=ParseMode.HTML
            )
            
        else:
            context.bot.answer_callback_query(query.id,
                                              text="You're not the user being added in tag list!"
                                              )
    elif query_match == "tagall_dicline":
        if query.from_user.id == int(user_id):
            member = chat.get_member(int(user_id))
            query.message.edit_text(
                "{} is deslined! to add yourself {}'s tag list.".format(mention_html(member.user.id, member.user.first_name),
                                                                        chat.title),
                parse_mode=ParseMode.HTML
            )
        else:
            context.bot.answer_callback_query(query.id,
                                              text="You're not the user being added in tag list!"
                                              )           
Example #3
0
def afk(update, context):
    args = update.effective_message.text.split(None, 1)
    user = update.effective_user
    if not user:  # ignore channels
        return

    if user.id == 777000:
        return
    start_afk_time = time.time()
    if len(args) >= 2:
        reason = args[1]
    else:
        reason = "none"
    start_afk(update.effective_user.id, reason)
    REDIS.set(f'afk_time_{update.effective_user.id}', start_afk_time)
    fname = update.effective_user.first_name
    try:
        sett_afkk = update.effective_message.reply_text(
            "User <b>{}</b> Is Now AFK!".format(fname), parse_mode="html")
        sleep(15)
        try:
            sett_afkk.delete()
        except BadRequest:
            pass
    except BadRequest:
        pass
Example #4
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)
Example #5
0
def no_longer_afk(update, context):
    user = update.effective_user
    message = update.effective_message
    if not user:  # ignore channels
        return

    if not is_user_afk(user.id):  #Check if user is afk or not
        return
    end_afk_time = get_readable_time(
        (time.time() - float(REDIS.get(f'afk_time_{user.id}'))))
    REDIS.delete(f'afk_time_{user.id}')
    res = end_afk(user.id)
    if res:
        if message.new_chat_members:  #dont say msg
            return
        firstname = update.effective_user.first_name
        try:
            rm_afkk = message.reply_text(
                "User <b>{}</b> Is No Longer AFK!\nYou Were AFK: <code>{}</code>"
                .format(firstname, end_afk_time),
                parse_mode="html")
            sleep(30)
            try:
                rm_afkk.delete()
            except BadRequest:
                pass
        except Exception:
            return
Example #6
0
def unapprove(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 approve or unapprove myself")
        return
    chat_id = str(chat.id)[1:]
    approve_list = list(REDIS.sunion(f'approve_list_{chat_id}'))
    target_user = mention_html(member.user.id, member.user.first_name)
    if target_user not in approve_list:
        message.reply_text("{} isn't approved yet.".format(
            mention_html(member.user.id, member.user.first_name)),
                           parse_mode=ParseMode.HTML)
        return
    member = chat.get_member(int(user_id))
    chat_id = str(chat.id)[1:]
    REDIS.srem(f'approve_list_{chat_id}',
               mention_html(member.user.id, member.user.first_name))
    message.reply_text("{} is no longer approved in {}.".format(
        mention_html(member.user.id, member.user.first_name), chat.title),
                       parse_mode=ParseMode.HTML)
Example #7
0
def untagall(update, context):
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message
    chat_id = str(chat.id)[1:]
    tagall_list = list(REDIS.sunion(f'tagall2_{chat_id}'))
    for tag_user in tagall_list:
        REDIS.srem(f'tagall2_{chat_id}', tag_user)
    message.reply_text(
        "Successully removed all users from {}'s tag list.".format(chat.title))
Example #8
0
def unapproveall(update, context):
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message
    chat_id = str(chat.id)[1:]
    approve_list = list(REDIS.sunion(f'approve_list_{chat_id}'))
    for target_user in approve_list:
        REDIS.srem(f'approve_list_{chat_id}', target_user)
    message.reply_text("Successully unapproved all users from {}.".format(
        chat.title))
Example #9
0
def tagme(update, context):
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message
    chat_id = str(chat.id)[1:]
    tagall_list = list(REDIS.sunion(f'tagall2_{chat_id}'))
    match_user = mention_html(user.id, user.first_name)
    if match_user in tagall_list:
        message.reply_text("You're Already Exist In {}'s Tag List!".format(
            chat.title))
        return
    REDIS.sadd(f'tagall2_{chat_id}', mention_html(user.id, user.first_name))
    message.reply_text(
        "{} has been successfully added in {}'s tag list.".format(
            mention_html(user.id, user.first_name), chat.title),
        parse_mode=ParseMode.HTML)
Example #10
0
def untagme(update, context):
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message
    chat_id = str(chat.id)[1:]
    tagall_list = list(REDIS.sunion(f'tagall2_{chat_id}'))
    match_user = mention_html(user.id, user.first_name)
    if match_user not in tagall_list:
        message.reply_text(
            "You're already doesn't exist in {}'s tag list!".format(
                chat.title))
        return
    REDIS.srem(f'tagall2_{chat_id}', mention_html(user.id, user.first_name))
    message.reply_text("{} has been removed from {}'s tag list.".format(
        mention_html(user.id, user.first_name), chat.title),
                       parse_mode=ParseMode.HTML)
Example #11
0
def check_afk(update, context, user_id, fst_name, userc_id):
    if is_user_afk(user_id):
        reason = afk_reason(user_id)
        since_afk = get_readable_time(
            (time.time() - float(REDIS.get(f'afk_time_{user_id}'))))
        if reason == "none":
            if int(userc_id) == int(user_id):
                return
            res = "User <b>{}</b> Is Currently AFK!\n\nLast Seen: <code>{}</code>".format(
                fst_name, since_afk)
            reply_afkk = update.effective_message.reply_text(res,
                                                             parse_mode="html")
            sleep(60)
            try:
                reply_afkk.delete()
            except BadRequest:
                pass
        else:
            if int(userc_id) == int(user_id):
                return
            res = "User <b>{}</b> Is Currently AFK! \nSays It's Because Of:\n{}\n\nLast Seen: <code>{}</code>".format(
                fst_name, reason, since_afk)
            replly_afkk = update.effective_message.reply_text(
                res, parse_mode="html")
            sleep(60)
            try:
                replly_afkk.delete()
            except BadRequest:
                pass
Example #12
0
def tagall(update, context):
    chat = update.effective_chat 
    user = update.effective_user 
    message = update.effective_message
    args = context.args
    query = " ".join(args)
    if not query:
        message.reply_text("Please give a reason why are you want to tag all!")
        return
    chat_id = str(chat.id)[1:] 
    tagall = list(REDIS.sunion(f'tagall2_{chat_id}'))
    tagall.sort()
    tagall = ", ".join(tagall)
    
    if tagall:
        tagall_reason = query 
        if message.reply_to_message:
            message.reply_to_message.reply_text(
                "{}"
                "\n\n<b>• Tagged Reason : </b>"
                "\n{}".format(tagall, tagall_reason),
                parse_mode=ParseMode.HTML
            )
        else:
            message.reply_text(
                "{}"
                "\n\n<b>• Tagged Reason : </b>"
                "\n{}".format(tagall, tagall_reason),
                parse_mode=ParseMode.HTML
            )
    else:
        message.reply_text(
            "Tagall list is empty!"
        )
Example #13
0
def animestuffs(update, context):
    query = update.callback_query
    user = update.effective_user
    splitter = query.data.split('=')
    query_match = splitter[0]
    callback_anime_data = splitter[1]
    if query_match == "xanime_watchlist":
        watchlist = list(REDIS.sunion(f'anime_watch_list{user.id}'))
        if not callback_anime_data in watchlist:
            REDIS.sadd(f'anime_watch_list{user.id}', callback_anime_data)
            context.bot.answer_callback_query(
                query.id,
                text=
                f"{callback_anime_data} is successfully added to your watch list.",
                show_alert=True)
        else:
            context.bot.answer_callback_query(
                query.id,
                text=
                f"{callback_anime_data} is already exists in your watch list!",
                show_alert=True)

    elif query_match == "xanime_fvrtchar":
        fvrt_char = list(REDIS.sunion(f'anime_fvrtchar{user.id}'))
        if not callback_anime_data in fvrt_char:
            REDIS.sadd(f'anime_fvrtchar{user.id}', callback_anime_data)
            context.bot.answer_callback_query(
                query.id,
                text=
                f"{callback_anime_data} is successfully added to your favorite character.",
                show_alert=True)
        else:
            context.bot.answer_callback_query(
                query.id,
                text=
                f"{callback_anime_data} is already exists in your favorite characters list!",
                show_alert=True)
    elif query_match == "xanime_manga":
        fvrt_char = list(REDIS.sunion(f'anime_mangaread{user.id}'))
        if not callback_anime_data in fvrt_char:
            REDIS.sadd(f'anime_mangaread{user.id}', callback_anime_data)
            context.bot.answer_callback_query(
                query.id,
                text=
                f"{callback_anime_data} is successfully added to your favorite character.",
                show_alert=True)
        else:
            context.bot.answer_callback_query(
                query.id,
                text=
                f"{callback_anime_data} is already exists in your favorite characters list!",
                show_alert=True)
Example #14
0
def remove_fvrtsticker(update, context):
    message = update.effective_message
    chat = update.effective_chat
    user = update.effective_user
    args = context.args
    del_stick = " ".join(args)
    if not del_stick:
        message.reply_text(
            "Please give a your favorite sticker pack name to remove from your list."
        )
        return
    del_check = REDIS.hexists(f'fvrt_stickers2_{user.id}', del_stick)
    if not del_check == False:
        REDIS.hdel(f'fvrt_stickers2_{user.id}', del_stick)
        message.reply_text(
            f"<code>{del_stick}</code> has been succesfully deleted from your list.",
            parse_mode=ParseMode.HTML)
    else:
        message.reply_text(
            f"<code>{del_stick}</code> doesn't exist in your favorite sticker pack list.",
            parse_mode=ParseMode.HTML)
Example #15
0
def removewatchlist(update, context):
    user = update.effective_user
    message = update.effective_message
    removewlist = message.text.split(' ', 1)
    args = context.args
    query = " ".join(args)
    if not query:
        message.reply_text(
            "Please enter a anime name to remove from your watchlist.")
        return
    watchlist = list(REDIS.sunion(f'anime_watch_list{user.id}'))
    removewlist = removewlist[1]

    if removewlist not in watchlist:
        message.reply_text(
            f"<code>{removewlist}</code> doesn't exist in your watch list.",
            parse_mode=ParseMode.HTML)
    else:
        message.reply_text(
            f"<code>{removewlist}</code> has been removed from your watch list.",
            parse_mode=ParseMode.HTML)
        REDIS.srem(f'anime_watch_list{user.id}', removewlist)
Example #16
0
def list_fvrtsticker(update, context):
    message = update.effective_message
    chat = update.effective_chat
    user = update.effective_user
    fvrt_stickers_list = REDIS.hvals(f'fvrt_stickers2_{user.id}')
    fvrt_stickers_list.sort()
    fvrt_stickers_list = "\n• ".join(fvrt_stickers_list)
    if fvrt_stickers_list:
        message.reply_text("{}'s favorite sticker packs:\n• {}".format(
            user.first_name, fvrt_stickers_list),
                           parse_mode=ParseMode.HTML)
    else:
        message.reply_text("You haven't added any sticker yet.")
Example #17
0
def removemangalist(update, context):
    user = update.effective_user
    message = update.effective_message
    removewlist = message.text.split(' ', 1)
    args = context.args
    query = " ".join(args)
    if not query:
        message.reply_text(
            "Please enter a manga name to remove from your manga list.")
        return
    fvrt_char = list(REDIS.sunion(f'anime_mangaread{user.id}'))
    removewlist = removewlist[1]

    if removewlist not in fvrt_char:
        message.reply_text(
            f"<code>{removewlist}</code> doesn't exist in your manga list.",
            parse_mode=ParseMode.HTML)
    else:
        message.reply_text(
            f"<code>{removewlist}</code> has been removed from your favorite characters list.",
            parse_mode=ParseMode.HTML)
        REDIS.srem(f'anime_mangaread{user.id}', removewlist)
Example #18
0
def readmanga(update, context):
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message
    manga_list = list(REDIS.sunion(f'anime_mangaread{user.id}'))
    manga_list.sort()
    manga_list = "\n• ".join(manga_list)
    if manga_list:
        message.reply_text("{}<b>'s Manga Lists:</b>"
                           "\n• {}".format(
                               mention_html(user.id, user.first_name),
                               manga_list),
                           parse_mode=ParseMode.HTML)
    else:
        message.reply_text("You havn't added anything in your manga list!")
Example #19
0
def watchlist(update, context):
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message
    watchlist = list(REDIS.sunion(f'anime_watch_list{user.id}'))
    watchlist.sort()
    watchlist = "\n• ".join(watchlist)
    if watchlist:
        message.reply_text("{}<b>'s Watchlist:</b>"
                           "\n• {}".format(
                               mention_html(user.id, user.first_name),
                               watchlist),
                           parse_mode=ParseMode.HTML)
    else:
        message.reply_text("You havn't added anything in your watchlist!")
Example #20
0
def fvrtchar(update, context):
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message
    fvrt_char = list(REDIS.sunion(f'anime_fvrtchar{user.id}'))
    fvrt_char.sort()
    fvrt_char = "\n• ".join(fvrt_char)
    if fvrt_char:
        message.reply_text("{}<b>'s Favorite Characters List:</b>"
                           "\n• {}".format(
                               mention_html(user.id, user.first_name),
                               fvrt_char),
                           parse_mode=ParseMode.HTML)
    else:
        message.reply_text(
            "You havn't added anything in your favorite characters list!")
Example #21
0
def approved(update, context):
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message
    chat_id = str(chat.id)[1:]
    approved_list = list(REDIS.sunion(f'approve_list_{chat_id}'))
    approved_list.sort()
    approved_list = ", ".join(approved_list)

    if approved_list:
        message.reply_text("The Following Users Are Approved: \n"
                           "{}".format(approved_list),
                           parse_mode=ParseMode.HTML)
    else:
        message.reply_text("No users are are approved in {}.".format(
            chat.title),
                           parse_mode=ParseMode.HTML)
Example #22
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
    )
Example #23
0
def approvel(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 approve myself")
        return

    chat_id = str(chat.id)[1:]
    approve_list = list(REDIS.sunion(f'approve_list_{chat_id}'))
    target_user = mention_html(member.user.id, member.user.first_name)
    if target_user in approve_list:
        message.reply_text(
            "{} is an approved user. Locks, antiflood, and blocklists won't apply to them."
            .format(mention_html(member.user.id, member.user.first_name)),
            parse_mode=ParseMode.HTML)
        return

    if target_user not in approve_list:
        message.reply_text(
            "{} is not an approved user. They are affected by normal commands."
            .format(mention_html(member.user.id, member.user.first_name)),
            parse_mode=ParseMode.HTML)
        return
Example #24
0
def is_user_afk(userid):
    afk = REDIS.get(f'is_afk_{userid}')
    if afk:
        return True
    else:
        return False
Example #25
0
def end_afk(userid):
    REDIS.delete(f'is_afk_{userid}')
    return True
Example #26
0
def afk_reason(userid):
    return strb(REDIS.get(f'is_afk_{userid}'))
Example #27
0
def start_afk(userid, reason):
    REDIS.set(f'is_afk_{userid}', reason)
def del_blackliststicker(update, context):
    bot = context.bot
    chat = update.effective_chat  # type: Optional[Chat]
    message = update.effective_message  # type: Optional[Message]
    user = update.effective_user
    to_match = message.sticker
    if not to_match:
        return


    chat_id = str(chat.id)[1:] 
    approve_list = list(REDIS.sunion(f'approve_list_{chat_id}'))
    target_user = mention_html(user.id, user.first_name)
    if target_user in approve_list:
        return

    bot = context.bot
    getmode, value = sql.get_blacklist_setting(chat.id)

    chat_filters = sql.get_chat_stickers(chat.id)
    for trigger in chat_filters:
        if to_match.set_name.lower() == trigger.lower():
            try:
                if getmode == 0:
                    return
                elif getmode == 1:
                    message.delete()
                elif getmode == 2:
                    message.delete()
                    warn(
                        update.effective_user,
                        chat,
                        "Using sticker '{}' which in blacklist stickers".format(
                            trigger),
                        message,
                        update.effective_user,
                        conn=False)
                    return
                elif getmode == 3:
                    message.delete()
                    bot.restrict_chat_member(
                        chat.id,
                        update.effective_user.id,
                        permissions=ChatPermissions(can_send_messages=False))
                    bot.sendMessage(
                        chat.id,
                        "{} muted because using '{}' which in blacklist stickers"
                        .format(
                            mention_markdown(user.id, user.first_name),
                            trigger),
                        parse_mode="markdown")
                    return
                elif getmode == 4:
                    message.delete()
                    res = chat.unban_member(update.effective_user.id)
                    if res:
                        bot.sendMessage(
                            chat.id,
                            "{} kicked because using '{}' which in blacklist stickers"
                            .format(
                                mention_markdown(user.id, user.first_name),
                                trigger),
                            parse_mode="markdown")
                    return
                elif getmode == 5:
                    message.delete()
                    chat.kick_member(user.id)
                    bot.sendMessage(
                        chat.id,
                        "{} banned because using '{}' which in blacklist stickers"
                        .format(
                            mention_markdown(user.id, user.first_name),
                            trigger),
                        parse_mode="markdown")
                    return
                elif getmode == 6:
                    message.delete()
                    bantime = extract_time(message, value)
                    chat.kick_member(user.id, until_date=bantime)
                    bot.sendMessage(
                        chat.id,
                        "{} banned for {} because using '{}' which in blacklist stickers"
                        .format(
                            mention_markdown(user.id, user.first_name), value,
                            trigger),
                        parse_mode="markdown")
                    return
                elif getmode == 7:
                    message.delete()
                    mutetime = extract_time(message, value)
                    bot.restrict_chat_member(
                        chat.id,
                        user.id,
                        permissions=ChatPermissions(
                            can_send_messages=False, until_date=mutetime))
                    bot.sendMessage(
                        chat.id,
                        "{} muted for {} because using '{}' which in blacklist stickers"
                        .format(
                            mention_markdown(user.id, user.first_name), value,
                            trigger),
                        parse_mode="markdown")
                    return
            except BadRequest as excp:
                if excp.message == "Message to delete not found":
                    pass
                else:
                    LOGGER.exception("Error while deleting blacklist message.")
                break
Example #29
0
def is_user_afk(userid):
    rget = REDIS.get(f'is_afk_{userid}')
    if rget:
        return True
    else:
        return False
Example #30
0
def check_flood(update, context) -> str:
    user = update.effective_user  # type: Optional[User]
    chat = update.effective_chat  # type: Optional[Chat]
    msg = update.effective_message  # type: Optional[Message]

    chat_id = str(chat.id)[1:]
    approve_list = list(REDIS.sunion(f'approve_list_{chat_id}'))
    target_user = mention_html(user.id, user.first_name)
    if target_user in approve_list:
        return

    if not user:  # ignore channels
        return ""

    # ignore admins
    if is_user_admin(chat, user.id):
        sql.update_flood(chat.id, None)
        return ""

    should_ban = sql.update_flood(chat.id, user.id)
    if not should_ban:
        return ""

    try:
        getmode, getvalue = sql.get_flood_setting(chat.id)
        if getmode == 1:
            chat.kick_member(user.id)
            execstrings = "Banned"
            tag = "BANNED"
        elif getmode == 2:
            chat.kick_member(user.id)
            chat.unban_member(user.id)
            execstrings = "Kicked"
            tag = "KICKED"
        elif getmode == 3:
            context.bot.restrict_chat_member(
                chat.id,
                user.id,
                permissions=ChatPermissions(can_send_messages=False))
            execstrings = "Muted"
            tag = "MUTED"
        elif getmode == 4:
            bantime = extract_time(msg, getvalue)
            chat.kick_member(user.id, until_date=bantime)
            execstrings = "Banned for {}".format(getvalue)
            tag = "TBAN"
        elif getmode == 5:
            mutetime = extract_time(msg, getvalue)
            context.bot.restrict_chat_member(
                chat.id,
                user.id,
                until_date=mutetime,
                permissions=ChatPermissions(can_send_messages=False),
            )
            execstrings = "Muted for {}".format(getvalue)
            tag = "TMUTE"
        send_message(
            update.effective_message,
            "Great, I like to leave flooding to staff members but you, "
            "you were just a disappointment. {}!".format(execstrings),
        )

        return ("<b>{}:</b>"
                "\n#{}"
                "\n<b>User:</b> {}"
                "\nFlooded the group.".format(
                    html.escape(chat.title), tag,
                    mention_html(user.id, user.first_name)))

    except BadRequest:
        msg.reply_text(
            "I can't restrict people here, give me permissions first! Until then, I'll disable anti-flood."
        )
        sql.set_flood(chat.id, 0)
        return (
            "<b>{}:</b>"
            "\n#INFO"
            "\nDon't have enough permission to restrict users so automatically disabled anti-flood"
            .format(chat.title))