예제 #1
0
async def adminlist(c: Mizuhara, 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
예제 #2
0
async def demote_usr(c: Mizuhara, 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 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(c, 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=mention_html(m.from_user.first_name,
                                         m.from_user.id),
                    demoted=mention_html(user_first_name, user_id),
                    chat_title=m.chat.title,
                ))

            # ----- Add admin to redis cache! -----
            ADMINDICT = get_key("ADMINDICT")  # Load ADMINDICT from string
            adminlist = []
            async for i in m.chat.iter_members(filter="administrators"):
                adminlist.append(i.user.id)
            ADMINDICT[str(m.chat.id)] = adminlist
            set_key("ADMINDICT", ADMINDICT)

        except errors.ChatAdminRequired:
            await m.reply_text(_("admin.notadmin"))
        except Exception as ef:
            await m.reply_text(_("admin.useadmincache"))
            LOGGER.error(ef)

        return

    await m.reply_text(_("admin.nodemoteperm"))
    return
예제 #3
0
async def list_all_admins(c: Mizuhara, m: Message):

    admindict = get_key("ADMINDICT")

    if len(str(admindict)) > 4000:
        with io.BytesIO(str.encode(chatfile)) as output:
            output.name = "alladmins.txt"
            await m.reply_document(
                document=output,
                caption="Here is the list of all admins in my Cache.",
            )
    else:
        await m.reply_text(admindict)

    return
예제 #4
0
async def reload_admins(c: Mizuhara, m: Message):

    _ = GetLang(m).strs

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

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

    try:
        adminlist = []
        async for i in m.chat.iter_members(filter="administrators"):
            adminlist.append(i.user.id)
        ADMINDICT[str(m.chat.id)] = adminlist
        set_key("ADMINDICT", ADMINDICT)
        await m.reply_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