Exemple #1
0
async def unmute_usr(c: Alita, m: Message):
    from alita import BOT_ID

    if len(m.text.split()) == 1 and not m.reply_to_message:
        await m.reply_text("I can't unmute nothing!")
        return

    user_id, user_first_name, _ = await extract_user(c, m)

    if user_id == BOT_ID:
        await m.reply_text(
            "Huh, why would I unmute myself if you are using me?")
        return

    try:
        await m.chat.restrict_member(user_id, m.chat.permissions)
        LOGGER.info(f"{m.from_user.id} unmuted {user_id} in {m.chat.id}")
        await m.reply_text((tlang(m, "admin.unmute.unmuted_user")).format(
            admin=(await mention_html(m.from_user.first_name, m.from_user.id)),
            unmuted=(await mention_html(user_first_name, user_id)),
        ), )
    except ChatAdminRequired:
        await m.reply_text(tlang(m, "admin.not_admin"))
    except UserNotParticipant:
        await m.reply_text(
            "How can I unmute a user who is not a part of this chat?")
    except RightForbidden:
        await m.reply_text(tlang(m, "admin.unmute.bot_no_right"))
    except RPCError as ef:
        await m.reply_text((tlang(m, "general.some_error")).format(
            SUPPORT_GROUP=SUPPORT_GROUP,
            ef=ef,
        ), )
        LOGGER.error(ef)
    return
Exemple #2
0
async def reload_admins(_, m: Message):
    global TEMP_ADMIN_CACHE_BLOCK

    if m.chat.type != "supergroup":
        return await m.reply_text(
            "This command is made to be used in groups only!", )

    if ((m.chat.id in set(TEMP_ADMIN_CACHE_BLOCK.keys()))
            and (m.from_user.id not in SUPPORT_STAFF)
            and TEMP_ADMIN_CACHE_BLOCK[m.chat.id] == "manualblock"):
        await m.reply_text("Can only reload admin cache once per 10 mins!")
        return

    try:
        await admin_cache_reload(m, "admincache")
        TEMP_ADMIN_CACHE_BLOCK[m.chat.id] = "manualblock"
        await m.reply_text(tlang(m, "admin.adminlist.reloaded_admins"))
        LOGGER.info(f"Admincache cmd use in {m.chat.id} by {m.from_user.id}")
    except RPCError as ef:
        await m.reply_text((tlang(m, "general.some_error")).format(
            SUPPORT_GROUP=SUPPORT_GROUP,
            ef=ef,
        ), )
        LOGGER.error(ef)
        LOGGER.error(format_exc())
    return
Exemple #3
0
async def get_invitelink(c: Alita, m: Message):
    # Bypass the bot devs, sudos and owner
    if m.from_user.id not in DEV_LEVEL:
        user = await m.chat.get_member(m.from_user.id)

        if not user.can_invite_users and user.status != "creator":
            await m.reply_text(tlang(m, "admin.no_user_invite_perm"))
            return False

    try:
        link = await c.export_chat_invite_link(m.chat.id)
        await m.reply_text(
            (tlang(m, "admin.invitelink")).format(
                chat_name=m.chat.id,
                link=link,
            ),
            disable_web_page_preview=True,
        )
        LOGGER.info(f"{m.from_user.id} exported invite link in {m.chat.id}")
    except ChatAdminRequired:
        await m.reply_text(tlang(m, "admin.not_admin"))
    except ChatAdminInviteRequired:
        await m.reply_text(tlang(m, "admin.no_invite_perm"))
    except RightForbidden:
        await m.reply_text(tlang(m, "admin.no_user_invite_perm"))
    except RPCError as ef:
        await m.reply_text((tlang(m, "general.some_error")).format(
            SUPPORT_GROUP=SUPPORT_GROUP,
            ef=ef,
        ), )
        LOGGER.error(ef)
        LOGGER.error(format_exc())

    return
Exemple #4
0
async def get_invitelink(c: Alita, m: Message):

    try:
        link = await c.export_chat_invite_link(m.chat.id)
        await m.reply_text(
            tlang(m, "admin.invitelink").format(
                chat_name=f"<b>{m.chat.id}</b>",
                link=link,
            ),
        )
    except ChatAdminRequired:
        await m.reply_text(tlang(m, "admin.not_admin"))
    except ChatAdminInviteRequired:
        await m.reply_text(tlang(m, "admin.noinviteperm"))
    except RightForbidden:
        await m.reply_text(tlang(m, "no_invite_perm"))
    except RPCError as ef:
        await m.reply_text(
            tlang(m, "general.some_error").format(
                SUPPORT_GROUP=f"@{SUPPORT_GROUP}",
                ef=f"<code>{ef}</code>",
            ),
        )
        LOGGER.error(ef)

    return
