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"