Skip to main content

nonebot-plugin-keyword-memes

关键词梗图:群聊里整句说出触发词,就随机发一张对应的表情包。

功能

  • 关键词触发:整句等于触发词就发图;可切换为「包含即触发」
  • 别名:一个规则可以有多个写法,例如「男的来了」和「男德」共用同一批图
  • 内容去重:图片按内容哈希命名,重复上传自动跳过
  • 安全删除:同一张图挂在多个触发词下时,删一个不会把文件删没
  • 上传/删除权限可控:默认仅超级用户,可配置为所有人
  • 按群开关:规则可绑定宿主自己的群功能开关(通过 register_switch_checker 接入)
  • 大小保护:上传和发送都有体积上限,避免大图把消息卡死
  • 纯本地存储:规则是 JSON,图片放在插件数据目录,备份就是复制一个文件夹

安装

nb plugin install nonebot-plugin-keyword-memes
# 或
pip install nonebot-plugin-keyword-memes

需要 nonebot-plugin-localstore(本插件已声明依赖)。

使用

群里直接说出触发词即可,例如:

群友:男的来了
机器人:[表情包]

管理命令(默认命令名 梗,可配置):

命令 说明 权限
/梗 查看用法 所有人
/梗 列表 列出全部触发词、图片数量与别名 所有人
/梗 查看 <触发词> 逐张预览,带序号 所有人
/梗 添加 <触发词> 附一张图,或回复一条带图消息 默认超级用户
/梗 删除 <触发词> [序号] 删单张;不带序号删整组 默认超级用户
/梗 别名 <触发词> <别名> 加别名,两个写法共用同一批图(触发词不能含空格) 默认超级用户
/梗 去别名 <触发词> <别名> 取消别名,图片保留 默认超级用户

配置

在 .env 中配置(前缀 KEYWORD_MEMES_):

配置项 默认值 说明
KEYWORD_MEMES_COMMAND 梗 管理命令名
KEYWORD_MEMES_ALIASES ["梗图"] 管理命令别名
KEYWORD_MEMES_MATCH exact exact 整句相等;contains 包含即触发
KEYWORD_MEMES_COOLDOWN 0 同一人同一群的触发冷却(秒)
KEYWORD_MEMES_UPLOAD superuser superuser 仅超级用户;everyone 所有人
KEYWORD_MEMES_MAX_UPLOAD_BYTES 8000000 单张上传大小上限
KEYWORD_MEMES_MAX_SEND_BYTES 2500000 单张发送大小上限
KEYWORD_MEMES_PRIORITY 9 触发响应器优先级
KEYWORD_MEMES_BLOCK false 命中后是否阻止后续响应器
KEYWORD_MEMES_DATA_DIR 空 自定义数据目录

接入按群开关

插件本身不假设任何开关系统。规则里的 switch 字段会交给宿主注册的判定函数:

from nonebot_plugin_keyword_memes import register_switch_checker


@register_switch_checker
async def check_switch(group_id: int | None, switch: str) -> bool:
    # 返回 False 表示本群关闭了这条规则;没有注册判定函数时一律视为开启
    return my_feature_registry.is_enabled(group_id, switch)

数据文件

<插件数据目录>/
├── rules.json          # 规则:触发词/别名 → 图片文件名
└── images/
    ├── 1a2b3c4d5e6f7788.gif
    └── ...

rules.json 示例:

{
  "version": 1,
  "rules": [
    {
      "id": "r-1a2b3c4d",
      "triggers": ["男的来了", "男德"],
      "images": ["1a2b3c4d5e6f7788.gif"],
      "switch": "",
      "cooldown": 0,
      "enabled": true
    }
  ]
}

开发

python -m venv .venv
.venv/bin/pip install -e . pytest
.venv/bin/pytest

许可

MIT

Metadata

Release files for nonebot-plugin-keyword-memes 0.1.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-keyword-memes 0.1.0
File Size Uploaded Provenance Actions
nonebot_plugin_keyword_memes-0.1.0.tar.gz 16.2 kB Without provenance Details for nonebot_plugin_keyword_memes-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nonebot-plugin-keyword-memes 0.1.0
File Interpreter ABI Platform Actions
nonebot_plugin_keyword_memes-0.1.0-py3-none-any.whl Python 3 none any Details for nonebot_plugin_keyword_memes-0.1.0-py3-none-any.whl

Total release size: 33.7 kB

Release files / nonebot_plugin_keyword_memes-0.1.0.tar.gz

Download URL nonebot_plugin_keyword_memes-0.1.0.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
18a18b18d718832493d2347792d1d25001651473d142a2d159d2464676c7b18c
BLAKE2b-256 checksum
How to use checksums
7bc8814f5dbf2fff721f762e5c262f599675c1123f35f66acd132e8566f316a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Release files / nonebot_plugin_keyword_memes-0.1.0-py3-none-any.whl

Download URL nonebot_plugin_keyword_memes-0.1.0-py3-none-any.whl
Size 17.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8c5d5f343f51da43bd9eb2caf332f82f45ce400f767910a7f90c3c476826e83e
BLAKE2b-256 checksum
How to use checksums
7a337d7feec9a633999e63d6fa42664d0e986ff226b53274a69ebd843edcae11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Security for nonebot-plugin-keyword-memes 0.1.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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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