Beispiel #1
0
def del_blackliststicker(update: Update, context: CallbackContext):
    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 or not to_match.set_name:
        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,
                        "ഉപയോഗിക്കുന്ന ഈ '{}' സ്റ്ററ്റിക്കർ ബ്ലാക്ക്ലിസ്റ്റിൽ ഉൾപ്പെടുത്തിയതാണ്"
                        .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,
                        "{} നെ നിശബ്ദമാക്കി കാരണം ഉപയോഗിച്ച ഈ '{}' സ്റ്റിക്കർ ബ്ലാക്ക്ലിസ്റ്റിൽ ഉൾപ്പെട്ടുത്തിയതാണ്"
                        .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,
                            "{} നെ കിക്ക് ചെയ്തു കാരണം ഉപയോഗിച്ച ഈ '{}'സ്റ്റിക്കർ ബ്ലാക്ക്ലിസ്റ്റിൽ ഉൾപ്പെട്ടുത്തിയതാണ് "
                            .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,
                        "{} നെ നിരോധിച്ചിരിക്കുന്നു കാരണം ഉപയോഗിച്ച ഈ '{}' സ്റ്റിക്കർ ബ്ലാക്ക്ലിസ്റ്റിൽ ഉൾപ്പെട്ടുത്തിയതാണ്"
                        .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,
                        "{} നെ ബാൻ ചെയ്തു കാരണം {} ബ്ലാക്ക്ലിസ്റ്റ്-ൽ ഉൾപ്പെടുത്തിയ സ്റ്ററ്റിക്കർ ഉപയോഗിച്ചു '{}' ഏതൊക്കെയാണ് ബ്ലാക്ക്ലിസ്റ്റിൽ🤪"
                        .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,
                        "{} നെ നിശബ്ദമാക്കി കാരണം {} ബ്ലാക്ക്ലിസ്റ്റ്-ൽ ഉൾപ്പെടുത്തിയ സ്റ്ററ്റിക്കർ ഉപയോഗിച്ചു '{}' ഏതൊക്കെയാണ് ബ്ലാക്ക്ലിസ്റ്റിൽ🤪"
                        .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":
                    LOGGER.exception("Error while deleting blacklist message.")
                break
