From 3469515e044f9546bb0b2b58c1b2f5127add3772 Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Thu, 26 Sep 2024 13:01:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=A0=E9=99=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=B8=AD=E5=AF=B9=20mirai=20=E7=9A=84=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/ISSUE_TEMPLATE/bug-report.yml | 2 +- .github/dependabot.yml | 1 - .github/pull_request_template.md | 3 ++ pkg/command/entities.py | 1 - pkg/core/bootutils/deps.py | 1 - pkg/core/entities.py | 1 - pkg/pipeline/cntfilter/cntfilter.py | 4 --- pkg/pipeline/controller.py | 1 - pkg/pipeline/entities.py | 5 --- pkg/pipeline/longtext/longtext.py | 1 - pkg/pipeline/longtext/strategies/forward.py | 3 -- pkg/pipeline/longtext/strategies/image.py | 2 -- pkg/pipeline/longtext/strategy.py | 2 -- pkg/pipeline/pool.py | 1 - pkg/pipeline/preproc/preproc.py | 1 - pkg/pipeline/process/handlers/chat.py | 1 - pkg/pipeline/process/handlers/command.py | 1 - pkg/pipeline/respback/respback.py | 1 - pkg/pipeline/resprule/entities.py | 1 - pkg/pipeline/resprule/resprule.py | 1 - pkg/pipeline/resprule/rule.py | 2 -- pkg/pipeline/resprule/rules/atbot.py | 1 - pkg/pipeline/resprule/rules/prefix.py | 1 - pkg/pipeline/resprule/rules/random.py | 1 - pkg/pipeline/resprule/rules/regexp.py | 1 - pkg/pipeline/wrapper/wrapper.py | 14 +++----- pkg/platform/adapter.py | 39 ++++++++++----------- pkg/platform/manager.py | 2 -- pkg/platform/sources/aiocqhttp.py | 2 -- pkg/platform/sources/nakuru.py | 1 - pkg/platform/sources/qqbotpy.py | 1 - pkg/platform/sources/yirimirai.py | 3 -- pkg/platform/types/base.py | 14 ++++---- pkg/platform/types/message.py | 13 ++----- pkg/plugin/context.py | 5 ++- pkg/plugin/events.py | 1 - pkg/provider/entities.py | 9 +++-- requirements.txt | 1 - 38 files changed, 42 insertions(+), 103 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml index 12f9b83..a5947b0 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.yml +++ b/.github/ISSUE_TEMPLATE/bug-report.yml @@ -8,10 +8,10 @@ body: label: 消息平台适配器 description: "连接QQ使用的框架" options: - - yiri-mirai(Mirai) - Nakuru(go-cqhttp) - aiocqhttp(使用 OneBot 协议接入的) - qq-botpy(QQ官方API) + - yiri-mirai(Mirai) validations: required: false - type: input diff --git a/.github/dependabot.yml b/.github/dependabot.yml index d1973eb..53c5849 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -10,5 +10,4 @@ updates: schedule: interval: "weekly" allow: - - dependency-name: "yiri-mirai-rc" - dependency-name: "openai" diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 6b636c2..a4b3a1a 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -6,8 +6,11 @@ ### PR 作者完成 +*请在方括号间写`x`以打勾 + - [ ] 阅读仓库[贡献指引](https://github.com/RockChinQ/QChatGPT/blob/master/CONTRIBUTING.md)了吗? - [ ] 与项目所有者沟通过了吗? +- [ ] 我确定已自行测试所作的更改,确保功能符合预期。 ### 项目所有者完成 diff --git a/pkg/command/entities.py b/pkg/command/entities.py index 3ea660f..463dfe3 100644 --- a/pkg/command/entities.py +++ b/pkg/command/entities.py @@ -3,7 +3,6 @@ from __future__ import annotations import typing import pydantic -# import mirai from ..core import app, entities as core_entities from . import errors, operator diff --git a/pkg/core/bootutils/deps.py b/pkg/core/bootutils/deps.py index e7df3e8..c392f80 100644 --- a/pkg/core/bootutils/deps.py +++ b/pkg/core/bootutils/deps.py @@ -5,7 +5,6 @@ required_deps = { "openai": "openai", "anthropic": "anthropic", "colorlog": "colorlog", - "mirai": "yiri-mirai-rc", "aiocqhttp": "aiocqhttp", "botpy": "qq-botpy", "PIL": "pillow", diff --git a/pkg/core/entities.py b/pkg/core/entities.py index 744c6d0..dbaa5ff 100644 --- a/pkg/core/entities.py +++ b/pkg/core/entities.py @@ -6,7 +6,6 @@ import datetime import asyncio import pydantic -# import mirai from ..provider import entities as llm_entities from ..provider.modelmgr import entities diff --git a/pkg/pipeline/cntfilter/cntfilter.py b/pkg/pipeline/cntfilter/cntfilter.py index f0c5428..f7376b6 100644 --- a/pkg/pipeline/cntfilter/cntfilter.py +++ b/pkg/pipeline/cntfilter/cntfilter.py @@ -1,9 +1,5 @@ from __future__ import annotations -# import mirai -# import mirai.models -# import mirai.models.message - from ...core import app from .. import stage, entities, stagemgr diff --git a/pkg/pipeline/controller.py b/pkg/pipeline/controller.py index 27b96de..0f07e06 100644 --- a/pkg/pipeline/controller.py +++ b/pkg/pipeline/controller.py @@ -4,7 +4,6 @@ import asyncio import typing import traceback -# import mirai from ..core import app, entities from . import entities as pipeline_entities diff --git a/pkg/pipeline/entities.py b/pkg/pipeline/entities.py index 347f5db..cbeb3d0 100644 --- a/pkg/pipeline/entities.py +++ b/pkg/pipeline/entities.py @@ -4,7 +4,6 @@ import enum import typing import pydantic -# import mirai from ..platform.types import message as platform_message from ..core import entities @@ -28,10 +27,6 @@ class StageProcessResult(pydantic.BaseModel): user_notice: typing.Optional[typing.Union[str, list[platform_message.MessageComponent], platform_message.MessageChain, None]] = [] """只要设置了就会发送给用户""" - # TODO delete - # admin_notice: typing.Optional[typing.Union[str, list[mirai_message.MessageComponent], mirai.MessageChain, None]] = [] - """只要设置了就会发送给管理员""" - console_notice: typing.Optional[str] = '' """只要设置了就会输出到控制台""" diff --git a/pkg/pipeline/longtext/longtext.py b/pkg/pipeline/longtext/longtext.py index d3715b7..ecb745d 100644 --- a/pkg/pipeline/longtext/longtext.py +++ b/pkg/pipeline/longtext/longtext.py @@ -3,7 +3,6 @@ import os import traceback from PIL import Image, ImageDraw, ImageFont -# from mirai.models.message import MessageComponent, Plain, MessageChain from ...core import app from . import strategy diff --git a/pkg/pipeline/longtext/strategies/forward.py b/pkg/pipeline/longtext/strategies/forward.py index 206bf08..c39c920 100644 --- a/pkg/pipeline/longtext/strategies/forward.py +++ b/pkg/pipeline/longtext/strategies/forward.py @@ -2,9 +2,6 @@ from __future__ import annotations import typing -# from mirai.models import MessageChain -# from mirai.models.message import MessageComponent, ForwardMessageNode -# from mirai.models.base import MiraiBaseModel import pydantic from .. import strategy as strategy_model diff --git a/pkg/pipeline/longtext/strategies/image.py b/pkg/pipeline/longtext/strategies/image.py index 3b1805c..9e32e59 100644 --- a/pkg/pipeline/longtext/strategies/image.py +++ b/pkg/pipeline/longtext/strategies/image.py @@ -8,8 +8,6 @@ import re from PIL import Image, ImageDraw, ImageFont -# from mirai.models import MessageChain, Image as ImageComponent -# from mirai.models.message import MessageComponent from ....platform.types import message as platform_message from .. import strategy as strategy_model diff --git a/pkg/pipeline/longtext/strategy.py b/pkg/pipeline/longtext/strategy.py index 5bc46a3..6f66bbf 100644 --- a/pkg/pipeline/longtext/strategy.py +++ b/pkg/pipeline/longtext/strategy.py @@ -2,8 +2,6 @@ from __future__ import annotations import abc import typing -# import mirai -# from mirai.models.message import MessageComponent from ...core import app from ...core import entities as core_entities diff --git a/pkg/pipeline/pool.py b/pkg/pipeline/pool.py index b7f7951..45f16e6 100644 --- a/pkg/pipeline/pool.py +++ b/pkg/pipeline/pool.py @@ -2,7 +2,6 @@ from __future__ import annotations import asyncio -# import mirai from ..core import entities from ..platform import adapter as msadapter diff --git a/pkg/pipeline/preproc/preproc.py b/pkg/pipeline/preproc/preproc.py index 976c8f7..3a71a84 100644 --- a/pkg/pipeline/preproc/preproc.py +++ b/pkg/pipeline/preproc/preproc.py @@ -1,6 +1,5 @@ from __future__ import annotations -# import mirai from .. import stage, entities, stagemgr from ...core import entities as core_entities diff --git a/pkg/pipeline/process/handlers/chat.py b/pkg/pipeline/process/handlers/chat.py index d87e285..6e192b7 100644 --- a/pkg/pipeline/process/handlers/chat.py +++ b/pkg/pipeline/process/handlers/chat.py @@ -5,7 +5,6 @@ import time import traceback import json -# import mirai from .. import handler from ... import entities diff --git a/pkg/pipeline/process/handlers/command.py b/pkg/pipeline/process/handlers/command.py index 5f6ed6e..cec64a4 100644 --- a/pkg/pipeline/process/handlers/command.py +++ b/pkg/pipeline/process/handlers/command.py @@ -1,7 +1,6 @@ from __future__ import annotations import typing -# import mirai from .. import handler from ... import entities diff --git a/pkg/pipeline/respback/respback.py b/pkg/pipeline/respback/respback.py index 1b0cd3a..d3dd83f 100644 --- a/pkg/pipeline/respback/respback.py +++ b/pkg/pipeline/respback/respback.py @@ -3,7 +3,6 @@ from __future__ import annotations import random import asyncio -# import mirai from ...core import app diff --git a/pkg/pipeline/resprule/entities.py b/pkg/pipeline/resprule/entities.py index 42c2092..2292715 100644 --- a/pkg/pipeline/resprule/entities.py +++ b/pkg/pipeline/resprule/entities.py @@ -1,5 +1,4 @@ import pydantic -# import mirai from ...platform.types import message as platform_message diff --git a/pkg/pipeline/resprule/resprule.py b/pkg/pipeline/resprule/resprule.py index aa07bb7..77858f0 100644 --- a/pkg/pipeline/resprule/resprule.py +++ b/pkg/pipeline/resprule/resprule.py @@ -1,6 +1,5 @@ from __future__ import annotations -# import mirai from ...core import app from . import entities as rule_entities, rule diff --git a/pkg/pipeline/resprule/rule.py b/pkg/pipeline/resprule/rule.py index b40e5ac..ad69d8a 100644 --- a/pkg/pipeline/resprule/rule.py +++ b/pkg/pipeline/resprule/rule.py @@ -2,8 +2,6 @@ from __future__ import annotations import abc import typing -# import mirai - from ...core import app, entities as core_entities from . import entities diff --git a/pkg/pipeline/resprule/rules/atbot.py b/pkg/pipeline/resprule/rules/atbot.py index d767f95..a0b7a7c 100644 --- a/pkg/pipeline/resprule/rules/atbot.py +++ b/pkg/pipeline/resprule/rules/atbot.py @@ -1,6 +1,5 @@ from __future__ import annotations -# import mirai from .. import rule as rule_model from .. import entities diff --git a/pkg/pipeline/resprule/rules/prefix.py b/pkg/pipeline/resprule/rules/prefix.py index c010c0f..fb7bbcf 100644 --- a/pkg/pipeline/resprule/rules/prefix.py +++ b/pkg/pipeline/resprule/rules/prefix.py @@ -1,4 +1,3 @@ -# import mirai from .. import rule as rule_model from .. import entities diff --git a/pkg/pipeline/resprule/rules/random.py b/pkg/pipeline/resprule/rules/random.py index bf8603a..0178f2c 100644 --- a/pkg/pipeline/resprule/rules/random.py +++ b/pkg/pipeline/resprule/rules/random.py @@ -1,6 +1,5 @@ import random -# import mirai from .. import rule as rule_model from .. import entities diff --git a/pkg/pipeline/resprule/rules/regexp.py b/pkg/pipeline/resprule/rules/regexp.py index a6a3ecd..f5f5b3f 100644 --- a/pkg/pipeline/resprule/rules/regexp.py +++ b/pkg/pipeline/resprule/rules/regexp.py @@ -1,6 +1,5 @@ import re -# import mirai from .. import rule as rule_model from .. import entities diff --git a/pkg/pipeline/wrapper/wrapper.py b/pkg/pipeline/wrapper/wrapper.py index 0e09382..1ffb314 100644 --- a/pkg/pipeline/wrapper/wrapper.py +++ b/pkg/pipeline/wrapper/wrapper.py @@ -2,7 +2,6 @@ from __future__ import annotations import typing -# import mirai from ...core import app, entities as core_entities from .. import entities @@ -46,19 +45,14 @@ class ResponseWrapper(stage.PipelineStage): else: if query.resp_messages[-1].role == 'command': - # query.resp_message_chain.append(mirai.MessageChain("[bot] "+query.resp_messages[-1].content)) - query.resp_message_chain.append(query.resp_messages[-1].get_content_mirai_message_chain(prefix_text='[bot] ')) + query.resp_message_chain.append(query.resp_messages[-1].get_content_platform_message_chain(prefix_text='[bot] ')) yield entities.StageProcessResult( result_type=entities.ResultType.CONTINUE, new_query=query ) elif query.resp_messages[-1].role == 'plugin': - # if not isinstance(query.resp_messages[-1].content, mirai.MessageChain): - # query.resp_message_chain.append(mirai.MessageChain(query.resp_messages[-1].content)) - # else: - # query.resp_message_chain.append(query.resp_messages[-1].content) - query.resp_message_chain.append(query.resp_messages[-1].get_content_mirai_message_chain()) + query.resp_message_chain.append(query.resp_messages[-1].get_content_platform_message_chain()) yield entities.StageProcessResult( result_type=entities.ResultType.CONTINUE, @@ -73,7 +67,7 @@ class ResponseWrapper(stage.PipelineStage): reply_text = '' if result.content: # 有内容 - reply_text = str(result.get_content_mirai_message_chain()) + reply_text = str(result.get_content_platform_message_chain()) # ============= 触发插件事件 =============== event_ctx = await self.ap.plugin_mgr.emit_event( @@ -101,7 +95,7 @@ class ResponseWrapper(stage.PipelineStage): else: - query.resp_message_chain.append(result.get_content_mirai_message_chain()) + query.resp_message_chain.append(result.get_content_platform_message_chain()) yield entities.StageProcessResult( result_type=entities.ResultType.CONTINUE, diff --git a/pkg/platform/adapter.py b/pkg/platform/adapter.py index c6d97b3..7cf64a1 100644 --- a/pkg/platform/adapter.py +++ b/pkg/platform/adapter.py @@ -4,7 +4,6 @@ from __future__ import annotations import typing import abc -# import mirai from ..core import app from .types import message as platform_message @@ -64,7 +63,7 @@ class MessageSourceAdapter(metaclass=abc.ABCMeta): Args: target_type (str): 目标类型,`person`或`group` target_id (str): 目标ID - message (mirai.MessageChain): YiriMirai库的消息链 + message (platform.types.MessageChain): 消息链 """ raise NotImplementedError @@ -77,8 +76,8 @@ class MessageSourceAdapter(metaclass=abc.ABCMeta): """回复消息 Args: - message_source (mirai.MessageEvent): YiriMirai消息源事件 - message (mirai.MessageChain): YiriMirai库的消息链 + message_source (platform.types.MessageEvent): 消息源事件 + message (platform.types.MessageChain): 消息链 quote_origin (bool, optional): 是否引用原消息. Defaults to False. """ raise NotImplementedError @@ -95,8 +94,8 @@ class MessageSourceAdapter(metaclass=abc.ABCMeta): """注册事件监听器 Args: - event_type (typing.Type[mirai.Event]): YiriMirai事件类型 - callback (typing.Callable[[mirai.Event], None]): 回调函数,接收一个参数,为YiriMirai事件 + event_type (typing.Type[platform.types.Event]): 事件类型 + callback (typing.Callable[[platform.types.Event], None]): 回调函数,接收一个参数,为事件 """ raise NotImplementedError @@ -108,8 +107,8 @@ class MessageSourceAdapter(metaclass=abc.ABCMeta): """注销事件监听器 Args: - event_type (typing.Type[mirai.Event]): YiriMirai事件类型 - callback (typing.Callable[[mirai.Event], None]): 回调函数,接收一个参数,为YiriMirai事件 + event_type (typing.Type[platform.types.Event]): 事件类型 + callback (typing.Callable[[platform.types.Event], None]): 回调函数,接收一个参数,为事件 """ raise NotImplementedError @@ -130,25 +129,25 @@ class MessageConverter: """消息链转换器基类""" @staticmethod def yiri2target(message_chain: platform_message.MessageChain): - """将YiriMirai消息链转换为目标消息链 + """将源平台消息链转换为目标平台消息链 Args: - message_chain (mirai.MessageChain): YiriMirai消息链 + message_chain (platform.types.MessageChain): 源平台消息链 Returns: - typing.Any: 目标消息链 + typing.Any: 目标平台消息链 """ raise NotImplementedError @staticmethod def target2yiri(message_chain: typing.Any) -> platform_message.MessageChain: - """将目标消息链转换为YiriMirai消息链 + """将目标平台消息链转换为源平台消息链 Args: - message_chain (typing.Any): 目标消息链 + message_chain (typing.Any): 目标平台消息链 Returns: - mirai.MessageChain: YiriMirai消息链 + platform.types.MessageChain: 源平台消息链 """ raise NotImplementedError @@ -158,24 +157,24 @@ class EventConverter: @staticmethod def yiri2target(event: typing.Type[platform_message.Event]): - """将YiriMirai事件转换为目标事件 + """将源平台事件转换为目标平台事件 Args: - event (typing.Type[mirai.Event]): YiriMirai事件 + event (typing.Type[platform.types.Event]): 源平台事件 Returns: - typing.Any: 目标事件 + typing.Any: 目标平台事件 """ raise NotImplementedError @staticmethod def target2yiri(event: typing.Any) -> platform_message.Event: - """将目标事件的调用参数转换为YiriMirai的事件参数对象 + """将目标平台事件的调用参数转换为源平台的事件参数对象 Args: - event (typing.Any): 目标事件 + event (typing.Any): 目标平台事件 Returns: - typing.Type[mirai.Event]: YiriMirai事件 + typing.Type[platform.types.Event]: 源平台事件 """ raise NotImplementedError diff --git a/pkg/platform/manager.py b/pkg/platform/manager.py index 4e5131d..d46e5b8 100644 --- a/pkg/platform/manager.py +++ b/pkg/platform/manager.py @@ -6,9 +6,7 @@ import logging import asyncio import traceback -# from mirai import At, GroupMessage, MessageEvent, StrangerMessage, \ # FriendMessage, Image, MessageChain, Plain -# import mirai from ..platform import adapter as msadapter from ..core import app, entities as core_entities diff --git a/pkg/platform/sources/aiocqhttp.py b/pkg/platform/sources/aiocqhttp.py index adf9c4e..25d197e 100644 --- a/pkg/platform/sources/aiocqhttp.py +++ b/pkg/platform/sources/aiocqhttp.py @@ -5,8 +5,6 @@ import traceback import time import datetime -# import mirai -# import mirai.models.message as yiri_message import aiocqhttp from .. import adapter diff --git a/pkg/platform/sources/nakuru.py b/pkg/platform/sources/nakuru.py index 5c05f9d..2fbe8be 100644 --- a/pkg/platform/sources/nakuru.py +++ b/pkg/platform/sources/nakuru.py @@ -6,7 +6,6 @@ import typing import traceback import logging -# import mirai import nakuru import nakuru.entities.components as nkc diff --git a/pkg/platform/sources/qqbotpy.py b/pkg/platform/sources/qqbotpy.py index 5a882c9..cbc86f4 100644 --- a/pkg/platform/sources/qqbotpy.py +++ b/pkg/platform/sources/qqbotpy.py @@ -6,7 +6,6 @@ import datetime import re import traceback -# import mirai import botpy import botpy.message as botpy_message import botpy.types.message as botpy_message_type diff --git a/pkg/platform/sources/yirimirai.py b/pkg/platform/sources/yirimirai.py index 4082e90..aa0823f 100644 --- a/pkg/platform/sources/yirimirai.py +++ b/pkg/platform/sources/yirimirai.py @@ -1,9 +1,6 @@ # import asyncio # import typing -# import mirai -# import mirai.models.bus -# from mirai.bot import MiraiRunner # from .. import adapter as adapter_model # from ...core import app diff --git a/pkg/platform/types/base.py b/pkg/platform/types/base.py index 964e9c6..d3c0be4 100644 --- a/pkg/platform/types/base.py +++ b/pkg/platform/types/base.py @@ -6,7 +6,7 @@ from pydantic import BaseModel class PlatformMetaclass(pdm.ModelMetaclass): - """此类是 YiriMirai 中使用的 pydantic 模型的元类的基类。""" + """此类是平台中使用的 pydantic 模型的元类的基类。""" def to_camel(name: str) -> str: @@ -23,7 +23,7 @@ class PlatformBaseModel(BaseModel, metaclass=PlatformMetaclass): 启用了三项配置: 1. 允许解析时传入额外的值,并将额外值保存在模型中。 2. 允许通过别名访问字段。 - 3. 自动生成小驼峰风格的别名,以符合 mirai-api-http 的命名。 + 3. 自动生成小驼峰风格的别名。 """ def __init__(self, *args, **kwargs): """""" @@ -47,17 +47,17 @@ class PlatformIndexedMetaclass(PlatformMetaclass): def __new__(cls, name, bases, attrs, **kwargs): new_cls = super().__new__(cls, name, bases, attrs, **kwargs) - # 第一类:MiraiIndexedModel + # 第一类:PlatformIndexedModel if name == 'PlatformIndexedModel': cls.__indexedmodel__ = new_cls new_cls.__indexes__ = {} return new_cls - # 第二类:MiraiIndexedModel 的直接子类,这些是可以通过子类名获取子类的类。 + # 第二类:PlatformIndexedModel 的直接子类,这些是可以通过子类名获取子类的类。 if cls.__indexedmodel__ in bases: cls.__indexedbases__.append(new_cls) new_cls.__indexes__ = {} return new_cls - # 第三类:MiraiIndexedModel 的直接子类的子类,这些添加到直接子类的索引中。 + # 第三类:PlatformIndexedModel 的直接子类的子类,这些添加到直接子类的索引中。 for base in cls.__indexedbases__: if issubclass(new_cls, base): base.__indexes__[name] = new_cls @@ -79,7 +79,7 @@ class PlatformIndexedModel(PlatformBaseModel, metaclass=PlatformIndexedMetaclass name: 类名称。 Returns: - Type['MiraiIndexedModel']: 子类类型。 + Type['PlatformIndexedModel']: 子类类型。 """ try: type_ = cls.__indexes__.get(name) @@ -97,7 +97,7 @@ class PlatformIndexedModel(PlatformBaseModel, metaclass=PlatformIndexedMetaclass obj: 一个字典,包含了模型对象的属性。 Returns: - MiraiIndexedModel: 构造的对象。 + PlatformIndexedModel: 构造的对象。 """ if cls in PlatformIndexedModel.__subclasses__(): ModelType = cls.get_subtype(obj['type']) diff --git a/pkg/platform/types/message.py b/pkg/platform/types/message.py index 00e420b..e790f88 100644 --- a/pkg/platform/types/message.py +++ b/pkg/platform/types/message.py @@ -514,9 +514,6 @@ class At(MessageComponent): def __str__(self): return f"@{self.display or self.target}" - def as_mirai_code(self) -> str: - return f"[mirai:at:{self.target}]" - class AtAll(MessageComponent): """At全体。""" @@ -525,9 +522,6 @@ class AtAll(MessageComponent): def __str__(self): return "@全体成员" - def as_mirai_code(self) -> str: - return f"[mirai:atall]" - class Image(MessageComponent): """图片。""" @@ -549,12 +543,9 @@ class Image(MessageComponent): def __str__(self): return '[图片]' - def as_mirai_code(self) -> str: - return f"[mirai:image:{self.image_id}]" - @pydantic.validator('path') def validate_path(cls, path: typing.Union[str, Path, None]): - """修复 path 参数的行为,使之相对于 YiriMirai 的启动路径。""" + """修复 path 参数的行为,使之相对于 QChatGPT 的启动路径。""" if path: try: return str(Path(path).resolve(strict=True)) @@ -682,7 +673,7 @@ class Voice(MessageComponent): """语音的长度,单位为秒。""" @pydantic.validator('path') def validate_path(cls, path: typing.Optional[str]): - """修复 path 参数的行为,使之相对于 YiriMirai 的启动路径。""" + """修复 path 参数的行为,使之相对于 QChatGPT 的启动路径。""" if path: try: return str(Path(path).resolve(strict=True)) diff --git a/pkg/plugin/context.py b/pkg/plugin/context.py index 9e4d8ca..f6cc176 100644 --- a/pkg/plugin/context.py +++ b/pkg/plugin/context.py @@ -3,7 +3,6 @@ from __future__ import annotations import typing import abc import pydantic -# import mirai from . import events from ..provider.tools import entities as tools_entities @@ -179,7 +178,7 @@ class EventContext: """回复此次消息请求 Args: - message_chain (mirai.MessageChain): YiriMirai库的消息链,若用户使用的不是 YiriMirai 适配器,程序也能自动转换为目标消息链 + message_chain (platform.types.MessageChain): 源平台的消息链,若用户使用的不是源平台适配器,程序也能自动转换为目标平台消息链 """ await self.host.ap.platform_mgr.send( event=self.event.query.message_event, @@ -198,7 +197,7 @@ class EventContext: Args: target_type (str): 目标类型,`person`或`group` target_id (str): 目标ID - message (mirai.MessageChain): YiriMirai库的消息链,若用户使用的不是 YiriMirai 适配器,程序也能自动转换为目标消息链 + message (platform.types.MessageChain): 源平台的消息链,若用户使用的不是源平台适配器,程序也能自动转换为目标平台消息链 """ await self.event.query.adapter.send_message( target_type=target_type, diff --git a/pkg/plugin/events.py b/pkg/plugin/events.py index 3fc2ea7..013dd11 100644 --- a/pkg/plugin/events.py +++ b/pkg/plugin/events.py @@ -3,7 +3,6 @@ from __future__ import annotations import typing import pydantic -# import mirai from ..core import entities as core_entities from ..provider import entities as llm_entities diff --git a/pkg/provider/entities.py b/pkg/provider/entities.py index 950cbb1..803613a 100644 --- a/pkg/provider/entities.py +++ b/pkg/provider/entities.py @@ -4,7 +4,6 @@ import typing import enum import pydantic -# import mirai from ..platform.types import message as platform_message @@ -75,14 +74,14 @@ class Message(pydantic.BaseModel): def readable_str(self) -> str: if self.content is not None: - return str(self.role) + ": " + str(self.get_content_mirai_message_chain()) + return str(self.role) + ": " + str(self.get_content_platform_message_chain()) elif self.tool_calls is not None: return f'调用工具: {self.tool_calls[0].id}' else: return '未知消息' - def get_content_mirai_message_chain(self, prefix_text: str="") -> platform_message.MessageChain | None: - """将内容转换为 Mirai MessageChain 对象 + def get_content_platform_message_chain(self, prefix_text: str="") -> platform_message.MessageChain | None: + """将内容转换为平台消息 MessageChain 对象 Args: prefix_text (str): 首个文字组件的前缀文本 @@ -108,7 +107,7 @@ class Message(pydantic.BaseModel): b64_str = b64_str.split(",")[1] mc.append(platform_message.Image(base64=b64_str)) - + # 找第一个文字组件 if prefix_text: for i, c in enumerate(mc): diff --git a/requirements.txt b/requirements.txt index 1b554d2..7bf257e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,6 @@ requests openai>1.0.0 anthropic colorlog~=6.6.0 -yiri-mirai-rc aiocqhttp qq-botpy nakuru-project-idk