Chat Moderator – 基于 AI 辅助聊天的 Paper 1.21 审核插件
ChatModer 是一款轻量级、免费且基于 AI 辅助的聊天审核插件,适用于 Paper 1.21 Minecraft 服务器。ChatModer 将快速的正则表达式/语言过滤与可选的离线 ONNX 分类器相结合,能够准确审核有毒、仇恨、色情和骚扰信息,而无需使用付费 API。
功能特性
- 混合审核:正则表达式 + 可选的 RoBERTa ONNX AI
- 身份感知的仇恨检测(无需 API 密钥)
- 语言检测与拦截
- 可调节的阈值、惩罚措施和严格模式
- 用于审查、训练和状态查看的管理员工具
- 持久化统计信息与自动保存(SQLite/MySQL)及自动迁移
- 文件/数据库日志记录与审查工具
- 性能优化,支持异步分类与缓存
- 完全离线工作(无需付费 API)
- 高度可配置且可扩展
安装
- 将
ChatModer.jar 放入服务器的 plugins/ 目录中
- 重启服务器以生成
plugins/ChatModer/config.yml
- (可选)在
plugins/ChatModer/models/ 下添加 ONNX 模型文件夹,并在配置文件中指向该 ONNX 文件
AI 模型设置 (Hugging Face RoBERTa)
ChatModer 支持 Hugging Face RoBERTa ONNX 模型,例如 protectai/unbiased-toxic-roberta-onnx。
创建如下文件夹:
plugins/ChatModer/models/unbiased-toxic-roberta-onnx/
在其中放入以下文件:
model_quantized.onnx(推荐)或 model.onnx
config.json(包含 id2label/label2id)
tokenizer.json(首选),或 vocab.json + merges.txt
- 可选:
tokenizer_config.json、special_tokens_map.json
配置片段:
moderation:
ai:
enabled: true
model_path: plugins/ChatModer/models/unbiased-toxic-roberta-onnx/model_quantized.onnx
max_sequence_length: 128
async_threads: 2
timeout_ms: 500
分词器和配置文件将从与 ONNX 相同的文件夹中自动加载。
标签映射
obscene -> profanity(脏话)
insult/threat -> harassment(骚扰)
sexual_explicit -> sexual(色情)
identity_attack -> hate(仇恨)
toxicity/severe_toxicity 会略微提升对脏话/骚扰的判定权重
- 纯身份标签(如
black、muslim)本身不会被标记;它们仅在结合侮辱/毒性内容时作为上下文参考
模式
- regex:仅使用正则表达式/词库启发式规则
- ai-only:仅使用 ONNX 模型(如果已启用);仍会使用语言拦截和白名单
- hybrid(推荐):结合正则表达式与 AI;AI 评分可通过
moderation.ai.weight 进行加权
moderation:
enabled: true
mode: hybrid # regex | ai-only | hybrid
ai:
enabled: true
weight: 0.8
数据库与自动保存
统计数据默认持久化到 SQLite,如果配置了 MySQL 则保存到 MySQL。插件可以将现有的 SQLite 统计数据自动迁移到 MySQL。
database:
type: sqlite
sqlite_file: plugins/ChatModer/data.db
mysql:
host: 127.0.0.1
port: 3306
database: chatmoder
user: root
password: "secret"
useSSL: false
sqlite_migrate_file: plugins/ChatModer/data.db
stats:
autosave_seconds: 300
阈值与惩罚
针对每个类别微调审核敏感度和操作措施。
thresholds:
profanity: 0.7
harassment: 0.6
hate: 0.6
sexual: 0.7
spam: 0.8
punishments:
profanity: block # warn | tempmute | kick | tempban | block | command:<cmd>
harassment: warn
hate: tempmute
sexual: block
spam: block
日志与审查
- 文件日志:JSONL 格式写入
plugins/ChatModer/logs/flags.log
- 数据库日志:SQLite/MySQL
flags 表(可选)
- 审查:
/chatmod review <player> 如果启用了数据库则从 DB 读取,否则从文件日志读取。支持旧版的美化打印日志和紧凑 JSONL 格式。
命令
/chatmod toggle — 启用/禁用审核。
/chatmod status — 实时统计概览。
/chatmod review <player> — 审查最近被标记的消息。
/chatmod whitelist add|remove <word> — 管理白名单。
/chatmod strict reload — 重新加载严格列表。
/chatmod train add|capture|fromlog|words|stats|export — 数据集工具。
/chatmod stats reset confirm — 清除内存中的统计数据并立即持久化。
训练工作流(可选)
- Capture:记录最近的消息作为训练的上下文
- From log:挖掘被标记的日志以构建数据集
- Words:词频分析
- Stats:训练数据集统计
- Export:输出
dataset.jsonl 以便进行微调
所有工具均可通过 /chatmod train ... 使用。
严格模式
对于即时拦截的情况(例如高严重性令牌),启用严格规则并通过命令重新加载而无需重启服务器:
/chatmod strict reload
权限
chatmod.admin — 访问管理员命令
chatmod.bypass — 绕过审核
chatmod.review — 访问审查工具
性能
- 仅正则表达式模式以实现最小开销
- AI 异步运行并使用 CPU 上的量化 ONNX 模型
- 使用令牌和消息缓存以减少重复工作
隐私
所有处理均在本地完成。除非启用 Webhooks,否则不会进行外部 API 调用。
兼容性
- Paper 1.21(大多数现代分支版本应能正常工作)
- Java 17+
- 内置 SQLite;MySQL 需要有效的凭据
故障排除
- ONNX 模型未加载:检查
moderation.ai.model_path 并确保 config.json 和 tokenizer.json(或 vocab.json + merges.txt)位于同一目录下。
- 分类超时:增加
moderation.ai.timeout_ms 或减少 max_sequence_length。
- CPU 占用过高:使用
model_quantized.onnx 并将 max_sequence_length 保持在 128/256。
- 审查无条目显示:确保已启用日志记录(文件或数据库)且日志不为空。
支持
请在项目仓库中提交 Issue,附上日志、配置和复现步骤。如果您使用了自定义模型,请提供模型详情。
Chat Moderator – AI-Assisted Chat Moderation for Paper 1.21
A lightweight, free, AI-assisted chat moderation plugin for Paper 1.21 Minecraft servers. ChatMod combines fast regex/language filtering with an optional offline ONNX-based classifier to accurately moderate toxic, hateful, sexual, and harassing messages without paid APIs.
Features
- Hybrid moderation: regex + optional RoBERTa ONNX AI
- Identity-aware hate detection (no API keys required)
- Language detection and blocking
- Tunable thresholds, punishments, and strict mode
- Admin tools for review, training, and status
- Persistent stats with autosave (SQLite/MySQL) and auto-migration
- File/DB logging and review tools
- Performance-optimized with async classification and caching
- Works fully offline (no paid APIs)
- Highly configurable and extensible
Installation
- Drop
ChatModer.jar into your server plugins/ directory
- Restart the server to generate
plugins/ChatModer/config.yml
- (Optional) Add an ONNX model folder under
plugins/ChatModer/models/ and point the config to the ONNX file
AI Model Setup (Hugging Face RoBERTa)
ChatModer supports Hugging Face RoBERTa ONNX models, e.g. protectai/unbiased-toxic-roberta-onnx.
Create a folder like:
plugins/ChatModer/models/unbiased-toxic-roberta-onnx/
Put these files inside:
model_quantized.onnx (recommended) or model.onnx
config.json (contains id2label/label2id)
tokenizer.json (preferred), or vocab.json + merges.txt
- Optional:
tokenizer_config.json, special_tokens_map.json
Config snippet:
moderation:
ai:
enabled: true
model_path: plugins/ChatModer/models/unbiased-toxic-roberta-onnx/model_quantized.onnx
max_sequence_length: 128
async_threads: 2
timeout_ms: 500
The tokenizer/config are auto-loaded from the same folder as the ONNX.
Label Mapping
obscene -> profanity
insult/threat -> harassment
sexual_explicit -> sexual
identity_attack -> hate
toxicity/severe_toxicity boost profanity/harassment slightly
- Identity-only labels (e.g.,
black, muslim) are not flagged by themselves; they serve as context when combined with insult/toxicity
Modes
- regex: Only regex/wordlist heuristics
- ai-only: Only ONNX model (if enabled); still uses language blocking and whitelist
- hybrid (recommended): Combine regex + AI; AI score can be weighted via
moderation.ai.weight
moderation:
enabled: true
mode: hybrid # regex | ai-only | hybrid
ai:
enabled: true
weight: 0.8
Database & Autosave
Stats are persisted to SQLite by default or MySQL if configured. The plugin can auto-migrate existing SQLite stats to MySQL.
database:
type: sqlite
sqlite_file: plugins/ChatModer/data.db
mysql:
host: 127.0.0.1
port: 3306
database: chatmoder
user: root
password: "secret"
useSSL: false
sqlite_migrate_file: plugins/ChatModer/data.db
stats:
autosave_seconds: 300
Thresholds & Punishments
Fine-tune moderation sensitivity and actions per category.
thresholds:
profanity: 0.7
harassment: 0.6
hate: 0.6
sexual: 0.7
spam: 0.8
punishments:
profanity: block # warn | tempmute | kick | tempban | block | command:<cmd>
harassment: warn
hate: tempmute
sexual: block
spam: block
Logging & Review
- File logs: JSONL written to
plugins/ChatModer/logs/flags.log
- DB logs: SQLite/MySQL
flags table (optional)
- Review:
/chatmod review <player> reads from DB if enabled, else file logs. Supports legacy pretty-printed logs and compact JSONL.
Commands
/chatmod toggle — Enable/disable moderation.
/chatmod status — Live stats overview.
/chatmod review <player> — Review recent flagged messages.
/chatmod whitelist add|remove <word> — Manage whitelist.
/chatmod strict reload — Reload strict list.
/chatmod train add|capture|fromlog|words|stats|export — Dataset tools.
/chatmod stats reset confirm — Clear in-memory stats and persist immediately.
Training Workflow (Optional)
- Capture: record recent messages as context for training
- From log: mine flagged logs into a dataset
- Words: word frequency analysis
- Stats: training dataset stats
- Export: outputs
dataset.jsonl ready for fine-tuning
All tools are available under /chatmod train ....
Strict Mode
For immediate blocks (e.g., high-severity tokens), enable strict rules and reload them without a restart:
/chatmod strict reload
Permissions
chatmod.admin — Access to admin commands
chatmod.bypass — Bypass moderation
chatmod.review — Access review tools
Performance
- Regex-only mode for minimal overhead
- AI runs asynchronously and uses a quantized ONNX model on CPU
- Token and message caching to reduce repeated work
Privacy
All processing is local. No external API calls are made unless you enable webhooks.
Compatibility
- Paper 1.21 (most modern forks should work)
- Java 17+
- SQLite included; MySQL requires valid credentials
Troubleshooting
- ONNX model not loading: Check
moderation.ai.model_path and ensure config.json and tokenizer.json (or vocab.json + merges.txt) are in the same directory.
- Classification timeout: Increase
moderation.ai.timeout_ms or reduce max_sequence_length.
- High CPU: Use
model_quantized.onnx and keep max_sequence_length at 128/256.
- Review shows no entries: Ensure logging is enabled (file or DB) and that your logs aren’t empty.
Support
Open an issue on the project repository with logs, configs, and steps to reproduce. Provide model details if you use a custom model.
评论 0
登录后参与评分
还没有评论,来抢沙发吧