Beispiel #1
0
async def del_blacklist(c: Alita, m: Message):
    try:
        user_list = []
        approved_users = app_db.all_approved(m.chat.id)
        for auser in approved_users:
            user_list.append(int(auser.user_id))
        async for i in m.chat.iter_members(filter="administrators"):
            user_list.append(i.user.id)
        if m.from_user.id in user_list:
            del user_list  # Reset Admin list, just in case new admins are added!
            return
        if m.text:
            chat_filters = db.get_chat_blacklist(m.chat.id)
            if not chat_filters:
                return
            for trigger in chat_filters:
                pattern = r"( |^|[^\w])" + trigger + r"( |$|[^\w])"
                match = regex_searcher(pattern, m.text.lower())
                if not match:
                    continue
                if match:
                    try:
                        await m.delete()
                    except Exception as ef:
                        LOGGER.info(ef)
                    break
    except AttributeError:
        pass  # Skip attribute errors!
Beispiel #2
0
async def rm_blacklist(c: Alita, m: Message):

    res = await admin_check(c, m)
    if not res:
        return

    _ = GetLang(m).strs
    chat_bl = db.get_chat_blacklist(m.chat.id)
    if not isinstance(chat_bl, bool):
        pass
    else:
        if len(m.text.split()) >= 2:
            bl_word = m.text.split(None, 1)[1]
            if bl_word in chat_bl:
                db.rm_from_blacklist(m.chat.id, bl_word.lower())
                await m.reply_text(
                    _("blacklist.rm_blacklist").format(bl_word=bl_word))
                return
            await m.reply_text(
                _("blacklist.no_bl_found").format(bl_word=bl_word))
        else:
            await m.reply_text(
                _("general.check_help"),
                reply_to_message_id=m.message_id,
            )
    return
Beispiel #3
0
async def rm_blacklist(_, m: Message):

    chat_bl = db.get_chat_blacklist(m.chat.id)
    if not isinstance(chat_bl, bool):
        pass
    else:
        if len(m.text.split()) >= 2:
            bl_word = m.text.split(None, 1)[1]
            if bl_word in chat_bl:
                db.rm_from_blacklist(m.chat.id, bl_word.lower())
                await m.reply_text(
                    tlang(m, "blacklist.rm_blacklist").format(
                        bl_word=f"<code>{bl_word}</code>",
                    ),
                )
                return
            await m.reply_text(
                tlang(m, "blacklist.no_bl_found").format(
                    bl_word=f"<code>{bl_word}</code>",
                ),
            )
        else:
            await m.reply_text(
                tlang(m, "general.check_help"),
                reply_to_message_id=m.message_id,
            )
    return
Beispiel #4
0
async def view_blacklist(_, m: Message):

    chat_title = m.chat.title
    blacklists_chat = tlang(m, "blacklist.curr_blacklist_initial").format(
        chat_title=f"<b>{chat_title}</b>",
    )
    all_blacklisted = db.get_chat_blacklist(m.chat.id)

    if not all_blacklisted:
        await m.reply_text(
            tlang(m, "blacklist.no_blacklist").format(
                chat_title=f"<b>{chat_title}</b>",
            ),
        )
        return

    for trigger in all_blacklisted:
        blacklists_chat += f" • <code>{escape(trigger)}</code>\n"

    await m.reply_text(blacklists_chat, reply_to_message_id=m.message_id)
    return
Beispiel #5
0
async def view_blacklist(c: Alita, m: Message):

    res = await admin_check(c, m)
    if not res:
        return

    _ = GetLang(m).strs
    chat_title = m.chat.title
    blacklists_chat = _("blacklist.curr_blacklist_initial").format(
        chat_title=chat_title)
    all_blacklisted = db.get_chat_blacklist(m.chat.id)

    if not all_blacklisted:
        await m.reply_text(
            _("blacklist.no_blacklist").format(chat_title=chat_title))
        return

    for trigger in all_blacklisted:
        blacklists_chat += f" • <code>{html.escape(trigger)}</code>\n"

    await m.reply_text(blacklists_chat, reply_to_message_id=m.message_id)
    return