Exemple #5
0
async def get_invitelink(c: Alita, m: Message):

    try:
        link = await c.export_chat_invite_link(m.chat.id)
        await m.reply_text(
            (tlang(m, "admin.invitelink")).format(
                chat_name=m.chat.id,
                link=link,
            ),
            disable_web_page_preview=True,
        )
        LOGGER.info(f"{m.from_user.id} exported invite link in {m.chat.id}")
    except ChatAdminRequired:
        await m.reply_text(tlang(m, "admin.not_admin"))
    except ChatAdminInviteRequired:
        await m.reply_text(tlang(m, "admin.no_invite_perm"))
    except RightForbidden:
        await m.reply_text(tlang(m, "admin.no_user_invite_perm"))
    except RPCError as ef:
        await m.reply_text(
            (tlang(m, "general.some_error")).format(
                SUPPORT_GROUP=SUPPORT_GROUP,
                ef=ef,
            ),
        )
        LOGGER.error(ef)
        LOGGER.error(format_exc())

    return
async def adminlist(c: Alita, m: Message):
    _ = GetLang(m).strs
    try:
        me_id = int(get_key("BOT_ID"))  # Get Bot ID from Redis!
        adminlist = get_key("ADMINDICT")[str(
            m.chat.id)]  # Load ADMINDICT from string
        adminstr = _("admin.adminlist").format(chat_title=m.chat.title)
        for i in adminlist:
            usr = await c.get_users(i)
            if i == me_id:
                adminstr += f"- {mention_html(usr.first_name, i)} (Me)\n"
            else:
                usr = await c.get_users(i)
                adminstr += f"- {mention_html(usr.first_name, i)} (`{i}`)\n"
        await m.reply_text(adminstr)
    except Exception as ef:

        if str(ef) == str(m.chat.id):
            await m.reply_text(_("admin.useadmincache"))
        else:
            await m.reply_text(
                _("admin.somerror").format(SUPPORT_GROUP=SUPPORT_GROUP, ef=ef))
            LOGGER.error(ef)

    return
Exemple #7
0
async def reload_admins(_, m: Message):

    ADMINDICT = await get_key("ADMINDICT")  # Load ADMINDICT from string

    try:
        adminlist = []
        async for i in m.chat.iter_members(filter="administrators"):
            if i.user.is_deleted:
                continue
            adminlist.append(
                (
                    i.user.id,
                    f"@{i.user.username}" if i.user.username else i.user.first_name,
                ),
            )
        ADMINDICT[str(m.chat.id)] = adminlist
        await set_key("ADMINDICT", ADMINDICT)
        await m.reply_text(tlang(m, "admin.adminlist.reloaded_admins"))
    except RPCError as ef:
        await m.reply_text(
            tlang(m, "general.some_error").format(
                SUPPORT_GROUP=f"@{SUPPORT_GROUP}",
                ef=f"<code>{ef}</code>",
            ),
        )
        LOGGER.error(ef)
    return
async def demote_usr(c: Alita, m: Message):

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

    from_user = await m.chat.get_member(m.from_user.id)

    # If user does not have permission to invite other users, return
    if from_user.can_invite_users or from_user.status == "creator":

        try:
            link = await c.export_chat_invite_link(m.chat.id)
            await m.reply_text(_("admin.invitelink").format(link=link))
        except errors.ChatAdminRequired:
            await m.reply_text(_("admin.notadmin"))
        except errors.ChatAdminInviteRequired:
            await m.reply_text(_("admin.noinviteperm"))
        except Exception as ef:
            await m.reply_text(_("admin.useadmincache"))
            LOGGER.error(ef)

        return

    await m.reply_text(_("admin.nouserinviteperm"))
    return
