Skip to main content

聊天屏蔽词插件

聊天屏蔽词插件是所有adapter的通用的插件,可以对用户发送的词进行检测然后进行自定义操作,例如屏蔽词中加入一些辱骂词汇,检测到辱骂词汇时进行撤回或者禁言等操作,也可以对机器人发送的进行检测,如果存在屏蔽词进行拦截发送或者替换屏蔽词。

如何添加屏蔽词

  1. 配置env中的blockwords配置项例如

    blockwords=["鸡", "垃圾", "废物"]
    
  2. 通过导入文件的方式可以配置env中的blockwords_file

    blockwords_file="blockwords.txt"
    
  3. 多文件导入方式

    blockwords_file=["blockwords1.txt", "blockwords2.txt"]
    

机器人发送的消息进行屏蔽词检测

在env中配置blockwords_bot开启bot发送消息检测

blockwords_bot = True  # 开启后机器人发送的消息会被进行检测

image-20231003153146954

上述例子中,因为检测到机器人发送的消息存在屏蔽词,插件会拦截机器人发送的消息,如果不希望进行拦截,可以查看如何将机器人发送的屏蔽词进行替换

将机器人发送的屏蔽词进行替换

在env中配置blockwords_replace配置项,以下是blockwords_replace配置项使用例子。

BLOCKWORDS_REPLACE="*" # 将屏蔽词替换为*

image-20231003154251844

接收用户消息屏蔽词检测

在env中配置blockwords_user开启接收用户所发送的消息进行检测

blockwords_user = True  # 开启后机器人发送的消息会被进行检测

在检测到屏蔽词时会触发到blockwords_matcher,可以导入blockwords_matcher对触发屏蔽词后进行自定义操作

from nonebot.internal.matcher import Matcher
from nonebot_plugin_blockwords import blockwords_matcher

@blockwords_matcher.handle()
async def _(matcher: Matcher):
    await matcher.finish("不许说脏话")

image-20231003155210208

Metadata

Release files for nonebot-plugin-blockwords 0.2.1

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-blockwords 0.2.1
File Size Uploaded
nonebot_plugin_blockwords-0.2.1.tar.gz 7.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nonebot-plugin-blockwords 0.2.1
File Interpreter ABI Platform
nonebot_plugin_blockwords-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.4 kB

Release files / nonebot_plugin_blockwords-0.2.1.tar.gz

Download URL nonebot_plugin_blockwords-0.2.1.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
136bb6f414720a41b64efbb52394b92beb6710910c918371f51854f927247540
BLAKE2b-256 checksum
How to use checksums
a4cb0f5f13cedbfe3db375dc7b49fbfbd7f7062103901c96b4c71790fbc6c555
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.10.13 Windows/10

Release files / nonebot_plugin_blockwords-0.2.1-py3-none-any.whl

Download URL nonebot_plugin_blockwords-0.2.1-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
44c3c07be3c0cfd529ae669a1496b76421582cf7c117632420a47d2944a659be
BLAKE2b-256 checksum
How to use checksums
daea1e345706d0197e6c800500589debab3f20e76911291e13ac7b20e5a1fa9e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.10.13 Windows/10

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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