mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-09 15:26:03 +00:00
feat: 删除代码中对 mirai 的引用
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -5,8 +5,6 @@ import traceback
|
||||
import time
|
||||
import datetime
|
||||
|
||||
# import mirai
|
||||
# import mirai.models.message as yiri_message
|
||||
import aiocqhttp
|
||||
|
||||
from .. import adapter
|
||||
|
||||
@@ -6,7 +6,6 @@ import typing
|
||||
import traceback
|
||||
import logging
|
||||
|
||||
# import mirai
|
||||
|
||||
import nakuru
|
||||
import nakuru.entities.components as nkc
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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'])
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user