async def pin_message(c: Alita, m: Message):

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

    pin_loud = m.text.split(" ", 1)
    if m.reply_to_message:
        try:
            disable_notification = True

            if len(pin_loud) >= 2 and pin_loud[1] in [
                    "alert", "notify", "loud"
            ]:
                disable_notification = False

            pinned_event = await c.pin_chat_message(
                m.chat.id,
                m.reply_to_m.message_id,
                disable_notification=disable_notification,
            )
            await m.reply_text(_("admin.pinnedmsg"))

        except errors.ChatAdminRequired:
            await m.reply_text(_("admin.notadmin"))
        except Exception as ef:
            await m.reply_text(_("admin.useadmincache"))
            LOGGER.error(ef)
    else:
        await m.reply_text(_("admin.nopinmsg"))
    return
Exemple #10
0
async def unpinall_calllback(c: Alita, q: CallbackQuery):
    user_id = q.from_user.id
    user_status = (await q.message.chat.get_member(user_id)).status
    if user_status not in {"creator", "administrator"}:
        await q.answer(
            "You're not even an admin, don't try this explosive shit!",
            show_alert=True,
        )
        return
    if user_status != "creator":
        await q.answer(
            "You're just an admin, not owner\nStay in your limits!",
            show_alert=True,
        )
        return
    try:
        await c.unpin_all_chat_messages(q.message.chat.id)
        LOGGER.info(
            f"{q.from_user.id} unpinned all messages in {q.message.chat.id}")
        await q.message.edit_text(tlang(q, "pin.unpinned_all_msg"))
    except ChatAdminRequired:
        await q.message.edit_text(tlang(q, "admin.notadmin"))
    except RightForbidden:
        await q.message.edit_text(tlang(q, "pin.no_rights_unpin"))
    except RPCError as ef:
        await q.message.edit_text((tlang(q, "general.some_error")).format(
            SUPPORT_GROUP=SUPPORT_GROUP,
            ef=ef,
        ), )
        LOGGER.error(ef)
    return
Exemple #11
0
async def unmute_usr(c: Alita, m: Message):

    _ = GetLang(m).strs

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

    from_user = await m.chat.get_member(m.from_user.id)

    if len(m.text.split()) == 1 and not m.reply_to_message:
        await m.reply_text("Whom should I unmute?\nSpecify a user first.")
        return

    if from_user.can_restrict_members or from_user.status == "creator":
        user_id, user_first_name = extract_user(m)
        try:
            await m.chat.restrict_member(user_id, unmute_permissions)
            await m.reply_text(f"<b>Muted</b> {mention_html(user_first_name,user_id)}")
        except errors.ChatAdminRequired:
            await m.reply_text(_("admin.notadmin"))
        except Exception as ef:
            await m.reply_text(f"<code>{ef}</code>\nReport to @{SUPPORT_GROUP}")
            LOGGER.error(ef)
        return

    await m.reply_text("You don't have permissions to restrict users.")
    return
Exemple #12
0
async def kick_usr(c: Alita, m: Message):

    _ = GetLang(m).strs

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

    from_user = await m.chat.get_member(m.from_user.id)

    if len(m.text.split()) == 1 and not m.reply_to_message:
        await m.reply_text("Whom should I kick?\nSpecify a user first.")
        return

    if from_user.can_restrict_members or from_user.status == "creator":
        user_id, user_first_name = extract_user(m)
        try:
            await c.kick_chat_member(m.chat.id, user_id, int(time.time() + 45))
            await m.reply_text(f"Banned {mention_html(user_first_name, user_id)}")
        except errors.ChatAdminRequired:
            await m.reply_text(_("admin.notadmin"))
        except Exception as ef:
            await m.reply_text(f"<code>{ef}</code>\nReport to @{SUPPORT_GROUP}")
            LOGGER.error(ef)

    return
Exemple #13
0
async def initial_works(_, m: Message):
    try:
        if m.migrate_to_chat_id or m.migrate_from_chat_id:
            if m.migrate_to_chat_id:
                old_chat = m.chat.id
                new_chat = m.migrate_to_chat_id
            elif m.migrate_from_chat_id:
                old_chat = m.migrate_from_chat_id
                new_chat = m.chat.id

            try:
                await migrate_chat(old_chat, new_chat)
            except RPCError as ef:
                LOGGER.error(ef)
                return
        else:
            userdb.update_user(
                m.from_user.id,
                m.from_user.username,
                m.chat.id,
                m.chat.title,
            )
            if m.reply_to_message:
                userdb.update_user(
                    m.reply_to_message.from_user.id,
                    m.reply_to_message.from_user.username,
                    m.chat.id,
                    m.chat.title,
                )
            if m.forward_from:
                userdb.update_user(m.forward_from.id, m.forward_from.username)
    except AttributeError:
        pass  # Skip attribute errors!
    return
