示例#1
0
async def get_invalid_gban(c: Alita, _, remove: bool = False):
    banned = gban_db.get_gban_list()
    ungbanned_users = 0
    ungban_list = []

    for user in banned:
        user_id = user["user_id"]
        await sleep(0.1)
        try:
            await c.get_users(user_id)
        except BadRequest:
            ungbanned_users += 1
            ungban_list.append(user_id)
        except RPCError:
            pass

    if remove:
        for user_id in ungban_list:
            try:
                await sleep(0.1)
                gban_db.ungban_user(user_id)
            except RPCError:
                pass

    return ungbanned_users
示例#2
0
async def ungban(c: Alita, m: Message):

    if len(m.text.split()) == 1:
        await m.reply_text("Pass a user id or username as an argument!")
        return

    user_id, user_first_name = await extract_user(m)
    me = await c.get_me()

    if user_id in SUPPORT_STAFF:
        await m.reply_text(
            "They can't be banned, so how am I supposed to ungban them?")
        return

    if user_id == me.id:
        await m.reply_text("Nice Try...!")
        return

    if db.is_user_gbanned(user_id):
        db.ungban_user(user_id)
        await m.reply_text(f"Removed {user_first_name} from Global Ban List.")
        log_msg = (
            f"#UNGBAN\n"
            f"<b>Originated from:</b> {m.chat.id}\n"
            f"<b>Admin:</b> {(await mention_html(m.from_user.first_name, m.from_user.id))}\n"
            f"<b>UnGbanned User:</b> {(await mention_html(user_first_name, user_id))}\n"
            f"<b>UnGbanned User ID:</b> {user_id}\n"
            f"<b>Event Stamp:</b> {datetime.utcnow().strftime('%H:%M - %d-%m-%Y')}"
        )
        await c.send_message(MESSAGE_DUMP, log_msg)
        try:
            # Send message to user telling that he's ungbanned
            await c.send_message(
                user_id,
                "You have been removed from my global ban list!\n",
            )
        except BaseException:  # TODO: Improve Error Detection
            pass
        return

    await m.reply_text("User is not gbanned!")
    return