Exemple #1
0
async def get_rules(c: Mizuhara, m: Message):
    _ = GetLang(m).strs

    chat_id = m.chat.id
    rules = db.get_rules(chat_id)

    if not rules:
        await m.reply_text(_("rules.no_rules"), reply_to_message_id=m.message_id)
        return

    try:
        await c.send_message(
            m.from_user.id,
            _("rules.get_rules").format(chat=m.chat.title, rules=rules),
        )
    except errors.UserIsBlocked:
        me = await c.get_me()
        pm_kb = InlineKeyboardMarkup(
            [[InlineKeyboardButton("PM", url=f"https://t.me/{me.username}?start")]]
        )
        await m.reply_text(
            _("rules.pm_me"), reply_to_message_id=m.message_id, reply_markup=pm_kb
        )
        return

    await m.reply_text(_("rules.sent_pm_rules"), reply_to_message_id=m.message_id)
    return
Exemple #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 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
Exemple #3
0
async def pin_message(c: Mizuhara, m: Message):

    _ = GetLang(m).strs

    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 #4
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
Exemple #5
0
async def clear_rules(c: Mizuhara, m: Message):

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

    _ = GetLang(m).strs

    rules = db.get_rules(m.chat.id)
    if not rules:
        await m.reply_text(_("rules.no_rules"), reply_to_message_id=m.message_id)
        return

    await m.reply_text(
        "Are you sure you want to clear rules?",
        reply_markup=InlineKeyboardMarkup(
            [
                [
                    InlineKeyboardButton("⚠️ Confirm", callback_data="clear.rules"),
                    InlineKeyboardButton("❌ Cancel", callback_data="close"),
                ]
            ]
        ),
    )
    return
Exemple #6
0
async def public_ip(c: Mizuhara, m: Message):
    _ = GetLang(m).strs
    ip = requests.get("https://api.ipify.org").text
    await c.send_message(
        MESSAGE_DUMP,
        f"#IP\n\n**User:** {mention_markdown(m.from_user.first_name, m.from_user.id)}",
    )
    await m.reply_text(_("dev.bot_ip").format(ip=ip))
    return
Exemple #7
0
async def view_locks(c: Mizuhara, m: Message):
    _ = GetLang(m).strs
    v_perm = ""
    vmsg = ""
    vmedia = ""
    vstickers = ""
    vanimations = ""
    vgames = ""
    vinlinebots = ""
    vwebprev = ""
    vpolls = ""
    vinfo = ""
    vinvite = ""
    vpin = ""

    chkmsg = await m.reply_text(_("locks.check_perm_msg"))
    v_perm = await c.get_chat(m.chat.id)

    def convert_to_emoji(val: bool):
        if val is True:
            return "✅"
        return "❌"

    vmsg = convert_to_emoji(v_perm.permissions.can_send_messages)
    vmedia = convert_to_emoji(v_perm.permissions.can_send_media_messages)
    vstickers = convert_to_emoji(v_perm.permissions.can_send_stickers)
    vanimations = convert_to_emoji(v_perm.permissions.can_send_animations)
    vgames = convert_to_emoji(v_perm.permissions.can_send_games)
    vinlinebots = convert_to_emoji(v_perm.permissions.can_use_inline_bots)
    vwebprev = convert_to_emoji(v_perm.permissions.can_add_web_page_previews)
    vpolls = convert_to_emoji(v_perm.permissions.can_send_polls)
    vinfo = convert_to_emoji(v_perm.permissions.can_change_info)
    vinvite = convert_to_emoji(v_perm.permissions.can_invite_users)
    vpin = convert_to_emoji(v_perm.permissions.can_pin_messages)

    if v_perm is not None:
        try:
            permission_view_str = _("locks.view_perm").format(
                vmsg=vmsg,
                vmedia=vmedia,
                vstickers=vstickers,
                vanimations=vanimations,
                vgames=vgames,
                vinlinebots=vinlinebots,
                vwebprev=vwebprev,
                vpolls=vpolls,
                vinfo=vinfo,
                vinvite=vinvite,
                vpin=vpin,
            )
            await chkmsg.edit_text(permission_view_str)

        except Exception as e_f:
            await chkmsg.edit_text(_("general.something_wrong"))
            await m.reply_text(e_f)

    return
