本插件提供可比较、可序列化的 UserRef 与 SceneRef,用于在 NoneBot 插件中持久化用户和场景身份。
安装
- 使用 nb-cli
nb plugin install nonebot-plugin-uniref
- 使用 pip
pip install nonebot-plugin-uniref
使用
从事件上下文获取和构造 Ref
from nonebot_plugin_alconna import At, UniMsg
from nonebot_plugin_uniref import RefContext
@matcher.handle()
async def handle(message: UniMsg, refs: RefContext):
user = refs.user_ref
scene = refs.scene_ref
user_ids = [at.target for at in message[At] if at.flag == "user"]
users = [refs.build_user_ref(user_id) for user_id in user_ids]
data_scene = refs.parent_scene_ref or scene
编码与恢复 Ref
from nonebot_plugin_uniref import UserRef, decode_ref, encode_ref
ref = UserRef(namespace="QQClient", id="123")
value = encode_ref(ref)
assert value == "user:QQClient:123"
assert decode_ref(value) == ref
构造 Alconna Target
from nonebot_plugin_uniref import decode_ref, ref_to_target
ref = decode_ref("scene:QQClient:group:456")
target = ref_to_target(ref, bot=bot)
模型定义
UserRef
| 属性 | 类型 | 含义 |
|---|---|---|
namespace |
str | 用户 ID 所属的身份命名空间 |
id |
str | 用户 ID |
SceneRef
| 属性 | 类型 | 含义 |
|---|---|---|
namespace |
str | 场景 ID 所属的身份命名空间 |
type |
SceneKind |
UniRef 定义的场景种类 |
id |
str | 场景 ID |
SceneKind 包含 private、group、guild、channel_text、channel_category 和 channel_voice。
支持的 Adapter
{...} 表示决定 ID 有效范围的平台值;id= 后是被引用实体自身的 Ref.id。namespace 表达平台空间、
签发方、ID family,以及无法由其他字段表达的必要局部作用域。
| 已验证 Adapter / 场景 | UserRef:namespace;ID | SceneRef:namespace;type;ID |
|---|---|---|
| OneBot V11、Milky | QQClient;id=QQ 号 |
QQClient;private:QQ 号;group:群号 |
| Telegram | Telegram;id=User ID |
private、group:Telegram;id=Chat ID;channel_text:Telegram:{Chat ID};id=Thread ID |
| Discord | Discord;id=User Snowflake |
Discord;private、guild、Channel;id=Snowflake |
| QQ C2C | QQAPI:{QQ AppID}:c2c;id=user_openid |
QQAPI:{QQ AppID};private;id=user_openid |
| QQ 群聊 | QQAPI:{QQ AppID}:group:{group_openid};id=member_openid |
QQAPI:{QQ AppID};group;id=group_openid |
| QQ 公开文字子频道 | QQAPI:{QQ AppID}:guild:{guild_id};id=频道用户 ID |
QQAPI:{QQ AppID};channel_text;id=channel_id |
| 飞书私聊 | Feishu:{Feishu AppID};id=open_id |
同 namespace;private;id=open_id |
| 飞书群聊 | Feishu:{Feishu AppID};id=open_id |
Feishu;group;id=chat_id |
Metadata
Release files for nonebot-plugin-uniref 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nonebot_plugin_uniref-0.4.1.tar.gz | 14.9 kB | Without provenance | Details for nonebot_plugin_uniref-0.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nonebot_plugin_uniref-0.4.1-py3-none-any.whl | Python 3 | none | any | Details for nonebot_plugin_uniref-0.4.1-py3-none-any.whl |
Total release size: 37.2 kB
Release files / nonebot_plugin_uniref-0.4.1.tar.gz
| Download URL | nonebot_plugin_uniref-0.4.1.tar.gz |
|---|---|
| Size | 14.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
07330455ceb6bdc7b3df5db642db464eaa2bcbc8084602b0370d522fcdc0cdb4
|
|
BLAKE2b-256 checksum How to use checksums |
cd91e210476bd881a9fd221c35f293e63c3aa633cccae176c07fc25112399305
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / nonebot_plugin_uniref-0.4.1-py3-none-any.whl
| Download URL | nonebot_plugin_uniref-0.4.1-py3-none-any.whl |
|---|---|
| Size | 22.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2d23af7e838de1628a494e1774643b96929df188742581c5bf6663bf91ff4262
|
|
BLAKE2b-256 checksum How to use checksums |
c9727f3b712bba0fb996ddaa799ec07f93d283989dfe4db1cafd7ffb2f48b489
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for nonebot-plugin-uniref 0.4.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.