nonebot-plugin-blockwords


Namenonebot-plugin-blockwords JSON
Version 0.2.1 PyPI version JSON
download
home_page
Summarynonebot聊天屏蔽词插件
upload_time2023-11-17 12:30:41
maintainer
docs_urlNone
authorMelodyKnit
requires_python>=3.8,<4.0
licenseMIT
keywords bot nonebot2 nonebot-plugin blockwords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 聊天屏蔽词插件

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

- [聊天屏蔽词插件](#聊天屏蔽词插件)
  - [如何添加屏蔽词](#如何添加屏蔽词)
  - [机器人发送的消息进行屏蔽词检测](#机器人发送的消息进行屏蔽词检测)
    - [将机器人发送的屏蔽词进行替换](#将机器人发送的屏蔽词进行替换)
  - [接收用户消息屏蔽词检测](#接收用户消息屏蔽词检测)

## 如何添加屏蔽词

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

   ```env
   blockwords=["鸡", "垃圾", "废物"]
   ```

2. 通过导入文件的方式可以配置`env`中的`blockwords_file`

   ```env
   blockwords_file="blockwords.txt"
   ```

3. 多文件导入方式

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

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

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

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

![image-20231003153146954](docs/images/image-20231003153146954.png)

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

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

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

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

![image-20231003154251844](docs/images/image-20231003154251844.png)

## 接收用户消息屏蔽词检测

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

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

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

```python
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](docs/images/image-20231003155210208.png)

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "nonebot-plugin-blockwords",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "bot,nonebot2,nonebot-plugin,blockwords",
    "author": "MelodyKnit",
    "author_email": "2711402357@qq.com",
    "download_url": "https://files.pythonhosted.org/packages/a4/cb/0f5f13cedbfe3db375dc7b49fbfbd7f7062103901c96b4c71790fbc6c555/nonebot_plugin_blockwords-0.2.1.tar.gz",
    "platform": null,
    "description": "# \u804a\u5929\u5c4f\u853d\u8bcd\u63d2\u4ef6\n\n\u804a\u5929\u5c4f\u853d\u8bcd\u63d2\u4ef6\u662f\u6240\u6709`adapter`\u7684\u901a\u7528\u7684\u63d2\u4ef6\uff0c\u53ef\u4ee5\u5bf9\u7528\u6237\u53d1\u9001\u7684\u8bcd\u8fdb\u884c\u68c0\u6d4b\u7136\u540e\u8fdb\u884c\u81ea\u5b9a\u4e49\u64cd\u4f5c\uff0c\u4f8b\u5982\u5c4f\u853d\u8bcd\u4e2d\u52a0\u5165\u4e00\u4e9b\u8fb1\u9a82\u8bcd\u6c47\uff0c\u68c0\u6d4b\u5230\u8fb1\u9a82\u8bcd\u6c47\u65f6\u8fdb\u884c\u64a4\u56de\u6216\u8005\u7981\u8a00\u7b49\u64cd\u4f5c\uff0c\u4e5f\u53ef\u4ee5\u5bf9\u673a\u5668\u4eba\u53d1\u9001\u7684\u8fdb\u884c\u68c0\u6d4b\uff0c\u5982\u679c\u5b58\u5728\u5c4f\u853d\u8bcd\u8fdb\u884c\u62e6\u622a\u53d1\u9001\u6216\u8005\u66ff\u6362\u5c4f\u853d\u8bcd\u3002\n\n- [\u804a\u5929\u5c4f\u853d\u8bcd\u63d2\u4ef6](#\u804a\u5929\u5c4f\u853d\u8bcd\u63d2\u4ef6)\n  - [\u5982\u4f55\u6dfb\u52a0\u5c4f\u853d\u8bcd](#\u5982\u4f55\u6dfb\u52a0\u5c4f\u853d\u8bcd)\n  - [\u673a\u5668\u4eba\u53d1\u9001\u7684\u6d88\u606f\u8fdb\u884c\u5c4f\u853d\u8bcd\u68c0\u6d4b](#\u673a\u5668\u4eba\u53d1\u9001\u7684\u6d88\u606f\u8fdb\u884c\u5c4f\u853d\u8bcd\u68c0\u6d4b)\n    - [\u5c06\u673a\u5668\u4eba\u53d1\u9001\u7684\u5c4f\u853d\u8bcd\u8fdb\u884c\u66ff\u6362](#\u5c06\u673a\u5668\u4eba\u53d1\u9001\u7684\u5c4f\u853d\u8bcd\u8fdb\u884c\u66ff\u6362)\n  - [\u63a5\u6536\u7528\u6237\u6d88\u606f\u5c4f\u853d\u8bcd\u68c0\u6d4b](#\u63a5\u6536\u7528\u6237\u6d88\u606f\u5c4f\u853d\u8bcd\u68c0\u6d4b)\n\n## \u5982\u4f55\u6dfb\u52a0\u5c4f\u853d\u8bcd\n\n1. \u914d\u7f6e`env`\u4e2d\u7684`blockwords`\u914d\u7f6e\u9879\u4f8b\u5982\n\n   ```env\n   blockwords=[\"\u9e21\", \"\u5783\u573e\", \"\u5e9f\u7269\"]\n   ```\n\n2. \u901a\u8fc7\u5bfc\u5165\u6587\u4ef6\u7684\u65b9\u5f0f\u53ef\u4ee5\u914d\u7f6e`env`\u4e2d\u7684`blockwords_file`\n\n   ```env\n   blockwords_file=\"blockwords.txt\"\n   ```\n\n3. \u591a\u6587\u4ef6\u5bfc\u5165\u65b9\u5f0f\n\n   ```env\n   blockwords_file=[\"blockwords1.txt\", \"blockwords2.txt\"]\n   ```\n\n## \u673a\u5668\u4eba\u53d1\u9001\u7684\u6d88\u606f\u8fdb\u884c\u5c4f\u853d\u8bcd\u68c0\u6d4b\n\n\u5728`env`\u4e2d\u914d\u7f6e`blockwords_bot`\u5f00\u542f`bot`\u53d1\u9001\u6d88\u606f\u68c0\u6d4b\n\n```env\nblockwords_bot = True  # \u5f00\u542f\u540e\u673a\u5668\u4eba\u53d1\u9001\u7684\u6d88\u606f\u4f1a\u88ab\u8fdb\u884c\u68c0\u6d4b\n```\n\n![image-20231003153146954](docs/images/image-20231003153146954.png)\n\n> \u4e0a\u8ff0\u4f8b\u5b50\u4e2d\uff0c\u56e0\u4e3a\u68c0\u6d4b\u5230\u673a\u5668\u4eba\u53d1\u9001\u7684\u6d88\u606f\u5b58\u5728\u5c4f\u853d\u8bcd\uff0c\u63d2\u4ef6\u4f1a\u62e6\u622a\u673a\u5668\u4eba\u53d1\u9001\u7684\u6d88\u606f\uff0c\u5982\u679c\u4e0d\u5e0c\u671b\u8fdb\u884c\u62e6\u622a\uff0c\u53ef\u4ee5\u67e5\u770b\u5982\u4f55[\u5c06\u673a\u5668\u4eba\u53d1\u9001\u7684\u5c4f\u853d\u8bcd\u8fdb\u884c\u66ff\u6362](#\u5c06\u673a\u5668\u4eba\u53d1\u9001\u7684\u5c4f\u853d\u8bcd\u8fdb\u884c\u66ff\u6362)\n\n### \u5c06\u673a\u5668\u4eba\u53d1\u9001\u7684\u5c4f\u853d\u8bcd\u8fdb\u884c\u66ff\u6362\n\n\u5728`env`\u4e2d\u914d\u7f6e`blockwords_replace`\u914d\u7f6e\u9879\uff0c\u4ee5\u4e0b\u662f`blockwords_replace`\u914d\u7f6e\u9879\u4f7f\u7528\u4f8b\u5b50\u3002\n\n```env\nBLOCKWORDS_REPLACE=\"*\" # \u5c06\u5c4f\u853d\u8bcd\u66ff\u6362\u4e3a*\n```\n\n![image-20231003154251844](docs/images/image-20231003154251844.png)\n\n## \u63a5\u6536\u7528\u6237\u6d88\u606f\u5c4f\u853d\u8bcd\u68c0\u6d4b\n\n\u5728`env`\u4e2d\u914d\u7f6e`blockwords_user`\u5f00\u542f\u63a5\u6536\u7528\u6237\u6240\u53d1\u9001\u7684\u6d88\u606f\u8fdb\u884c\u68c0\u6d4b\n\n```env\nblockwords_user = True  # \u5f00\u542f\u540e\u673a\u5668\u4eba\u53d1\u9001\u7684\u6d88\u606f\u4f1a\u88ab\u8fdb\u884c\u68c0\u6d4b\n```\n\n\u5728\u68c0\u6d4b\u5230\u5c4f\u853d\u8bcd\u65f6\u4f1a\u89e6\u53d1\u5230`blockwords_matcher`\uff0c\u53ef\u4ee5\u5bfc\u5165`blockwords_matcher`\u5bf9\u89e6\u53d1\u5c4f\u853d\u8bcd\u540e\u8fdb\u884c\u81ea\u5b9a\u4e49\u64cd\u4f5c\n\n```python\nfrom nonebot.internal.matcher import Matcher\nfrom nonebot_plugin_blockwords import blockwords_matcher\n\n@blockwords_matcher.handle()\nasync def _(matcher: Matcher):\n    await matcher.finish(\"\u4e0d\u8bb8\u8bf4\u810f\u8bdd\")\n```\n\n![image-20231003155210208](docs/images/image-20231003155210208.png)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "nonebot\u804a\u5929\u5c4f\u853d\u8bcd\u63d2\u4ef6",
    "version": "0.2.1",
    "project_urls": null,
    "split_keywords": [
        "bot",
        "nonebot2",
        "nonebot-plugin",
        "blockwords"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "daea1e345706d0197e6c800500589debab3f20e76911291e13ac7b20e5a1fa9e",
                "md5": "a71a8fbdd518dee455fd6b40e4baa2bb",
                "sha256": "44c3c07be3c0cfd529ae669a1496b76421582cf7c117632420a47d2944a659be"
            },
            "downloads": -1,
            "filename": "nonebot_plugin_blockwords-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a71a8fbdd518dee455fd6b40e4baa2bb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 10207,
            "upload_time": "2023-11-17T12:30:39",
            "upload_time_iso_8601": "2023-11-17T12:30:39.467239Z",
            "url": "https://files.pythonhosted.org/packages/da/ea/1e345706d0197e6c800500589debab3f20e76911291e13ac7b20e5a1fa9e/nonebot_plugin_blockwords-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a4cb0f5f13cedbfe3db375dc7b49fbfbd7f7062103901c96b4c71790fbc6c555",
                "md5": "933ea200f5f2a393de0971d629624160",
                "sha256": "136bb6f414720a41b64efbb52394b92beb6710910c918371f51854f927247540"
            },
            "downloads": -1,
            "filename": "nonebot_plugin_blockwords-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "933ea200f5f2a393de0971d629624160",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 7232,
            "upload_time": "2023-11-17T12:30:41",
            "upload_time_iso_8601": "2023-11-17T12:30:41.444219Z",
            "url": "https://files.pythonhosted.org/packages/a4/cb/0f5f13cedbfe3db375dc7b49fbfbd7f7062103901c96b4c71790fbc6c555/nonebot_plugin_blockwords-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-17 12:30:41",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "nonebot-plugin-blockwords"
}
        
Elapsed time: 0.30919s