Exemple #14
0
async def pin_message(c: Alita, m: Message):

    _ = GetLang(m).strs

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

    pin_args = m.text.split(None, 1)
    if m.reply_to_message:
        try:
            disable_notification = True

            if len(pin_args) >= 2 and pin_args[1] in ["alert", "notify", "loud"]:
                disable_notification = False

            await c.pin_chat_message(
                m.chat.id,
                m.reply_to_message.message_id,
                disable_notification=disable_notification,
            )
            await m.reply_text(_("admin.pinnedmsg"))

        except errors.ChatAdminRequired:
            await m.reply_text(_("admin.notadmin"))
        except errors.RightForbidden:
            await m.reply_text("I don't have enough rights to pin messages.")
        except Exception as ef:
            await m.reply_text(f"<code>{ef}</code>\nReport to @{SUPPORT_GROUP}")
            LOGGER.error(ef)
    else:
        await m.reply_text(_("admin.nopinmsg"))

    return
Exemple #15
0
async def chat_broadcast(c: Alita, m: Message):
    if m.reply_to_message:
        msg = m.reply_to_message.text.markdown
    else:
        await m.reply_text("Reply to a message to broadcast it")
        return

    exmsg = await m.reply_text("Started broadcasting!")
    all_chats = (Chats.list_chats_by_id()) or {}
    err_str, done_broadcast = "", 0

    for chat in all_chats:
        try:
            await c.send_message(chat, msg, disable_web_page_preview=True)
            done_broadcast += 1
            await sleep(0.1)
        except RPCError as ef:
            LOGGER.error(ef)
            err_str += str(ef)
            continue

    await exmsg.edit_text(
        f"Done broadcasting ✅\nSent message to {done_broadcast} chats",
    )

    if err_str:
        with BytesIO(str.encode(await remove_markdown_and_html(err_str))) as f:
            f.name = "error_broadcast.txt"
            await m.reply_document(
                document=f,
                caption="Broadcast Error",
            )

    return
Exemple #16
0
async def reload_admins(c: Alita, m: Message):

    _ = GetLang(m).strs
    replymsg = await m.reply_text("Refreshing admin list...")

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

    ADMINDICT = await get_key("ADMINDICT")  # Load ADMINDICT from string

    try:
        adminlist = []
        async for i in m.chat.iter_members(filter="administrators"):
            if not i.user.is_deleted:
                continue
            adminlist.append((
                i.user.id,
                f"@{i.user.username}"
                if i.user.username else i.user.first_name,
            ), )
        ADMINDICT[str(m.chat.id)] = adminlist
        await set_key("ADMINDICT", ADMINDICT)
        await replymsg.edit_text(_("admin.reloadedadmins"))
        LOGGER.info(f"Reloaded admins for {m.chat.title}({m.chat.id})")
    except Exception as ef:
        await m.reply_text(_("admin.useadmincache"))
        LOGGER.error(ef)

    return
Exemple #17
0
async def ban_usr(_, m: Message):

    user_id, user_first_name = await extract_user(m)
    try:
        await m.chat.kick_member(user_id)
        await m.reply_text(
            tlang(m, "admin.banned_user").format(
                admin=(await mention_html(m.from_user.first_name,
                                          m.from_user.id)),
                banned=(await mention_html(user_first_name, user_id)),
                chat_title=f"<b>{m.chat.title}</b>",
            ), )
    except ChatAdminRequired:
        await m.reply_text(tlang(m, "admin.not_admin"))
    except RightForbidden:
        await m.reply_text(tlang(m, tlang(m, "admin.bot_no_ban_right")))
    except RPCError as ef:
        await m.reply_text(
            tlang(m, "general.some_error").format(
                SUPPORT_GROUP=f"@{SUPPORT_GROUP}",
                ef=f"<code>{ef}</code>",
            ), )
        LOGGER.error(ef)

    return
