Exemplo n.º 1
0
async def on_setting_env(c: Client, cq: CallbackQuery):
    if cq.message:
        cq.message.chat.cancel_listener()
    lang = cq._lang
    buttons = []
    async for row in Config.all():
        btn = (f"👁‍🗨 {row.key}", f"view_env {row.key}")
        if cq.message and cq.message.from_user.id == bot.me.id:
            btn = (f"📝 {row.key}", f"edit_env {row.key}")
        buttons.append(btn)
    lines = array_chunk(buttons, 2)
    lines.append([(lang.back, "settings")])
    keyboard = ikb(lines)
    await cq.edit(lang.settings_env_text, keyboard)
Exemplo n.º 2
0
async def on_setting_language(c: Client, cq: CallbackQuery):
    lang = cq._lang
    buttons = []
    for code, obj in lang.strings.items():
        text, data = (
            (f"✅ {obj['NAME']}", "noop")
            if obj["LANGUAGE_CODE"] == lang.code
            else (obj["NAME"], f"set_language {obj['LANGUAGE_CODE']}")
        )
        buttons.append((text, data))
    lines = array_chunk(buttons, 2)
    lines.append([(lang.back, "settings")])
    keyboard = ikb(lines)
    await cq.edit(lang.choose_language, keyboard)
Exemplo n.º 3
0
async def on_set_language(c: Client, cq: CallbackQuery):
    lang = cq._lang
    match = cq.matches[0]
    lang = lang.get_language(match["code"])
    await Config.get(key="LANGUAGE").update(value=lang.code)
    os.environ["LANGUAGE"] = lang.code
    buttons = []
    for code, obj in lang.strings.items():
        text, data = (
            (f"✅ {obj['NAME']}", "noop")
            if obj["LANGUAGE_CODE"] == lang.code
            else (obj["NAME"], f"set_language {obj['LANGUAGE_CODE']}")
        )
        buttons.append((text, data))
    lines = array_chunk(buttons, 2)
    lines.append([(lang.back, "settings")])
    keyboard = ikb(lines)
    await cq.edit(lang.choose_language, keyboard, {"text": lang.language_chosen})
Exemplo n.º 4
0
async def sudoers_interface(cq: CallbackQuery):
    lang = cq._lang
    c = cq._client
    text = lang.setting_sudoers_text + "\n"
    buttons = []
    added = []
    for user_id in sudoers:
        try:
            user_obj = await c.get_users(user_id)
        except BaseException:
            import traceback

            traceback.print_exc()
            user_obj = None
        id = user_obj.id if user_obj else user_id
        if id in added:
            continue
        added.append(id)

        mention = user_id
        if user_obj:
            mention = (f"@{user_obj.username}"
                       if user_obj.username else user_obj.first_name)
        text += f"\n👤 {mention}"

        if id not in ["me", user.me.id, cq.from_user.id]:
            buttons.append((f"🗑 {mention}", f"remove_sudoer {user_id}"))

    lines = array_chunk(buttons, 2)
    if bot.me.username:
        lines.append([(
            lang.add_sudoer,
            f"https://t.me/{bot.me.username}?start=add_sudoer",
            "url",
        )])
    lines.append([(lang.back, "settings")])
    keyboard = ikb(lines)
    return text, keyboard