Universal Information Model for Nonebot2
Project description
本插件提供了多个模型,可以从不同适配器的 Bot 和 Event 中提取与会话相关的属性
安装
- 使用 nb-cli
nb plugin install nonebot-plugin-uninfo
- 使用 pip
pip install nonebot-plugin-uninfo
使用
获取 Session:
from nonebot_plugin_uninfo import get_session
@matcher.handle()
async def handle(bot: Bot, event: Event):
session = await get_session(bot, event)
或使用依赖注入的形式:
from nonebot_plugin_uninfo import Uninfo, UniSession, Session
@matcher.handle()
async def handle(session: Session = UniSession()):
...
@matcher.handle()
async def handle1(session: Uninfo):
...
拉取用户/群组/频道列表:
from nonebot_plugin_uninfo import get_interface
@matcher.handle()
async def handle(bot: Bot):
interface = await get_interface(bot)
if interface:
users = await interface.get_users()
使用内建的 Permission:
from nonebot import on_command
from nonebot_plugin_uninfo import ADMIN
matcher = on_command("inspect", permission=ADMIN())
模型定义
User
| 属性 | 类型 | 含义 | 备注 |
|---|---|---|---|
id |
str | 用户 id | |
name |
str | None | 用户名称 | |
nick |
str | None | 用户昵称 | 好友备注 |
avatar |
str | None | 用户头像 | |
gender |
str | 用户性别 |
Scene
| 属性 | 类型 | 含义 | 备注 |
|---|---|---|---|
id |
str | 场景 id | |
type |
SceneType | 场景类型 | 可分为 Private, Group, Guild 和 Channel_XXX |
name |
str | None | 场景名称 | |
avatar |
str | None | 场景图标 | |
parent |
Scene | None | 父级场景 | 适用于频道的二级群组场景, 或针对临时会话的来源群组 |
Member
| 属性 | 类型 | 含义 | 备注 |
|---|---|---|---|
user |
User | 成员的用户信息 | |
nick |
str | None | 成员昵称 | |
role |
str | None | 成员角色组 | 当可能存在多个角色组时,此处会使用 level 最高的那个 |
mute |
MuteInfo | None | 成员禁言信息 | |
joined_at |
datetime | None | 成员加入时间 |
Session
| 属性 | 类型 | 含义 | 备注 |
|---|---|---|---|
self_id |
str | 机器人 id | |
adapter |
str | 适配器名称 | |
scope |
str | 适配器范围 | 相比 adapter 更指向实际平台 |
scene |
Scene | 事件场景 | |
user |
User | 用户信息 | |
member |
Member | None | 成员信息 | 仅适用于群组,频道场景 |
operator |
Member | None | 操作者信息 | 仅适用于群组,频道场景 |
示例
from nonebot_plugin_uninfo import Uninfo
from nonebot import on_command
matcher = on_command("inspect", aliases={"查看"}, priority=1)
@matcher.handle()
async def inspect(session: Uninfo):
texts = [
f"平台名: {session.adapter} | {session.scope}",
f"用户ID: {session.user.name + ' | ' if session.user.name else ''}{session.user.id}",
f"自身ID: {session.self_id}",
f"事件场景: {session.scene.type.name}",
f"频道 ID: {session.scene.name + ' | ' if session.scene.name else ''}{session.scene.id}"
]
if session.scene.parent:
texts.append(f"群组 ID: {session.scene.parent.name + ' | ' if session.scene.parent.name else ''}{session.scene.parent.id}")
if session.member:
texts.append(f"成员 ID: {session.member.nick + ' | ' if session.member.nick else ''}{session.member.id}")
await matcher.send("\n".join(texts))
支持的 adapter
- OneBot v11
- OneBot v12
- Console
- Kook (Kaiheila)
- Telegram
- Feishu
- Discord
- Satori
- DoDo
- Kritor
- Mirai
- Tailchat
- WXMP
- heybox
- Gewechat
相关插件
- nonebot-plugin-alconna 强大的 Nonebot2 命令匹配拓展,支持富文本/多媒体解析,跨平台消息收发
鸣谢
- nonebot-plugin-session 与 nonebot-plugin-userinfo 项目的灵感来源以及部分实现的参考
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nonebot_plugin_uninfo-0.7.2.tar.gz.
File metadata
- Download URL: nonebot_plugin_uninfo-0.7.2.tar.gz
- Upload date:
- Size: 38.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: pdm/2.22.4 CPython/3.12.3 Linux/6.8.0-1021-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
623cfbf81806d8b0314be0b731b74fb3f16b414b9febb52c60643f7117c414a8
|
|
| MD5 |
bab83ff7ae42058ab6d925a5ccead40d
|
|
| BLAKE2b-256 |
1804982abc8a56866fd02b8d89b0a11c26308d2157bb6fa7262b14611f989048
|
File details
Details for the file nonebot_plugin_uninfo-0.7.2-py3-none-any.whl.
File metadata
- Download URL: nonebot_plugin_uninfo-0.7.2-py3-none-any.whl
- Upload date:
- Size: 60.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: pdm/2.22.4 CPython/3.12.3 Linux/6.8.0-1021-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0fe133b7a0ab1babe740c8bfe64ad365a60a694f6ef08369f9a79666cd744957
|
|
| MD5 |
d988716bf249dbe178c55d9b1de32923
|
|
| BLAKE2b-256 |
b7ec8ea0d73118edd0c0a759166c43a7dc9905b4e77c6ebf0ad172b45aed5091
|