Exemple #8
0
async def evaluate_code(c: Mizuhara, m: Message):
    _ = GetLang(m).strs
    if len(m.text.split()) == 1:
        await m.reply_text(_("dev.execute_cmd_err"))
        return
    sm = await m.reply_text("`Processing...`")
    cmd = m.text.split(" ", maxsplit=1)[1]

    reply_to_id = m.message_id
    if m.reply_to_message:
        reply_to_id = m.reply_to_message.message_id

    old_stderr = sys.stderr
    old_stdout = sys.stdout
    redirected_output = sys.stdout = io.StringIO()
    redirected_error = sys.stderr = io.StringIO()
    stdout, stderr, exc = None, None, None

    try:
        await aexec(cmd, c, m)
    except Exception:
        exc = traceback.format_exc()

    stdout = redirected_output.getvalue()
    stderr = redirected_error.getvalue()
    sys.stdout = old_stdout
    sys.stderr = old_stderr

    evaluation = ""
    if exc:
        evaluation = exc
    elif stderr:
        evaluation = stderr
    elif stdout:
        evaluation = stdout
    else:
        evaluation = "Success"

    final_output = f"<b>EVAL</b>: <code>{cmd}</code>\n\n<b>OUTPUT</b>:\n<code>{evaluation.strip()}</code> \n"

    if len(final_output) > 4000:
        with open("eval.text", "w+", encoding="utf8") as out_file:
            out_file.write(str(final_output))
        await m.reply_document(
            document="eval.text",
            caption=cmd,
            disable_notification=True,
            reply_to_message_id=reply_to_id,
        )
        os.remove("eval.text")
        await sm.delete()
    else:
        await sm.edit(final_output)
    return
Exemple #9
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
Exemple #10
0
async def fun_shout(c: Mizuhara, m: Message):
    _ = GetLang(m).strs
    if len(m.text.split()) == 1:
        await m.reply_text(_("general.check_help"), reply_to_message_id=m.message_id)
        return
    text = " ".join(m.text.split(None, 1)[1])
    result = []
    result.append(" ".join([s for s in text]))
    for pos, symbol in enumerate(text[1:]):
        result.append(symbol + " " + "  " * pos + symbol)
    result = list("\n".join(result))
    result[0] = text[0]
    result = "".join(result)
    msg = "```\n" + result + "```"
    await m.reply_text(msg, parse_mode="MARKDOWN")
    return
Exemple #11
0
async def del_msg(c: Mizuhara, m: Message):

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

    _ = GetLang(m).strs
    if m.reply_to_message:
        if m.chat.type != "supergroup":
            return
        await c.delete_messages(chat_id=m.chat.id,
                                message_ids=m.reply_to_message.message_id)
        await asyncio.sleep(0.5)
        await m.delete()
    else:
        await m.reply_text(_("purge.what_del"))
    return
Exemple #12
0
async def unpin_message(c: Mizuhara, m: Message):

    _ = GetLang(m).strs

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

    try:
        await m.chat.unpin_chat_message(m.chat.id)
    except errors.ChatAdminRequired:
        await m.reply_text(_("admin.notadmin"))
    except Exception as ef:
        await m.reply_text(
            _("admin.somerror").format(SUPPORT_GROUP=SUPPORT_GROUP, ef=ef))
        LOGGER.error(ef)
    return
Exemple #13
0
async def test_speed(c: Mizuhara, m: Message):
    _ = GetLang(m).strs
    string = _("dev.speedtest")
    await c.send_message(
        MESSAGE_DUMP,
        f"#SPEEDTEST\n\n**User:** {mention_markdown(m.from_user.first_name, m.from_user.id)}",
    )
    sent = await m.reply_text(_("dev.start_speedtest"))
    s = speedtest.Speedtest()
    bs = s.get_best_server()
    dl = round(s.download() / 1024 / 1024, 2)
    ul = round(s.upload() / 1024 / 1024, 2)
    await sent.edit_text(
        string.format(host=bs["sponsor"],
                      ping=int(bs["latency"]),
                      download=dl,
                      upload=ul))
    return
