From 858057b1509c454f9909cc5e8e66ffbfcd6901c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98KimigaiiWuyi=E2=80=99?= <444835641@qq.com> Date: Tue, 14 Nov 2023 19:48:31 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=9B=B4=E5=A4=9A=E9=80=82=E9=85=8D=E5=99=A8,=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=B7=B2=E7=9F=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GenshinUID/client.py | 41 +++++++++++++++++++++++++++-------------- pyproject.toml | 4 ++-- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/GenshinUID/client.py b/GenshinUID/client.py index 6eaddb81..6e515abd 100644 --- a/GenshinUID/client.py +++ b/GenshinUID/client.py @@ -41,6 +41,8 @@ def _get_bot(bot_id: str) -> Bot: bot_id = 'onebotv12' elif 'red' in bot_id: bot_id = 'RedProtocol' + elif 'qqguild' in bot_id: + bot_id = 'qq' # bots: Dict[str, str] 以适配器名称为键、bot_self_id为值的字典 _refresh_bots() if bot_id not in bots: @@ -623,11 +625,19 @@ async def guild_send( msg_id: Optional[str], guild_id: Optional[str], ): + from nonebot.adapters.qq.exception import ActionFailed + from nonebot.adapters.qq.bot import Bot as qqbot + + assert isinstance(bot, qqbot) + async def _send(content: Optional[str], image: Optional[str]): result: Dict[str, Any] = {'msg_id': msg_id} if image: - img_bytes = base64.b64decode(image.replace('base64://', '')) - result['file_image'] = img_bytes + if image.startswith('link://'): + result['image'] = image.replace('link://', '') + else: + img_bytes = base64.b64decode(image.replace('base64://', '')) + result['file_image'] = img_bytes if content: result['content'] = content if at_list and target_type == 'group': @@ -639,22 +649,25 @@ async def guild_send( logger.warning('[gscore] qqguild暂不支持发送buttons消息') if target_type == 'group': - await bot.call_api( - 'post_messages', + await bot.post_messages( channel_id=str(target_id) if target_id else 0, **result, ) else: - dms = await bot.call_api( - 'post_dms', - recipient_id=str(target_id), - source_guild_id=str(guild_id), - ) - await bot.call_api( - 'post_dms_messages', - guild_id=dms.guild_id, - **result, - ) + try: + await bot.post_dms_messages( + guild_id=str(guild_id), + **result, + ) + except ActionFailed: + dms = await bot.post_dms( + recipient_id=str(target_id), + source_guild_id=str(guild_id), + ) + await bot.post_dms_messages( + guild_id=dms.guild_id, + **result, + ) if node: for _msg in node: diff --git a/pyproject.toml b/pyproject.toml index 54a56bd1..82158c56 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,8 +23,8 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "nonebot-plugin-genshinuid" -version = "4.3.1" -description = "支持OneBot(QQ)、OneBotV12、QQ频道、微信、KOOK(开黑啦)、Telegram(电报)、FeiShu(飞书)的全功能NoneBot2原神插件" +version = "4.4.0" +description = "支持OneBot(QQ)、OneBotV12、QQ频道、微信、KOOK(开黑啦)、Telegram(电报)、FeiShu(飞书)、DoDo、Villa(米游社大别野)、Discord的全功能NoneBot2原神插件" authors = ["KimigaiiWuyi <444835641@qq.com>"] license = "GPL-3.0-or-later" readme = "README.md"