Beispiel #2
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]
    if not user:  # ignore channels
        return ""

    # ignore admins and whitelists
    if is_user_admin(chat, user.id) or user.id in WOLVES or user.id in TIGERS:
        sql.update_flood(chat.id, None)
        return ""
    # ignore approved users
    if is_approved(chat.id, 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, "Beep Boop! Boop Beep!\n{}!".format(execstrings)
        )

        return (
            "<b>{}:</b>"
            "\n#{}"
            "\n<b>User:</b> {}"
            "\nFlooded the group.".format(
                tag,
                html.escape(chat.title),
                mention_html(user.id, html.escape(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
            )
        )
Beispiel #3
0
def temp_ban(update: Update, context: CallbackContext) -> str:
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message
    log_message = ""
    bot, args = context.bot, context.args
    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("നിങ്ങൾ പറഞ്ഞ മെമ്പറെക്കുറിച്ച് എനിക്ക് ഒന്നും അറിയില്ല..")
        return log_message

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message != "നിങ്ങൾ പറഞ്ഞ മെമ്പറെ കണ്ടെത്താൻ കഴിയുന്നില്ല":
            raise
        message.reply_text("നിങ്ങൾ പറഞ്ഞ മെമ്പറെ ഞാൻ ഇതുവരെ കണ്ടിട്ടില്ല.")
        return log_message
    if user_id == bot.id:
        message.reply_text("ഭ... നിനക്ക് ഭ്രാന്ത് ആണോ? ഞാൻ എന്നെ തന്നെ ബാൻ ചെയ്യണം എന്നോ?..നടക്കില്ല മോനെ..")
        return log_message

    if is_user_ban_protected(chat, user_id, member):
        message.reply_text("എന്തോ? എങ്ങനെ?.")
        return log_message

    if not reason:
        message.reply_text("നിങ്ങൾ വ്യക്കമായ ഒരു കാരണം പറഞ്ഞാൽ മാത്രമേ, നിങ്ങൾ പറഞ്ഞത് പോലെ ആ കാരണം വെച്ച് എനിക്ക് ബാൻ ചെയ്യുവാൻ കഴിയുള്ളൂ..!")
        return log_message

    split_reason = reason.split(None, 1)

    time_val = split_reason[0].lower()
    reason = split_reason[1] if len(split_reason) > 1 else ""
    bantime = extract_time(message, time_val)

    if not bantime:
        return log_message

    log = (
        f"<b>{html.escape(chat.title)}:</b>\n"
        "#TEMP BANNED\n"
        f"<b>😹അഡ്മിൻ:</b> {mention_html(user.id, html.escape(user.first_name))}\n"
        f"<b>👤യൂസർ:</b> {mention_html(member.user.id, html.escape(member.user.first_name))}\n"
        f"<b>⏰️സമയം:</b> {time_val}"
    )
    if reason:
        log += "\n<b>📰കാരണം:</b> {}".format(reason)

    try:
        chat.kick_member(user_id, until_date=bantime)
        # bot.send_sticker(chat.id, BAN_STICKER)  # banhammer marie sticker
        bot.sendMessage(
            chat.id,
            f"Banned! User {mention_html(member.user.id, html.escape(member.user.first_name))} "
            f"will be banned for {time_val}.",
            parse_mode=ParseMode.HTML,
        )
        return log

    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text(
                f"ബാൻ ചെയ്തു! ഇയാൾ {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 log_message
Beispiel #4
0
def del_blacklist(update, context):
    chat = update.effective_chat
    message = update.effective_message
    user = update.effective_user
    bot = context.bot
    to_match = extract_text(message)
    if not to_match:
        return
    if is_approved(chat.id, user.id):
        return
    getmode, value = sql.get_blacklist_setting(chat.id)

    chat_filters = sql.get_chat_blacklist(chat.id)
    for trigger in chat_filters:
        pattern = r"( |^|[^\w])" + re.escape(trigger) + r"( |$|[^\w])"
        if re.search(pattern, to_match, flags=re.IGNORECASE):
            try:
                if getmode == 0:
                    return
                elif getmode == 1:
                    try:
                        message.delete()
                    except BadRequest:
                        pass
                elif getmode == 2:
                    try:
                        message.delete()
                    except BadRequest:
                        pass
                    warn(
                        update.effective_user,
                        chat,
                        ("ഉപയോഗിക്കുന്ന ബ്ലാക്ക്ലിസ്റ്റ് ട്രിഗർ: {}".format(trigger)),
                        message,
                        update.effective_user,
                    )
                    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,
                        f"{user.first_name} നെ നിശബ്ദം ആക്കിയതിൻ്റെ കാരണം ബ്ലാക്ക്ലിസ്റ്റ് പദം ഉപയോഗിച്ചു: {trigger}!",
                    )
                    return
                elif getmode == 4:
                    message.delete()
                    res = chat.unban_member(update.effective_user.id)
                    if res:
                        bot.sendMessage(
                            chat.id,
                            f"{user.first_name} നെ കിക്ക് ചെയ്തിതിൻ്റെ കാരണം ബ്ലാക്ക്ലിസ്റ്റ് പദം ഉപയോഗിച്ചു: {trigger}!",
                        )
                    return
                elif getmode == 5:
                    message.delete()
                    chat.kick_member(user.id)
                    bot.sendMessage(
                        chat.id,
                        f"{user.first_name} നെ ബാൻ ചെയ്തു കാരണം ബ്ലാക്ക്ലിസ്റ്റ് പദം ഉപയോഗിച്ചു: {trigger}",
                    )
                    return
                elif getmode == 6:
                    message.delete()
                    bantime = extract_time(message, value)
                    chat.kick_member(user.id, until_date=bantime)
                    bot.sendMessage(
                        chat.id,
                        f"നിശ്ചിത സമയത്തേക്ക് {user.first_name} ബാൻ ചെയ്തു. ബാൻ സമയം '{value}' ബാൻ ചെയ്യാൻ ഉള്ള കാരണം ബ്ലാക്ക്ലിസ്റ്റ് പദം ഉപയോഗിച്ചു: {trigger}!",
                    )
                    return
                elif getmode == 7:
                    message.delete()
                    mutetime = extract_time(message, value)
                    bot.restrict_chat_member(
                        chat.id,
                        user.id,
                        until_date=mutetime,
                        permissions=ChatPermissions(can_send_messages=False),
                    )
                    bot.sendMessage(
                        chat.id,
                        f"നിശ്ചിത സമയത്തേക്ക് {user.first_name} നെ മ്യൂട്ട് ആക്കി. മ്യൂട്ട് സമയം.'{value}' മ്യൂട്ട് ചെയ്യാൻ ഉള്ള കാരണം ബ്ലാക്ക്ലിസ്റ്റ് പദം ഉപയോഗിച്ചു: {trigger}!",
                    )
                    return
            except BadRequest as excp:
                if excp.message != "ഡിലിറ്റ് ചെയ്യാൻ ഉള്ള സന്ദേശം ലിച്ചില്ല.":
                    LOGGER.exception("സന്ദേശങ്ങൾ ഇല്ലാതാക്കാൻ പറ്റുന്നില്ല.")
            break
Beispiel #5
0
def blacklist_mode(update, context):
    chat = update.effective_chat
    user = update.effective_user
    msg = update.effective_message
    args = context.args

    conn = connected(context.bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if update.effective_message.chat.type == "private":
            send_message(
                update.effective_message,
                "ഈ കമാൻഡ് പി.എം അല്ല ഗ്രൂപ്പിൽ ആണ് ഉപയോഗിക്കേണ്ടത്.",
            )
            return ""
        chat = update.effective_chat
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title

    if args:
        if args[0].lower() in ["off", "nothing", "no"]:
            settypeblacklist = "do nothing"
            sql.set_blacklist_strength(chat_id, 0, "0")
        elif args[0].lower() in ["del", "delete"]:
            settypeblacklist = "delete blacklisted message"
            sql.set_blacklist_strength(chat_id, 1, "0")
        elif args[0].lower() == "warn":
            settypeblacklist = "warn the sender"
            sql.set_blacklist_strength(chat_id, 2, "0")
        elif args[0].lower() == "mute":
            settypeblacklist = "mute the sender"
            sql.set_blacklist_strength(chat_id, 3, "0")
        elif args[0].lower() == "kick":
            settypeblacklist = "kick the sender"
            sql.set_blacklist_strength(chat_id, 4, "0")
        elif args[0].lower() == "ban":
            settypeblacklist = "ban the sender"
            sql.set_blacklist_strength(chat_id, 5, "0")
        elif args[0].lower() == "tban":
            if len(args) == 1:
                teks = """ നിങ്ങൾ അയച്ച ഫോർമാക്റ്റ് തെറ്റ് ആണ്. ബ്ലാക്ക്ലിസ്റ്റ് മോഡ് തന്നിരിക്കുന്ന രീതിയിൽ സെറ്റ് ചെയു ;Try, `/blacklistmode tban <timevalue>`.
				
Examples of time value: 4m = 4 minutes, 3h = 3 hours, 6d = 6 days, 5w = 5 weeks."""
                send_message(update.effective_message, teks, parse_mode="markdown")
                return ""
            restime = extract_time(msg, args[1])
            if not restime:
                teks = """Invalid time value!
Example of time value: 4m = 4 minutes, 3h = 3 hours, 6d = 6 days, 5w = 5 weeks."""
                send_message(update.effective_message, teks, parse_mode="markdown")
                return ""
            settypeblacklist = "{} വരെ താൽക്കാലിക നിരോധനം".format(args[1])
            sql.set_blacklist_strength(chat_id, 6, str(args[1]))
        elif args[0].lower() == "tmute":
            if len(args) == 1:
                teks = """ബ്ലാക്ക്ലിസ്റ്റ് മോഡ് തന്നിരിക്കുന്ന രീതിയിൽ സെറ്റ് ചെയു ;try, `/blacklistmode tmute <timevalue>`.

Examples of time value: 4m = 4 minutes, 3h = 3 hours, 6d = 6 days, 5w = 5 weeks."""
                send_message(update.effective_message, teks, parse_mode="markdown")
                return ""
            restime = extract_time(msg, args[1])
            if not restime:
                teks = """Invalid time value!
Examples of time value: 4m = 4 minutes, 3h = 3 hours, 6d = 6 days, 5w = 5 weeks."""
                send_message(update.effective_message, teks, parse_mode="markdown")
                return ""
            settypeblacklist = "{} താല്കാലിക നിശബ്ദംദം.".format(args[1])
            sql.set_blacklist_strength(chat_id, 7, str(args[1]))
        else:
            send_message(
                update.effective_message,
                "നിങ്ങൾ പറഞ്ഞത് എന്നിക്ക് മനസ്സിലായില്ല: off/del/warn/ban/kick/mute/tban/tmute!",
            )
            return ""
        if conn:
            text = "ബ്ലാക്ക്ലിസ്റ്റ് മോഡ് ചെയ്ഞ്ച് ആക്കി: `{}` ടൂ' *{}*!".format(
                settypeblacklist, chat_name
            )
        else:
            text = "ബ്ലാക്ക്ലിസ്റ്റ് മോഡ് ചെയ്ഞ്ച് ആക്കി: `{}`!".format(settypeblacklist)
        send_message(update.effective_message, text, parse_mode="markdown")
        return (
            "<b>{}:</b>\n"
            "<b> അഡ്മിൻ:</b> {}\n"
            "ബ്ലാക്ക്ലിസ്റ്റ് മോഡ് മാറ്റി. ഇപ്പോൾ നിലവിലുള്ള മോഡ്{}.".format(
                html.escape(chat.title),
                mention_html(user.id, html.escape(user.first_name)),
                settypeblacklist,
            )
        )
    else:
        getmode, getvalue = sql.get_blacklist_setting(chat.id)
        if getmode == 0:
            settypeblacklist = "do nothing"
        elif getmode == 1:
            settypeblacklist = "delete"
        elif getmode == 2:
            settypeblacklist = "warn"
        elif getmode == 3:
            settypeblacklist = "mute"
        elif getmode == 4:
            settypeblacklist = "kick"
        elif getmode == 5:
            settypeblacklist = "ban"
        elif getmode == 6:
            settypeblacklist = "{} വരെ താൽക്കാലിക നിരോധനം".format(getvalue)
        elif getmode == 7:
            settypeblacklist = "{} വരെ താൽക്കാലിക നിശബ്ദംദം ".format(getvalue)
        if conn:
            text = "ഇപ്പോഴത്തെ ബ്ലാക്ക്ലിസ്റ്റ് മോഡ്: *{}* ടൂ *{}*.".format(
                settypeblacklist, chat_name
            )
        else:
            text = " ഇപ്പോഴത്തെ ബ്ലാക്ക്ലിസ്റ്റ് മോഡ്: *{}*.".format(settypeblacklist)
        send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN)
    return ""
Beispiel #6
0
def temp_mute(update: Update, context: CallbackContext) -> str:
    bot, args = context.bot, context.args
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message

    user_id, reason = extract_user_and_text(message, args)
    reply = check_user(user_id, bot, chat)

    if reply:
        message.reply_text(reply)
        return ""

    member = chat.get_member(user_id)

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

    try:
        if member.can_send_messages is None or member.can_send_messages:
            chat_permissions = ChatPermissions(can_send_messages=False)
            bot.restrict_chat_member(
                chat.id, user_id, chat_permissions, until_date=mutetime
            )
            bot.sendMessage(
                chat.id,
                f"Muted <b>{html.escape(member.user.first_name)}</b> for {time_val}!",
                parse_mode=ParseMode.HTML,
            )
            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(f"Muted for {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 ""