feat: 删除代码中对 mirai 的引用

This commit is contained in:
RockChinQ 2024-09-26 13:01:45 +08:00
parent e8da26cb8a
commit 3469515e04
No known key found for this signature in database
GPG Key ID: 8AC0BEFE1743A015
38 changed files with 42 additions and 103 deletions

View File

@ -8,10 +8,10 @@ body:
label: 消息平台适配器
description: "连接QQ使用的框架"
options:
- yiri-miraiMirai
- Nakurugo-cqhttp
- aiocqhttp使用 OneBot 协议接入的)
- qq-botpyQQ官方API
- yiri-miraiMirai
validations:
required: false
- type: input

View File

@ -10,5 +10,4 @@ updates:
schedule:
interval: "weekly"
allow:
- dependency-name: "yiri-mirai-rc"
- dependency-name: "openai"

View File

@ -6,8 +6,11 @@
### PR 作者完成
*请在方括号间写`x`以打勾
- [ ] 阅读仓库[贡献指引](https://github.com/RockChinQ/QChatGPT/blob/master/CONTRIBUTING.md)了吗?
- [ ] 与项目所有者沟通过了吗?
- [ ] 我确定已自行测试所作的更改,确保功能符合预期。
### 项目所有者完成

View File

@ -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

View File

@ -5,7 +5,6 @@ required_deps = {
"openai": "openai",
"anthropic": "anthropic",
"colorlog": "colorlog",
"mirai": "yiri-mirai-rc",
"aiocqhttp": "aiocqhttp",
"botpy": "qq-botpy",
"PIL": "pillow",

View File

@ -6,7 +6,6 @@ import datetime
import asyncio
import pydantic
# import mirai
from ..provider import entities as llm_entities
from ..provider.modelmgr import entities

View File

@ -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

View File

@ -4,7 +4,6 @@ import asyncio
import typing
import traceback
# import mirai
from ..core import app, entities
from . import entities as pipeline_entities

View File

@ -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] = ''
"""只要设置了就会输出到控制台"""

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -2,7 +2,6 @@ from __future__ import annotations
import asyncio
# import mirai
from ..core import entities
from ..platform import adapter as msadapter

View File

@ -1,6 +1,5 @@
from __future__ import annotations
# import mirai
from .. import stage, entities, stagemgr
from ...core import entities as core_entities

View File

@ -5,7 +5,6 @@ import time
import traceback
import json
# import mirai
from .. import handler
from ... import entities

View File

@ -1,7 +1,6 @@
from __future__ import annotations
import typing
# import mirai
from .. import handler
from ... import entities

View File

@ -3,7 +3,6 @@ from __future__ import annotations
import random
import asyncio
# import mirai
from ...core import app

View File

@ -1,5 +1,4 @@
import pydantic
# import mirai
from ...platform.types import message as platform_message

View File

@ -1,6 +1,5 @@
from __future__ import annotations
# import mirai
from ...core import app
from . import entities as rule_entities, rule

View File

@ -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

View File

@ -1,6 +1,5 @@
from __future__ import annotations
# import mirai
from .. import rule as rule_model
from .. import entities

View File

@ -1,4 +1,3 @@
# import mirai
from .. import rule as rule_model
from .. import entities

View File

@ -1,6 +1,5 @@
import random
# import mirai
from .. import rule as rule_model
from .. import entities

View File

@ -1,6 +1,5 @@
import re
# import mirai
from .. import rule as rule_model
from .. import entities

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -5,8 +5,6 @@ import traceback
import time
import datetime
# import mirai
# import mirai.models.message as yiri_message
import aiocqhttp
from .. import adapter

View File

@ -6,7 +6,6 @@ import typing
import traceback
import logging
# import mirai
import nakuru
import nakuru.entities.components as nkc

View File

@ -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

View File

@ -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

View File

@ -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'])

View File

@ -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))

View File

@ -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,

View File

@ -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

View File

@ -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):

View File

@ -2,7 +2,6 @@ requests
openai>1.0.0
anthropic
colorlog~=6.6.0
yiri-mirai-rc
aiocqhttp
qq-botpy
nakuru-project-idk