Exemple #18
0
async def get_invitelink(c: Alita, m: Message):

    _ = GetLang(m).strs

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

    from_user = await m.chat.get_member(m.from_user.id)

    # If user does not have permission to invite other users, return
    if from_user.can_invite_users or from_user.status == "creator":

        try:
            link = await c.export_chat_invite_link(m.chat.id)
            await m.reply_text(_("admin.invitelink").format(link=link))
        except errors.ChatAdminRequired:
            await m.reply_text(_("admin.notadmin"))
        except errors.ChatAdminInviteRequired:
            await m.reply_text(_("admin.noinviteperm"))
        except errors.RightForbidden:
            await m.reply_text("I don't have enough rights to view invitelink."
                               )
        except Exception as ef:
            await m.reply_text(f"<code>{ef}</code>\nReport to @{SUPPORT_GROUP}"
                               )
            LOGGER.error(ef)

        return

    await m.reply_text(_("admin.nouserinviteperm"))
    return
Exemple #19
0
async def unmute_usr(c: Alita, m: Message):

    _ = GetLang(m).strs

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

    from_user = await m.chat.get_member(m.from_user.id)

    if from_user.can_restrict_members or from_user.status == "creator":
        user_id, user_first_name = await extract_user(m)
        try:
            await m.chat.restrict_member(user_id, unmute_permissions)
            await m.reply_text(
                f"<b>Unmuted</b> {(await mention_html(user_first_name,user_id))}",
            )
        except errors.ChatAdminRequired:
            await m.reply_text(_("admin.notadmin"))
        except Exception as ef:
            await m.reply_text(f"<code>{ef}</code>\nReport to @{SUPPORT_GROUP}"
                               )
            LOGGER.error(ef)
        return

    await m.reply_text("You don't have permissions to restrict users.")
    return
Exemple #20
0
async def skick_usr(c: Alita, m: Message):
    if len(m.text.split()) == 1 and not m.reply_to_message:
        await m.reply_text(tlang(m, "admin.kick.no_target"))
        return

    try:
        user_id, _, _ = await extract_user(c, m)
    except Exception:
        return

    if not user_id:
        await m.reply_text("Cannot find user to kick")
        return

    if user_id == BOT_ID:
        await m.reply_text("Huh, why would I kick myself?")
        await m.stop_propagation()

    if user_id in SUPPORT_STAFF:
        await m.reply_text(tlang(m, "admin.support_cannot_restrict"))
        LOGGER.info(
            f"{m.from_user.id} trying to skick {user_id} (SUPPORT_STAFF) in {m.chat.id}",
        )
        await m.stop_propagation()

    try:
        admins_group = {i[0] for i in ADMIN_CACHE[m.chat.id]}
    except KeyError:
        admins_group = await admin_cache_reload(m, "kick")

    if user_id in admins_group:
        await m.reply_text(tlang(m, "admin.kick.admin_cannot_kick"))
        await m.stop_propagation()

    try:
        LOGGER.info(f"{m.from_user.id} skicked {user_id} in {m.chat.id}")
        await m.chat.kick_member(user_id)
        await m.delete()
        if m.reply_to_message:
            await m.reply_to_message.delete()
        await m.chat.unban_member(user_id)
    except ChatAdminRequired:
        await m.reply_text(tlang(m, "admin.not_admin"))
    except PeerIdInvalid:
        await m.reply_text(
            "I have not seen this user yet...!\nMind forwarding one of their message so I can recognize them?",
        )
    except UserAdminInvalid:
        await m.reply_text(tlang(m, "admin.user_admin_invalid"))
    except RightForbidden:
        await m.reply_text(tlang(m, "admin.kick.bot_no_right"))
    except RPCError as ef:
        await m.reply_text((tlang(m, "general.some_error")).format(
            SUPPORT_GROUP=SUPPORT_GROUP,
            ef=ef,
        ), )
        LOGGER.error(ef)
        LOGGER.error(format_exc())

    return
Exemple #21
0
async def initial_works(c: Alita, m: Message):
    if m.migrate_to_chat_id or m.migrate_from_chat_id:
        if m.migrate_to_chat_id:
            old_chat = m.chat.id
            new_chat = m.migrate_to_chat_id
        elif m.migrate_from_chat_id:
            old_chat = m.migrate_from_chat_id
            new_chat = m.chat.id

        try:
            await migrate_chat(old_chat, new_chat)
        except Exception as ef:
            LOGGER.error(ef)
            return
    else:
        userdb.update_user(m.from_user.id, m.from_user.username, m.chat.id,
                           m.chat.title)
        if m.reply_to_message:
            userdb.update_user(
                m.reply_to_message.from_user.id,
                m.reply_to_message.from_user.username,
                m.chat.id,
                m.chat.title,
            )
        if m.forward_from:
            userdb.update_user(m.forward_from.id, m.forward_from.username)
    return