Exemple #14
0
async def add_blacklist(c: Mizuhara, m: Message):

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

    _ = GetLang(m).strs
    if len(m.text.split()) >= 2:
        bl_word = m.text.split(" ", 1)[1]
        db.add_to_blacklist(m.chat.id, bl_word.lower())
        await m.reply_text(
            _("blacklist.added_blacklist").format(trigger=bl_word),
            reply_to_message_id=m.message_id,
        )
        return
    await m.reply_text(_("general.check_help"),
                       reply_to_message_id=m.message_id)
    return
Exemple #15
0
async def translate(c: Mizuhara, m: Message):
    _ = GetLang(m).strs
    translator = Translator()
    text = m.text[4:]
    lang = get_lang(text)
    if m.reply_to_message:
        text = m.reply_to_message.text or m.reply_to_message.caption
    else:
        text = text.replace(lang, "",
                            1).strip() if text.startswith(lang) else text

    if text:
        sent = await m.reply_text(_("translate.translating"),
                                  reply_to_message_id=m.message_id)
        langs = {}

        if len(lang.split("-")) > 1:
            langs["src"] = lang.split("-")[0]
            langs["dest"] = lang.split("-")[1]
        else:
            langs["dest"] = lang

        trres = translator.translate(text, **langs)
        text = trres.text

        res = html.escape(text)
        await sent.edit_text(
            _("translate.translation").format(from_lang=trres.src,
                                              to_lang=trres.dest,
                                              translation=res),
            parse_mode="HTML",
        )

    else:
        await m.reply_text(
            _("translate.translate_usage"),
            reply_to_message_id=m.message_id,
            parse_mode="markdown",
        )

    return
Exemple #16
0
async def set_rules(c: Mizuhara, m: Message):

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

    _ = GetLang(m).strs

    chat_id = m.chat.id
    if m.reply_to_message and m.reply_to_message.text:
        rules = m.reply_to_message.text
    elif (not m.reply_to_message) and len(m.text.split()) >= 2:
        rules = m.text.split(None, 1)[1]

    if len(rules) > 4000:
        rules = rules[0:3949]  # Split Rules if len > 4000 chars
        await m.reply_text("Rules truncated to 3950 characters!")

    db.set_rules(chat_id, rules)
    await m.reply_text(_("rules.set_rules"), reply_to_message_id=m.message_id)
    return
