pmcaptcha web configure

Co-authored-by: omg-xtao <100690902+omg-xtao@users.noreply.github.com>
This commit is contained in:
Cloudreflection 2023-04-05 19:06:58 +08:00 committed by GitHub
parent 6cbaf243f5
commit 2a1d9e33c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,6 +9,7 @@ from io import BytesIO
from dataclasses import dataclass, field from dataclasses import dataclass, field
from random import randint from random import randint
from typing import Optional, Callable, Union, List, Any, Dict, Coroutine from typing import Optional, Callable, Union, List, Any, Dict, Coroutine
from base64 import b64decode, b64encode
from pyrogram.errors import (FloodWait, AutoarchiveNotAvailable, ChannelsAdminPublicTooMuch, from pyrogram.errors import (FloodWait, AutoarchiveNotAvailable, ChannelsAdminPublicTooMuch,
BotResponseTimeout, PeerIdInvalid) BotResponseTimeout, PeerIdInvalid)
@ -29,6 +30,8 @@ from pagermaid.single_utils import sqlite
cmd_name = "pmcaptcha" cmd_name = "pmcaptcha"
lang_version = "2.25"
log_collect_bot = img_captcha_bot = "PagerMaid_Sam_Bot" log_collect_bot = img_captcha_bot = "PagerMaid_Sam_Bot"
# Get alias for user command # Get alias for user command
@ -87,7 +90,7 @@ def str_timestamp(unix_ts: int) -> str:
def get_lang_list(): # Yes, blocking def get_lang_list(): # Yes, blocking
from httpx import Client from httpx import Client
endpoint = f"https://raw.githubusercontent.com/TeamPGM/PMCaptcha-i18n/main/v{get_version()}.py" endpoint = f"https://raw.githubusercontent.com/TeamPGM/PMCaptcha-i18n/main/v{lang_version}.py"
for _ in range(3): for _ in range(3):
try: try:
with Client() as client: with Client() as client:
@ -438,7 +441,7 @@ class Command:
"""显示指令帮助信息,使用 <code>,{cmd_name} search [搜索内容]</code> 进行文档、指令(和别名)搜索 """显示指令帮助信息,使用 <code>,{cmd_name} search [搜索内容]</code> 进行文档、指令(和别名)搜索
:param opt command: 命令名称 :param opt command: 命令名称
:param opt search_str: 搜索的文字只有 <code>command</code< <code>search</code> 时有效 :param opt search_str: 搜索的文字只有 <code>command</code> <code>search</code> 时有效
:alias: h :alias: h
""" """
help_msg = [f"{code('PMCaptcha')} {lang('cmd_list')}:", ""] help_msg = [f"{code('PMCaptcha')} {lang('cmd_list')}:", ""]
@ -1117,6 +1120,35 @@ class Command:
setting.set("img_max_retry", number) setting.set("img_max_retry", number)
await self._edit(lang('img_captcha_retry_set') % number) await self._edit(lang('img_captcha_retry_set') % number)
async def web_configure(self, config: Optional[str]):
"""PMCaptcha 网页可视化配置
:alias: web
"""
if not config:
config = sqlite[setting.key_name]
config['version'] = get_version()
config['cmd'] = user_cmd_name
for key in ("pass", "banned", "flooded"):
if config.get(key):
del config[key]
config = b64encode(json.dumps(config).encode("utf-8")).decode("utf-8")
await self._edit(
f"网页配置链接: https://pmc-config.xtaolabs.com/{config}"
)
return
try:
nc = json.loads(b64decode(config))
except Exception:
await self._edit(lang("import_failed"))
return
for i in nc:
if nc[i] == -1:
setting.delete(i)
else:
setting.set(i, nc[i])
await self._edit(lang("import_success"))
# region Captcha # region Captcha