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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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