Skip to main content

nonebot聊天屏蔽词插件

Project description

聊天屏蔽词插件

聊天屏蔽词插件是所有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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nonebot_plugin_blockwords-0.2.1.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

nonebot_plugin_blockwords-0.2.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file nonebot_plugin_blockwords-0.2.1.tar.gz.

File metadata

File hashes

Hashes for nonebot_plugin_blockwords-0.2.1.tar.gz
Algorithm Hash digest
SHA256 136bb6f414720a41b64efbb52394b92beb6710910c918371f51854f927247540
MD5 933ea200f5f2a393de0971d629624160
BLAKE2b-256 a4cb0f5f13cedbfe3db375dc7b49fbfbd7f7062103901c96b4c71790fbc6c555

See more details on using hashes here.

File details

Details for the file nonebot_plugin_blockwords-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for nonebot_plugin_blockwords-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 44c3c07be3c0cfd529ae669a1496b76421582cf7c117632420a47d2944a659be
MD5 a71a8fbdd518dee455fd6b40e4baa2bb
BLAKE2b-256 daea1e345706d0197e6c800500589debab3f20e76911291e13ac7b20e5a1fa9e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page