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 prevent_approved(c: Alita, m: Message):
    x = app_db.all_approved(m.chat.id)
    LOGGER.info(x)
    ul = []
    for j in x:
        ul.append(j.user_id)
    for i in ul:
        await c.restrict_chat_member(
            chat_id=m.chat.id,
            user_id=i,
            permissions=ChatPermissions(
                can_send_messages=True,
                can_send_media_messages=True,
                can_send_stickers=True,
                can_send_animations=True,
                can_send_games=True,
                can_use_inline_bots=True,
                can_add_web_page_previews=True,
                can_send_polls=True,
                can_change_info=True,
                can_invite_users=True,
                can_pin_messages=True,
            ),
        )
        LOGGER.info(f"Approved {i} in {m.chat.id}")
        await sleep(0.2)

    return
Beispiel #3
0
async def check_approved(c: Alita, m: Message):

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

    chat_title = m.chat.title
    chat = m.chat
    no_users = False
    msg = "The following users are approved:\n"
    x = db.all_approved(m.chat.id)

    for i in x:
        try:
            member = await chat.get_member(int(i.user_id))
        except:
            no_users = True
            break
        msg += f"- `{i.user_id}`: {mention_html(member.user['first_name'], int(i.user_id))}\n"
    if msg.endswith("approved:\n"):
        await m.reply_text(f"No users are approved in {chat_title}.")
        return
    else:
        await m.reply_text(msg)
        return
Beispiel #4
0
async def check_approved(_, m: Message):

    chat_title = m.chat.title
    chat = m.chat
    user_id = (await extract_user(m))[0]
    msg = "The following users are approved:\n"
    x = db.all_approved(m.chat.id)

    for i in x:
        try:
            member = await chat.get_member(int(i.user_id))
        except UserNotParticipant:
            db.disapprove(chat.id, user_id)
            continue
        msg += f"- `{i.user_id}`: {(await mention_html(member.user['first_name'], int(i.user_id)))}\n"
    if msg.endswith("approved:\n"):
        await m.reply_text(f"No users are approved in {chat_title}.")
        return
    await m.reply_text(msg)
    return