Exemple #22
0
    def rm_filter(self, chat_id: int, keyword: str):
        global FILTER_CACHE
        with INSERTION_LOCK:
            try:
                FILTER_CACHE[chat_id].remove(
                    next(i for i in FILTER_CACHE[chat_id]
                         if keyword in i["keyword"].split("|")), )
            except KeyError:
                pass
            except Exception as ef:
                LOGGER.error(ef)
                LOGGER.error(format_exc())

            curr = self.collection.find_one(
                {
                    "chat_id": chat_id,
                    "keyword": {
                        "$regex": fr"\|?{keyword}\|?"
                    }
                }, )
            if curr:
                self.collection.delete_one(curr)
                return True

            return False
Exemple #23
0
async def pin_message(c: Alita, m: Message):

    pin_args = m.text.split(None, 1)
    if m.reply_to_message:
        try:
            disable_notification = True

            if len(pin_args) >= 2 and pin_args[1] in [
                    "alert", "notify", "loud"
            ]:
                disable_notification = False

            await c.pin_chat_message(
                m.chat.id,
                m.reply_to_message.message_id,
                disable_notification=disable_notification,
            )
            await m.reply_text(tlang(m, "pin.pinned_msg"))

        except ChatAdminRequired:
            await m.reply_text(tlang(m, "admin.not_admin"))
        except RightForbidden:
            await m.reply_text(tlang(m, "pin.no_rights_pin"))
        except RPCError as ef:
            await m.reply_text(
                tlang(m, "general.some_error").format(
                    SUPPORT_GROUP=f"@{SUPPORT_GROUP}",
                    ef=f"<code>{ef}</code>",
                ), )
            LOGGER.error(ef)
    else:
        await m.reply_text(tlang(m, "admin.nopinmsg"))

    return
Exemple #24
0
async def unblacklist_chat(c: Alita, m: Message):
    if len(m.text.split()) >= 2:
        chat_ids = m.text.split()[1:]
        replymsg = await m.reply_text(
            f"Removing {len(chat_ids)} chats from blacklist")
        LOGGER.info(
            f"{m.from_user.id} removed blacklisted {chat_ids} groups for bot")
        bl_chats = db.list_all_chats()
        for chat in chat_ids:
            try:
                get_chat = await c.get_chat(chat)
                chat_id = get_chat.id
                if chat_id not in bl_chats:
                    # If chat is not blaklisted, continue loop
                    continue
                db.remove_chat(chat_id)
            except PeerIdInvalid:
                await replymsg.edit_text(
                    "Haven't seen this group in this session, maybe try again later?",
                )
            except RPCError as ef:
                LOGGER.error(ef)
                LOGGER.error(format_exc())
        await replymsg.edit_text(
            f"Removed the following chats to Blacklist.\n<code>{', '.join(chat_ids)}</code>.",
        )
    return
Exemple #25
0
async def antichanpin_cleanlinked(c: Alita, m: Message):
    try:
        msg_id = m.message_id
        pins_db = Pins(m.chat.id)
        curr = pins_db.get_settings()
        if curr["antichannelpin"]:
            await c.unpin_chat_message(chat_id=m.chat.id, message_id=msg_id)
            LOGGER.info(
                f"AntiChannelPin: msgid-{m.message_id} unpinned in {m.chat.id}"
            )
        if curr["cleanlinked"]:
            await c.delete_messages(m.chat.id, msg_id)
            LOGGER.info(
                f"CleanLinked: msgid-{m.message_id} cleaned in {m.chat.id}")
    except ChatAdminRequired:
        await m.reply_text(
            "Disabled antichannelpin as I don't have enough admin rights!", )
        pins_db.antichannelpin_off()
        LOGGER.warning(
            f"Disabled antichannelpin in {m.chat.id} as i'm not an admin.")
    except Exception as ef:
        LOGGER.error(ef)
        LOGGER.error(format_exc())

    return
