Skip to main content

nonebot-plugin-mixin

✨ 通过代码或非代码方式外部介入 NoneBot2 插件行为 ✨

license pypi python

📖 介绍

本插件允许通过代码/非代码方式介入插件内部 Matcher 的行为。

💿 安装

通过 nb-cli:

nb plugin install nonebot-plugin-mixin

⚙️ 配置

本插件增加了下列可选配置项,有需要的用户请自行在 .env 中配置:

# 下列配置项请按需解除注释并配置

# Mixin 数据文件路径(可选),支持 json 格式。
# mixin_source=["hello_mixin.json", "justsix_mixin.json"]

使用

加载静态数据

本插件目前支持加载 json 数据。

要加载静态的 Mixin 数据,需要将数据文件路径加入配置文件中的 mixin_source 中,然后启动项目即可。数据格式参阅下面的数据结构。

[
    {
        "source": {
            "module_name": "nonebot_plugin_helloworld"
        },
        "dest": {
            "rule": {
                "fullmatch": {
                    "msg": ["fxxk", "fxxkyou", "caonima"]
                }
            },
            "priority": 42
        }
    }
]

从代码加载

from nonebot import require

mixin = require("nonebot_plugin_mixin")

my_mixins = []
my_mixins.append(
    mixin.Mixin(
        source=mixin.MixinQuery(
            module_name="nonebot_plugin_helloworld"
        ),
        dest=mixin.MixinData(
            rule=mixin.MixinRule(
                fullmatch=mixin.CaseMatch(msg=("fxxk", "fxxkyou", "caonima"))
            ),
            priority=42
        )
    )
)

mixin.multi_mixin(my_mixins)

数据结构

下面是一个 Mixin 对象的整体结构:

注:可选参数的类型前面会加星号 *。

mixin: Mixin
    source: MixinQuery  # 此段参数只用于查询要修改的 Matcher
        plugin_name: *str
        module_name: *str
        type: *str
        rule: *MixinRule
            startswith: *CaseMatch
                msg: Tuple[str, ...]
                ignorecase: bool = False
            endswith: *CaseMatch
                msg: Tuple[str, ...]
                ignorecase: bool = False
            fullmatch: *CaseMatch
                msg: Tuple[str, ...]
                ignorecase: bool = False
            keywords: *Tuple[str, ...]
                "keyword1"
                ...
            command: *Tuple[Tuple[str, ...]]
                ("command1",)
                ("command2", "sub")
                ...
            regex: *ReMatch
                regex: str
                flags: int = 0
            to_me: bool = False
        priority: *int
        block: *bool
    dest: MixinData  # 此段参数只用于选择性修改 Matcher 的属性
        type: *str
        rule: *MixinRule
            startswith: *CaseMatch
                msg: Tuple[str, ...]
                ignorecase: bool = False
            endswith: *CaseMatch
                msg: Tuple[str, ...]
                ignorecase: bool = False
            fullmatch: *CaseMatch
                msg: Tuple[str, ...]
                ignorecase: bool = False
            keywords: *Tuple[str, ...]
                "keyword1"
                ...
            command: *Tuple[Tuple[str, ...]]
                ("command1",)
                ("command2", "sub")
                ...
            regex: *ReMatch
                regex: str
                flags: int = 0
            to_me: bool = False
        rule_override: bool = False  # 为 True 时完全覆盖 rule 数据 (v0.1.1 新增)
        priority: *int
        block: *bool

而读取静态文件时,本插件默认会从某个文件中读取单个或多个并列的 Mixin 规则,因此数据文件的最上级必须是一个序列。例如:

[
    {
        "source": ...,
        "dest": ...
    },
    ...
]

覆盖规则

可选参数只有给定具体有效值的属性会被完全覆盖,未给定具体有效值的属性默认保留。

Metadata

Release files for nonebot-plugin-mixin 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nonebot-plugin-mixin 0.2.0
File Size Uploaded Provenance Actions
nonebot_plugin_mixin-0.2.0.tar.gz 6.2 kB Without provenance Details for nonebot_plugin_mixin-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nonebot-plugin-mixin 0.2.0
File Interpreter ABI Platform Actions
nonebot_plugin_mixin-0.2.0-py3-none-any.whl Python 3 none any Details for nonebot_plugin_mixin-0.2.0-py3-none-any.whl

Total release size: 13.2 kB

Release files / nonebot_plugin_mixin-0.2.0.tar.gz

Download URL nonebot_plugin_mixin-0.2.0.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e2d350e32c89b8107a5fbaaa98379d34104c95a14e1d1c6722b1b2b913e257e2
BLAKE2b-256 checksum
How to use checksums
15a82b633e0f474b0f3cafae12d5c4220859407330e874ea46701ddb7caf37a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.19

Release files / nonebot_plugin_mixin-0.2.0-py3-none-any.whl

Download URL nonebot_plugin_mixin-0.2.0-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
18bde942d2f8725ae2bbf6b7bae2fe55d4ad5159fb83e1a96d2d917bc28142d2
BLAKE2b-256 checksum
How to use checksums
a97003fb414a47185bd87f08c3a79933c299ec726de7c4c55da30040453fe1ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.19

Security for nonebot-plugin-mixin 0.2.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page