1
0
forked from bot/app

初步对Uninfo的支持

This commit is contained in:
2024-10-23 01:04:42 +08:00
parent ab89cd1c72
commit 86e50e369b
5 changed files with 151 additions and 399 deletions

View File

@ -9,6 +9,8 @@ from magicoca import Chan, select
from liteyuki.log import logger
from .models import *
def message_handler_thread(i_chans: Iterable[Chan[Any]]):
"""
@ -18,4 +20,4 @@ def message_handler_thread(i_chans: Iterable[Chan[Any]]):
"""
for msg in select(*i_chans):
logger.debug(f"Recv from anybot {msg}")
logger.info(f"Recv from anybot {msg}")
logger.info(f"Recv from anybot {msg}")

View File

@ -1,5 +1,49 @@
"""
本模块使用了[nonebot-plugin-uninfo](https://github.com/RF-Tar-Railt/nonebot-plugin-uninfo)的部分模型定义
MIT License
Copyright (c) 2024 RF-Tar-Railt
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
from datetime import datetime
from enum import Enum
from typing import Any
from pydantic import BaseModel
class SceneType(int, Enum):
PRIVATE = 0
"""私聊场景"""
GROUP = 1
"""群聊场景"""
GUILD = 2
"""频道场景"""
CHANNEL_TEXT = 3
"""子频道文本场景"""
CHANNEL_CATEGORY = 4
"""频道分类场景"""
CHANNEL_VOICE = 5
"""子频道语音场景"""
class User(BaseModel):
"""
用户信息
@ -9,10 +53,13 @@ class User(BaseModel):
nick: 用户昵称
avatar: 用户头像图链接
"""
id: str
name: str | None
nick: str | None
avatar: str | None
name: str | None = None
nick: str | None = None
avatar: str | None = None
gender: str | None = None
class Scene(BaseModel):
"""
@ -24,11 +71,28 @@ class Scene(BaseModel):
avatar: 场景头像图链接
parent: 父场景
"""
id: str
type: str
name: str | None
avatar: str | None
parent: "Scene | None"
type: SceneType
name: str | None = None
avatar: str | None = None
parent: "Scene | None" = None
class Role(BaseModel):
id: str
level: int | None = None
name: str | None = None
class Member(BaseModel):
user: User
nickname: str | None = None
role: Role | None = None
mute: bool | None = None
joined_at: datetime | None = None
class Session(BaseModel):
"""
@ -41,11 +105,43 @@ class Session(BaseModel):
user: 用户信息
member: 成员信息,仅频道及群聊有效
operator: 操作者信息,仅频道及群聊有效
session_id: 会话ID精确到会话用于快速标识会话通常为{适配器范围}:{群聊ID(公共)/用户ID(群聊)}
target_id: 目标ID精确到用户用于快速标识会话通常为{适配器范围}:{群聊ID}:{用户ID}(仅公共) 或 {适配器范围}:{用户ID}(仅私聊)
"""
self_id: str
adapter: str
scope: str
scene: Scene
user: User
member: "Member | None"
operator: "Member | None"
member: "Member | None" = None
operator: "Member | None" = None
@property
def session_id(self):
if self.scope == SceneType.PRIVATE:
return f"{self.scope}:{self.user.id}"
elif self.scope in (
SceneType.GROUP,
SceneType.GUILD,
SceneType.CHANNEL_TEXT,
SceneType.CHANNEL_VOICE,
SceneType.CHANNEL_CATEGORY,
):
return f"{self.scope}:{self.scene.id}"
else:
raise ValueError("Invalid SceneType")
@property
def target_id(self):
if self.scope == SceneType.PRIVATE:
return f"{self.scope}:{self.user.id}"
elif self.scope in (
SceneType.GROUP,
SceneType.GUILD,
SceneType.CHANNEL_TEXT,
SceneType.CHANNEL_VOICE,
SceneType.CHANNEL_CATEGORY,
):
return f"{self.scope}:{self.scene.id}:{self.user.id}"