Exemple #26
0
async def demote_usr(c: Alita, m: Message):

    _ = GetLang(m).strs

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

    from_user = await m.chat.get_member(m.from_user.id)

    # If user does not have permission to demote other users, return
    if from_user.can_promote_members or from_user.status == "creator":

        user_id, user_first_name = await extract_user(m)
        try:
            await m.chat.promote_member(
                user_id=user_id,
                can_change_info=False,
                can_delete_messages=False,
                can_restrict_members=False,
                can_invite_users=False,
                can_pin_messages=False,
            )
            await m.reply_text(
                _("admin.demoted").format(
                    demoter=(await mention_html(m.from_user.first_name,
                                                m.from_user.id)),
                    demoted=(await mention_html(user_first_name, user_id)),
                    chat_title=m.chat.title,
                ), )

            # ----- Add admin to redis cache! -----
            ADMINDICT = await get_key("ADMINDICT"
                                      )  # Load ADMINDICT from string
            adminlist = []
            async for i in m.chat.iter_members(filter="administrators"):
                if not i.user.is_deleted:
                    continue
                adminlist.append([
                    i.user.id,
                    f"@{i.user.username}"
                    if i.user.username else i.user.first_name,
                ], )
            ADMINDICT[str(m.chat.id)] = adminlist
            await set_key("ADMINDICT", ADMINDICT)

        except errors.ChatAdminRequired:
            await m.reply_text(_("admin.notadmin"))
        except errors.RightForbidden:
            await m.reply_text(
                "I don't have enough rights to demote this user.")
        except Exception as ef:
            await m.reply_text(f"<code>{ef}</code>\nReport to @{SUPPORT_GROUP}"
                               )
            LOGGER.error(ef)

        return

    await m.reply_text(_("admin.nodemoteperm"))
    return
Exemple #27
0
async def smute_usr(c: Alita, m: Message):
    if len(m.text.split()) == 1 and not m.reply_to_message:
        await m.reply_text("Я не могу никого замьютить!")
        return

    try:
        user_id, _, _ = await extract_user(c, m)
    except Exception:
        return

    if not user_id:
        await m.reply_text("Cannot find user to mute")
        return
    if user_id == Config.BOT_ID:
        await m.reply_text("Huh, why would I mute myself?")
        return

    if user_id in SUPPORT_STAFF:
        LOGGER.info(
            f"{m.from_user.id} trying to mute {user_id} (SUPPORT_STAFF) in {m.chat.id}",
        )
        await m.reply_text(tlang(m, "admin.support_cannot_restrict"))
        return

    try:
        admins_group = {i[0] for i in ADMIN_CACHE[m.chat.id]}
    except KeyError:
        admins_group = await admin_cache_reload(m, "mute")

    if user_id in admins_group:
        await m.reply_text(tlang(m, "admin.mute.admin_cannot_mute"))
        return

    try:
        await m.chat.restrict_member(
            user_id,
            ChatPermissions(),
        )
        LOGGER.info(f"{m.from_user.id} smuted {user_id} in {m.chat.id}")
        await m.delete()
        if m.reply_to_message:
            await m.reply_to_message.delete()
            return
        return
    except ChatAdminRequired:
        await m.reply_text(tlang(m, "admin.not_admin"))
    except RightForbidden:
        await m.reply_text(tlang(m, "admin.mute.bot_no_right"))
    except UserNotParticipant:
        await m.reply_text(
            "How can I mute a user who is not a part of this chat?")
    except RPCError as ef:
        await m.reply_text((tlang(m, "general.some_error")).format(
            SUPPORT_GROUP=SUPPORT_GROUP,
            ef=ef,
        ), )
        LOGGER.error(ef)

    return
Exemple #28
0
async def close_btn_callback(_, q: CallbackQuery):
    await q.message.delete()
    try:
        await q.message.reply_to_message.delete()
    except Exception as ef:
        LOGGER.error(f"Error: Cannot delete message\n{ef}")
    await q.answer()
    return
 def list_gbans(self):
     with INSERTION_LOCK:
         try:
             return list(ANTISPAM_BANNED)
         except Exception as ef:
             LOGGER.error(ef)
             LOGGER.error(format_exc())
         return self.collection.find_all()
 def count_gbans(self):
     with INSERTION_LOCK:
         try:
             return len(ANTISPAM_BANNED)
         except Exception as ef:
             LOGGER.error(ef)
             LOGGER.error(format_exc())
             return self.collection.count()