mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-07 04:40:00 +08:00
🐛 修复添加插件依赖更新 (#1837)
* 🐛 修复添加插件依赖更新 * 🔧 修改插件依赖安装命令为使用poetry运行pip * 🐛 修复群组入群与退群提示 * 🐛 修复群组踢出用户提醒 * 🎨 代码优化 * 🎨 群欢迎迁移优化 * 🩹 精确webui调用统计 * 🚨 auto fix by pre-commit hooks * 🐛 修复测试 * 🎨 fix pre-commit.ci * 🎨 fix pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
pre-commit-ci[bot]
parent
d6fd5f170a
commit
4ed1791b30
@@ -0,0 +1,16 @@
|
||||
from httpx import ConnectError, HTTPStatusError, TimeoutException
|
||||
from tenacity import retry, retry_if_exception_type, stop_after_attempt, wait_fixed
|
||||
|
||||
|
||||
class Retry:
|
||||
@staticmethod
|
||||
def api():
|
||||
"""接口调用重试"""
|
||||
return retry(
|
||||
reraise=True,
|
||||
stop=stop_after_attempt(3),
|
||||
wait=wait_fixed(1),
|
||||
retry=retry_if_exception_type(
|
||||
(TimeoutException, ConnectError, HTTPStatusError)
|
||||
),
|
||||
)
|
||||
+29
-23
@@ -7,6 +7,7 @@ import time
|
||||
from typing import Any, ClassVar, Literal
|
||||
|
||||
import aiofiles
|
||||
from anyio import EndOfStream
|
||||
import httpx
|
||||
from httpx import ConnectTimeout, HTTPStatusError, Response
|
||||
from nonebot_plugin_alconna import UniMessage
|
||||
@@ -41,7 +42,7 @@ class AsyncHttpx:
|
||||
verify: bool = True,
|
||||
use_proxy: bool = True,
|
||||
proxy: dict[str, str] | None = None,
|
||||
timeout: int = 30,
|
||||
timeout: int = 30, # noqa: ASYNC109
|
||||
**kwargs,
|
||||
) -> Response:
|
||||
"""Get
|
||||
@@ -96,7 +97,7 @@ class AsyncHttpx:
|
||||
verify: bool = True,
|
||||
use_proxy: bool = True,
|
||||
proxy: dict[str, str] | None = None,
|
||||
timeout: int = 30,
|
||||
timeout: int = 30, # noqa: ASYNC109
|
||||
**kwargs,
|
||||
) -> Response:
|
||||
if not headers:
|
||||
@@ -123,7 +124,7 @@ class AsyncHttpx:
|
||||
verify: bool = True,
|
||||
use_proxy: bool = True,
|
||||
proxy: dict[str, str] | None = None,
|
||||
timeout: int = 30,
|
||||
timeout: int = 30, # noqa: ASYNC109
|
||||
**kwargs,
|
||||
) -> Response:
|
||||
"""Get
|
||||
@@ -166,7 +167,7 @@ class AsyncHttpx:
|
||||
params: dict[str, str] | None = None,
|
||||
headers: dict[str, str] | None = None,
|
||||
cookies: dict[str, str] | None = None,
|
||||
timeout: int = 30,
|
||||
timeout: int = 30, # noqa: ASYNC109
|
||||
**kwargs,
|
||||
) -> Response:
|
||||
"""
|
||||
@@ -219,7 +220,7 @@ class AsyncHttpx:
|
||||
proxy: dict[str, str] | None = None,
|
||||
headers: dict[str, str] | None = None,
|
||||
cookies: dict[str, str] | None = None,
|
||||
timeout: int = 30,
|
||||
timeout: int = 30, # noqa: ASYNC109
|
||||
stream: bool = False,
|
||||
follow_redirects: bool = True,
|
||||
**kwargs,
|
||||
@@ -311,12 +312,17 @@ class AsyncHttpx:
|
||||
completed=response.num_bytes_downloaded,
|
||||
)
|
||||
logger.info(
|
||||
f"下载 {u} 成功.. "
|
||||
f"Path:{path.absolute()}"
|
||||
f"下载 {u} 成功.. Path:{path.absolute()}"
|
||||
)
|
||||
return True
|
||||
except (TimeoutError, ConnectTimeout, HTTPStatusError):
|
||||
logger.warning(f"下载 {u} 失败.. 尝试下一个地址..")
|
||||
except EndOfStream as e:
|
||||
logger.warning(
|
||||
f"下载 {url} EndOfStream 异常 Path:{path.absolute()}", e=e
|
||||
)
|
||||
if path.exists():
|
||||
return True
|
||||
logger.error(f"下载 {url} 下载超时.. Path:{path.absolute()}")
|
||||
except Exception as e:
|
||||
logger.error(f"下载 {url} 错误 Path:{path.absolute()}", e=e)
|
||||
@@ -334,7 +340,7 @@ class AsyncHttpx:
|
||||
proxy: dict[str, str] | None = None,
|
||||
headers: dict[str, str] | None = None,
|
||||
cookies: dict[str, str] | None = None,
|
||||
timeout: int = 30,
|
||||
timeout: int = 30, # noqa: ASYNC109
|
||||
**kwargs,
|
||||
) -> list[bool]:
|
||||
"""分组同时下载文件
|
||||
@@ -374,22 +380,22 @@ class AsyncHttpx:
|
||||
tasks = []
|
||||
result_ = []
|
||||
for x, y in zip(_split_url_list, _split_path_list):
|
||||
for url, path in zip(x, y):
|
||||
tasks.append(
|
||||
asyncio.create_task(
|
||||
cls.download_file(
|
||||
url,
|
||||
path,
|
||||
params=params,
|
||||
headers=headers,
|
||||
cookies=cookies,
|
||||
use_proxy=use_proxy,
|
||||
timeout=timeout,
|
||||
proxy=proxy,
|
||||
**kwargs,
|
||||
)
|
||||
tasks.extend(
|
||||
asyncio.create_task(
|
||||
cls.download_file(
|
||||
url,
|
||||
path,
|
||||
params=params,
|
||||
headers=headers,
|
||||
cookies=cookies,
|
||||
use_proxy=use_proxy,
|
||||
timeout=timeout,
|
||||
proxy=proxy,
|
||||
**kwargs,
|
||||
)
|
||||
)
|
||||
for url, path in zip(x, y)
|
||||
)
|
||||
_x = await asyncio.gather(*tasks)
|
||||
result_ = result_ + list(_x)
|
||||
tasks.clear()
|
||||
@@ -465,7 +471,7 @@ class AsyncPlaywright:
|
||||
wait_until: (
|
||||
Literal["domcontentloaded", "load", "networkidle"] | None
|
||||
) = "networkidle",
|
||||
timeout: float | None = None,
|
||||
timeout: float | None = None, # noqa: ASYNC109
|
||||
type_: Literal["jpeg", "png"] | None = None,
|
||||
user_agent: str | None = None,
|
||||
cookies: list[dict[str, Any]] | dict[str, Any] | None = None,
|
||||
|
||||
@@ -17,6 +17,7 @@ from nonebot_plugin_alconna import (
|
||||
Voice,
|
||||
)
|
||||
from pydantic import BaseModel
|
||||
import ujson as json
|
||||
|
||||
from zhenxun.configs.config import BotConfig
|
||||
from zhenxun.services.log import logger
|
||||
@@ -141,6 +142,21 @@ class MessageUtils:
|
||||
)
|
||||
return UniMessage(Reference(nodes=node_list))
|
||||
|
||||
@classmethod
|
||||
def markdown(cls, content: dict) -> Message:
|
||||
"""markdown格式消息
|
||||
|
||||
参数:
|
||||
content: 消息内容
|
||||
|
||||
返回:
|
||||
Message: 构造完成的消息
|
||||
"""
|
||||
content_data = base64.b64encode(json.dumps(content).encode("utf-8")).decode(
|
||||
"utf-8"
|
||||
)
|
||||
return Message(f"[CQ:markdown,data=base64://{content_data}]")
|
||||
|
||||
@classmethod
|
||||
def custom_forward_msg(
|
||||
cls,
|
||||
|
||||
+25
-25
@@ -55,6 +55,8 @@ class PlatformUtils:
|
||||
"""
|
||||
if isinstance(session, Bot):
|
||||
return bool(BotConfig.get_qbot_uid(session.self_id))
|
||||
if BotConfig.get_qbot_uid(session.self_id):
|
||||
return True
|
||||
return session.scope == SupportScope.qq_api
|
||||
|
||||
@classmethod
|
||||
@@ -354,32 +356,30 @@ class PlatformUtils:
|
||||
返回:
|
||||
tuple[list[GroupConsole], str]: 群组列表, 平台
|
||||
"""
|
||||
if interface := get_interface(bot):
|
||||
platform = cls.get_platform(bot)
|
||||
result_list = []
|
||||
scenes = await interface.get_scenes(SceneType.GROUP)
|
||||
for scene in scenes:
|
||||
group_id = scene.id
|
||||
result_list.append(
|
||||
GroupConsole(
|
||||
group_id=scene.id,
|
||||
group_name=scene.name,
|
||||
)
|
||||
if not (interface := get_interface(bot)):
|
||||
return [], ""
|
||||
platform = cls.get_platform(bot)
|
||||
result_list = []
|
||||
scenes = await interface.get_scenes(SceneType.GROUP)
|
||||
for scene in scenes:
|
||||
group_id = scene.id
|
||||
result_list.append(
|
||||
GroupConsole(
|
||||
group_id=scene.id,
|
||||
group_name=scene.name,
|
||||
)
|
||||
if not only_group and platform != "qq":
|
||||
if channel_list := await interface.get_scenes(
|
||||
parent_scene_id=group_id
|
||||
):
|
||||
for channel in channel_list:
|
||||
result_list.append(
|
||||
GroupConsole(
|
||||
group_id=scene.id,
|
||||
group_name=channel.name,
|
||||
channel_id=channel.id,
|
||||
)
|
||||
)
|
||||
return result_list, platform
|
||||
return [], ""
|
||||
)
|
||||
if not only_group and platform != "qq":
|
||||
if channel_list := await interface.get_scenes(parent_scene_id=group_id):
|
||||
result_list.extend(
|
||||
GroupConsole(
|
||||
group_id=scene.id,
|
||||
group_name=channel.name,
|
||||
channel_id=channel.id,
|
||||
)
|
||||
for channel in channel_list
|
||||
)
|
||||
return result_list, platform
|
||||
|
||||
@classmethod
|
||||
async def update_friend(cls, bot: Bot) -> int:
|
||||
|
||||
Reference in New Issue
Block a user