feat: 支持 gewechat 设置验证码 #448
This commit is contained in:
@@ -302,8 +302,21 @@ class SimpleGewechatClient():
|
||||
"uuid": qr_uuid,
|
||||
"appId": appid
|
||||
})
|
||||
verify_flag = False
|
||||
while retry_cnt > 0:
|
||||
retry_cnt -= 1
|
||||
|
||||
# 需要验证码
|
||||
if verify_flag:
|
||||
with open("data/temp/gewe_code", "r") as f:
|
||||
code = f.read().strip()
|
||||
if not code:
|
||||
logger.warning("未找到验证码,请在管理面板聊天页输入 /gewe_code 验证码 来验证,如 /gewe_code 123456")
|
||||
await asyncio.sleep(5)
|
||||
continue
|
||||
payload['captchCode'] = code
|
||||
logger.info(f"使用验证码: {code}")
|
||||
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.post(
|
||||
f"{self.base_url}/login/checkLogin",
|
||||
@@ -312,17 +325,26 @@ class SimpleGewechatClient():
|
||||
) as resp:
|
||||
json_blob = await resp.json()
|
||||
logger.info(f"检查登录状态: {json_blob}")
|
||||
status = json_blob['data']['status']
|
||||
nickname = json_blob['data'].get('nickName', '')
|
||||
if status == 1:
|
||||
logger.info(f"等待确认...{nickname}")
|
||||
elif status == 2:
|
||||
logger.info(f"绿泡泡平台登录成功: {nickname}")
|
||||
break
|
||||
elif status == 0:
|
||||
logger.info("等待扫码...")
|
||||
|
||||
ret = json_blob['ret']
|
||||
msg = ''
|
||||
if json_blob['data'] and 'msg' in json_blob['data']:
|
||||
msg = json_blob['data']['msg']
|
||||
if ret == 500 and '安全验证码' in msg:
|
||||
logger.warning("此次登录需要安全验证码,请在管理面板聊天页输入 /gewe_code 验证码 来验证,如 /gewe_code 123456")
|
||||
verify_flag = True
|
||||
else:
|
||||
logger.warning(f"未知状态: {status}")
|
||||
status = json_blob['data']['status']
|
||||
nickname = json_blob['data'].get('nickName', '')
|
||||
if status == 1:
|
||||
logger.info(f"等待确认...{nickname}")
|
||||
elif status == 2:
|
||||
logger.info(f"绿泡泡平台登录成功: {nickname}")
|
||||
break
|
||||
elif status == 0:
|
||||
logger.info("等待扫码...")
|
||||
else:
|
||||
logger.warning(f"未知状态: {status}")
|
||||
await asyncio.sleep(5)
|
||||
|
||||
if appid:
|
||||
|
||||
@@ -788,6 +788,14 @@ UID: {user_id} 此 ID 可用于设置管理员。/op <UID> 授权管理员, /deo
|
||||
yield event.plain_result("已登出 gewechat,请重启 AstrBot")
|
||||
return
|
||||
|
||||
|
||||
@filter.command("gewe_code")
|
||||
async def gewe_code(self, event: AstrMessageEvent, code: str):
|
||||
'''保存 gewechat 验证码'''
|
||||
with open("data/temp/gewe_code", "w", encoding='utf-8') as f:
|
||||
f.write(code)
|
||||
yield event.plain_result("验证码已保存。")
|
||||
|
||||
@filter.platform_adapter_type(filter.PlatformAdapterType.ALL)
|
||||
async def on_message(self, event: AstrMessageEvent):
|
||||
'''群聊记忆增强'''
|
||||
|
||||
@@ -17,9 +17,9 @@ class Main(star.Star):
|
||||
|
||||
# set and load config
|
||||
if not os.path.exists("data/astrbot-reminder.json"):
|
||||
with open("data/astrbot-reminder.json", "w") as f:
|
||||
with open("data/astrbot-reminder.json", "w", encoding='utf-8') as f:
|
||||
f.write("{}")
|
||||
with open("data/astrbot-reminder.json", "r") as f:
|
||||
with open("data/astrbot-reminder.json", "r", encoding='utf-8') as f:
|
||||
self.reminder_data = json.load(f)
|
||||
|
||||
self._init_scheduler()
|
||||
@@ -64,7 +64,7 @@ class Main(star.Star):
|
||||
|
||||
async def _save_data(self):
|
||||
'''Save the reminder data.'''
|
||||
with open("data/astrbot-reminder.json", "w") as f:
|
||||
with open("data/astrbot-reminder.json", "w", encoding='utf-8') as f:
|
||||
json.dump(self.reminder_data, f, ensure_ascii=False)
|
||||
|
||||
def _parse_cron_expr(self, cron_expr: str):
|
||||
|
||||
Reference in New Issue
Block a user