diff --git a/GenshinUID/__init__.py b/GenshinUID/__init__.py index 5330d876..cad0d7d6 100644 --- a/GenshinUID/__init__.py +++ b/GenshinUID/__init__.py @@ -134,6 +134,8 @@ async def get_all_message(bot: Bot, ev: Event): if bot.adapter.get_name() == 'QQ Guild': from nonebot.adapters.qqguild.event import ( MessageEvent, + C2CMessageCreate, + GroupAtMessageCreate, DirectMessageCreateEvent, ) @@ -142,6 +144,16 @@ async def get_all_message(bot: Bot, ev: Event): user_type = 'direct' group_id = str(ev.guild_id) msg_id = ev.id + elif isinstance(ev, GroupAtMessageCreate): + sp_bot_id = 'qqgroup' + user_type = 'group' + group_id = str(ev.group_id) + msg_id = ev.id + elif isinstance(ev, C2CMessageCreate): + sp_bot_id = 'qqgroup' + user_type = 'direct' + group_id = None + msg_id = ev.id # 群聊 elif isinstance(ev, MessageEvent): user_type = 'group' diff --git a/GenshinUID/client.py b/GenshinUID/client.py index f2d02eab..fda02476 100644 --- a/GenshinUID/client.py +++ b/GenshinUID/client.py @@ -211,6 +211,17 @@ class GsClient: msg.target_id, msg.target_type, ) + elif msg.bot_id == 'qqgroup': + await group_send( + bot, + content, + image, + node, + at_list, + msg.target_id, + msg.target_type, + msg.msg_id, + ) elif msg.bot_id == 'feishu': await feishu_send( bot, @@ -411,6 +422,50 @@ async def guild_send( await _send(content, image) +async def group_send( + bot: Bot, + content: Optional[str], + image: Optional[str], + node: Optional[List[Dict]], + at_list: Optional[List[str]], + target_id: Optional[str], + target_type: Optional[str], + msg_id: Optional[str], +): + async def _send(content: Optional[str], image: Optional[str]): + result: Dict[str, Any] = {} + if content: + result['content'] = content + if image: + result['image'] = image + if target_type == 'group': + await bot.post_group_message( + group_id=target_id, + msg_id=msg_id, + event_id=msg_id, + **result, + ) + else: + await bot.post_c2c_message( + user_id=target_id, + msg_id=msg_id, + event_id=msg_id, + **result, + ) + + if node: + for _msg in node: + if _msg['type'] == 'image': + image = _msg['data'] + content = None + else: + image = None + content = _msg['data'] + await _send(content, image) + else: + await _send(content, image) + + async def ntchat_send( bot: Bot, content: Optional[str], diff --git a/pyproject.toml b/pyproject.toml index 96f8efac..7b66f807 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "nonebot-plugin-genshinuid" -version = "4.0.6" +version = "4.1.0" description = "支持OneBot(QQ)、OneBotV12、QQ频道、微信、KOOK(开黑啦)、Telegram(电报)、FeiShu(飞书)的全功能NoneBot2原神插件" authors = ["KimigaiiWuyi <444835641@qq.com>"] license = "GPL-3.0-or-later"