Skip to content

Commit

Permalink
release v0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
iyume committed Dec 3, 2023
1 parent 8986115 commit 1de559a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,15 @@ pip install nonebot-plugin-nsfw[nsfw-model]
## 插件配置项

| | 默认值 | 可选值 | 说明 |
| --------------- | --------------------------------- | ------------------------------ | ------------------------------------- |
| model | "safety_checker" | "safety_checker", "nsfw_model" | |
| device | "cpu" | "cpu", "cuda", etc. | |
| withdraw | True | True, False | 撤回检测到 NSFW 图片的消息 |
| nsfw_model_path | cwd() / nsfw_mobilenet2_v1.2.0.h5 | .h5 or SavedModel path | nsfw-model 模型路径,没配置则自动下载 |
| | 默认值 | 可选值 | 说明 |
| ------------------------ | --------------------------------- | ------------------------------ | -------------------------------------------------- |
| nsfw\_\_model | "safety_checker" | "safety_checker", "nsfw_model" | |
| nsfw\_\_device | "cpu" | "cpu", "cuda", etc. | |
| nsfw\_\_withdraw | True | True, False | 撤回检测到 NSFW 图片的消息 |
| nsfw\_\_nsfw_model_path | cwd() / nsfw_mobilenet2_v1.2.0.h5 | .h5 or SavedModel path | nsfw-model 模型路径,没配置则自动下载 |
| nsfw\_\_warning_capacity | 3 | 正整数 | 一天内警告 N 次后禁言,0 不警告,ban=True 直接禁言 |
| nsfw\_\_ban | True | True, False | 是否启用禁言 |
| nsfw\_\_ban_time | 1800 | 正整数 | 禁言时长,单位为秒数 |

更多配置正在开发中...

Expand Down
7 changes: 6 additions & 1 deletion nonebot_plugin_nsfw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@ async def _(
await bot.delete_msg(message_id=event.message_id)
if config.warning_capacity != 0:
user.warning_count += 1
await bot.send(event, f"不许色色,警告 {user.warning_count} 次!", at_sender=True)
if config.ban == True and user.warning_count > config.warning_capacity:
await bot.set_group_ban(
group_id=event.group_id, user_id=event.user_id, duration=config.ban_time
)
else:
await bot.send(event, f"涩涩哒咩,警告 {user.warning_count} 次!", at_sender=True)
20 changes: 14 additions & 6 deletions nonebot_plugin_nsfw/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

import nonebot
from nonebot import logger
from pydantic import BaseModel, NonNegativeInt
from pydantic import BaseModel, NonNegativeInt, PositiveInt

DEFAULT_NSFW_MODEL_PATH = str(Path.cwd() / "nsfw_mobilenet2_v1.2.0.h5")
DEFAULT_NSFW_MODEL_URI = "https://github.com/iyume/nonebot-plugin-nsfw/releases/download/v0.1/nsfw_mobilenet2_v1.2.0.h5"

T_AVAILABLE_MODEL = Literal["safety_checker", "nsfw_model"]


class Config(BaseModel):
class PluginScopedConfig(BaseModel):
model: T_AVAILABLE_MODEL = "nsfw_model"
"""要使用的模型。默认为 NSFW Model。"""

Expand All @@ -25,13 +25,21 @@ class Config(BaseModel):
默认值: `cwd()/nsfw_mobilenet2_v1.2.0.h5`
"""

warning_capacity: NonNegativeInt = 5
"""一天内警告 N 次后禁言,0 表示不警告,ban=True 则直接禁言。默认为 5."""
warning_capacity: NonNegativeInt = 3
"""一天内警告 N 次后禁言,0 表示不警告,ban=True 则直接禁言。默认为 3."""

ban: bool = False
ban: bool = True
"""是否禁言。默认为 True。"""

ban_time: PositiveInt = 30 * 60 # maybe list of increasing time
"""禁言时长秒数。默认为 1800。"""

config = Config.parse_obj(nonebot.get_driver().config)

class PluginConfig(BaseModel):
nsfw: PluginScopedConfig


config = PluginConfig.parse_obj(nonebot.get_driver().config).nsfw

if config.nsfw_model_path is not None and config.model != "nsfw_model":
logger.warning("Provided nsfw_model_path without using its model")
4 changes: 0 additions & 4 deletions nonebot_plugin_nsfw/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ def refresh(self) -> None:
self.date_ = today
self.warning_count = 0

@property
def should_ban(self) -> bool:
return self.warning_count > config.warning_capacity


# simple database
users: Dict[str, User] = {}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "nonebot-plugin-nsfw"
version = "0.1.0"
version = "0.2"
description = "群聊 NSFW 图片检测插件,带有撤回、禁言等功能。使用 Safety Checker / NSFW Model。"
authors = [{ name = "iyume", email = "iyumelive@gmail.com" }]
requires-python = ">=3.8"
Expand Down

0 comments on commit 1de559a

Please sign in to comment.