Exemple #17
0
async def execution(c: Mizuhara, m: Message):
    _ = GetLang(m).strs
    if len(m.text.split()) == 1:
        await m.reply_text(_("dev.execute_cmd_err"))
        return
    sm = await m.reply_text("`Processing...`")
    cmd = m.text.split(maxsplit=1)[1]
    reply_to_id = m.message_id
    if m.reply_to_message:
        reply_to_id = m.reply_to_message.message_id

    process = await asyncio.create_subprocess_shell(
        cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
    stdout, stderr = await process.communicate()
    e = stderr.decode()
    if not e:
        e = "No Error"
    o = stdout.decode()
    if not o:
        o = "No Output"

    OUTPUT = ""
    OUTPUT += f"<b>QUERY:</b>\n<u>Command:</u>\n<code>{cmd}</code> \n"
    OUTPUT += f"<u>PID</u>: <code>{process.pid}</code>\n\n"
    OUTPUT += f"<b>stderr</b>: \n<code>{e}</code>\n\n"
    OUTPUT += f"<b>stdout</b>: \n<code>{o}</code>"

    if len(OUTPUT) > 4000:
        with open("exec.text", "w+", encoding="utf8") as out_file:
            out_file.write(str(OUTPUT))
        await m.reply_document(
            document="exec.text",
            caption=cmd,
            disable_notification=True,
            reply_to_message_id=reply_to_id,
        )
        os.remove("exec.text")
    else:
        await sm.edit_text(OUTPUT)
    return
Exemple #18
0
async def view_blacklist(c: Mizuhara, 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
Exemple #19
0
async def purge(c: Mizuhara, m: Message):

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

    _ = GetLang(m).strs
    if m.chat.type != "supergroup":
        await m.reply_text(_("purge.err_basic"))
        return
    dm = await m.reply_text(_("purge.deleting"))

    message_ids = []

    if m.reply_to_message:
        for a_msg in range(m.reply_to_message.message_id, m.message_id):
            message_ids.append(a_msg)

    if (not m.reply_to_message and len(m.text.split()) == 2
            and isinstance(m.text.split()[1], int)):
        c_msg_id = m.message_id
        first_msg = (m.message_id) - (m.text.split()[1])
        for a_msg in range(first_msg, c_msg_id):
            message_ids.append(a_msg)

    try:
        await c.delete_messages(chat_id=m.chat.id,
                                message_ids=message_ids,
                                revoke=True)
    except errors.MessageDeleteForbidden:
        await dm.edit_text(_("purge.old_msg_err"))
        return

    count_del_msg = len(message_ids)

    await dm.edit(_("purge.purge_msg_count").format(msg_count=count_del_msg))
    await asyncio.sleep(3)
    await dm.delete()
    return
Exemple #20
0
async def ban_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 from_user.can_restrict_members or from_user.status == "creator":
        user_id, user_first_name = await extract_user(c, m)
        try:
            await c.kick_chat_member(m.chat.id, user_id)
            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"Error: {ef}\n\nReport it in Support Group!")
            LOGGER.error(ef)

    return
Exemple #21
0
async def rm_blacklist(c: Mizuhara, 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 isinstance(chat_bl, bool):
        pass
    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
Exemple #22
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
Exemple #23
0
async def clearrules_callback(c: Mizuhara, q: CallbackQuery):
    _ = GetLang(q.message).strs
    db.clear_rules(q.message.chat.id)
    await q.message.reply_text(_("rules.clear"))
    await q.answer()
    return
Exemple #24
0
async def lock_perm(c: Mizuhara, m: Message):

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

    _ = GetLang(m).strs
    msg = ""
    media = ""
    stickers = ""
    animations = ""
    games = ""
    inlinebots = ""
    webprev = ""
    polls = ""
    info = ""
    invite = ""
    pin = ""
    perm = ""

    if not len(m.text.split()) >= 2:
        await m.reply_text("Please enter a permission to lock!")
        return
    lock_type = m.text.split(" ", 1)[1]
    chat_id = m.chat.id

    if not lock_type:
        await m.reply_text(_("locks.locks_perm.sp_perm"))
        return

    get_perm = await c.get_chat(chat_id)

    msg = get_perm.permissions.can_send_messages
    media = get_perm.permissions.can_send_media_messages
    stickers = get_perm.permissions.can_send_stickers
    animations = get_perm.permissions.can_send_animations
    games = get_perm.permissions.can_send_games
    inlinebots = get_perm.permissions.can_use_inline_bots
    webprev = get_perm.permissions.can_add_web_page_previews
    polls = get_perm.permissions.can_send_polls
    info = get_perm.permissions.can_change_info
    invite = get_perm.permissions.can_invite_users
    pin = get_perm.permissions.can_pin_messages

    if lock_type == "all":
        try:
            await c.set_chat_permissions(chat_id, ChatPermissions())
            await prevent_approved(c, m)  # Don't lock permissions for approved users!
            await m.reply_text("🔒 " + _("locks.lock_all"))
        except errors.ChatAdminRequired:
            await m.reply_text(_("general.no_perm_admin"))
        return

    if lock_type == "msg":
        msg = False
        perm = "messages"

    elif lock_type == "media":
        media = False
        perm = "audios, documents, photos, videos, video notes, voice notes"

    elif lock_type == "stickers":
        stickers = False
        perm = "stickers"

    elif lock_type == "animations":
        animations = False
        perm = "animations"

    elif lock_type == "games":
        games = False
        perm = "games"

    elif lock_type == "inlinebots":
        inlinebots = False
        perm = "inline bots"

    elif lock_type == "webprev":
        webprev = False
        perm = "web page previews"

    elif lock_type == "polls":
        polls = False
        perm = "polls"

    elif lock_type == "info":
        info = False
        perm = "info"

    elif lock_type == "invite":
        invite = False
        perm = "invite"

    elif lock_type == "pin":
        pin = False
        perm = "pin"

    else:
        await m.reply_text(_("locks.invalid_lock"))
        return

    try:
        await c.set_chat_permissions(
            chat_id,
            ChatPermissions(
                can_send_messages=msg,
                can_send_media_messages=media,
                can_send_stickers=stickers,
                can_send_animations=animations,
                can_send_games=games,
                can_use_inline_bots=inlinebots,
                can_add_web_page_previews=webprev,
                can_send_polls=polls,
                can_change_info=info,
                can_invite_users=invite,
                can_pin_messages=pin,
            ),
        )
        await prevent_approved(c, m)  # Don't lock permissions for approved users!
        await m.reply_text("🔒 " + _("locks.locked_perm").format(perm=perm))
    except errors.ChatAdminRequired:
        await m.reply_text(_("general.no_perm_admin"))
    return
Exemple #25
0
async def get_module_info(c: Mizuhara, m: CallbackQuery):
    _ = GetLang(m).strs
Exemple #26
0
async def unlock_perm(c: Mizuhara, m: Message):

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

    _ = GetLang(m).strs
    umsg = ""
    umedia = ""
    ustickers = ""
    uanimations = ""
    ugames = ""
    uinlinebots = ""
    uwebprev = ""
    upolls = ""
    uinfo = ""
    uinvite = ""
    upin = ""
    uperm = ""

    if not len(m.text.split()) >= 2:
        await m.reply_text("Please enter a permission to unlock!")
        return
    unlock_type = m.text.split(" ", 1)[1]
    chat_id = m.chat.id

    if not unlock_type:
        await m.reply_text(_("locks.unlocks_perm.sp_perm"))
        return

    get_uperm = await c.get_chat(chat_id)

    umsg = get_uperm.permissions.can_send_messages
    umedia = get_uperm.permissions.can_send_media_messages
    ustickers = get_uperm.permissions.can_send_stickers
    uanimations = get_uperm.permissions.can_send_animations
    ugames = get_uperm.permissions.can_send_games
    uinlinebots = get_uperm.permissions.can_use_inline_bots
    uwebprev = get_uperm.permissions.can_add_web_page_previews
    upolls = get_uperm.permissions.can_send_polls
    uinfo = get_uperm.permissions.can_change_info
    uinvite = get_uperm.permissions.can_invite_users
    upin = get_uperm.permissions.can_pin_messages

    if unlock_type == "all":
        try:
            await c.set_chat_permissions(
                chat_id,
                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_send_polls=True,
                    can_change_info=True,
                    can_invite_users=True,
                    can_pin_messages=True,
                    can_add_web_page_previews=True,
                ),
            )
            await prevent_approved(c, m)  # Don't lock permissions for approved users!
            await m.reply_text("🔓 " + _("locks.unlock_all"))
        except errors.ChatAdminRequired:
            await m.reply_text(_("general.no_perm_admin"))
        return

    if unlock_type == "msg":
        umsg = True
        uperm = "messages"

    elif unlock_type == "media":
        umedia = True
        uperm = "audios, documents, photos, videos, video notes, voice notes"

    elif unlock_type == "stickers":
        ustickers = True
        uperm = "stickers"

    elif unlock_type == "animations":
        uanimations = True
        uperm = "animations"

    elif unlock_type == "games":
        ugames = True
        uperm = "games"

    elif unlock_type == "inlinebots":
        uinlinebots = True
        uperm = "inline bots"

    elif unlock_type == "webprev":
        uwebprev = True
        uperm = "web page previews"

    elif unlock_type == "polls":
        upolls = True
        uperm = "polls"

    elif unlock_type == "info":
        uinfo = True
        uperm = "info"

    elif unlock_type == "invite":
        uinvite = True
        uperm = "invite"

    elif unlock_type == "pin":
        upin = True
        uperm = "pin"

    else:
        await m.reply_text(_("locks.invalid_lock"))
        return

    try:
        await c.set_chat_permissions(
            chat_id,
            ChatPermissions(
                can_send_messages=umsg,
                can_send_media_messages=umedia,
                can_send_stickers=ustickers,
                can_send_animations=uanimations,
                can_send_games=ugames,
                can_use_inline_bots=uinlinebots,
                can_add_web_page_previews=uwebprev,
                can_send_polls=upolls,
                can_change_info=uinfo,
                can_invite_users=uinvite,
                can_pin_messages=upin,
            ),
        )
        await prevent_approved(c, m)  # Don't lock permissions for approved users!
        await m.reply_text("🔓 " + _("locks.unlocked_perm").format(uperm=uperm))

    except errors.ChatAdminRequired:
        await m.reply_text(_("general.no_perm_admin"))
    return
Exemple #27
0
async def commands_menu(c: Mizuhara, m: CallbackQuery):
    _ = GetLang(m).strs