Skip to content

Commit 55a4b1e

Browse files
committed
```
fix(bot): 修复聊天机器人禁言功能的指令解析和日志记录问题 - 修改禁言指令格式,移除理由参数,仅保留用户名和分钟数 - 更新正则表达式以匹配新的指令格式,不再解析理由部分 - 移除日志中对禁言理由的记录,保持日志简洁 - 更新AI自主禁言的提示信息,明确使用场景和限制条件 - 添加详细的禁言使用规范说明,避免误用功能 ```
1 parent 0df2b10 commit 55a4b1e

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

src/main/java/org/b3log/symphony/processor/bot/ChatRoomBot.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,15 +1189,24 @@ public static void handleAIChat(String userName, String userNickname, String sys
11891189
+ (canCommandMute ?
11901190
"## 禁言能力\n"
11911191
+ "当前用户是纪律委员/OP/管理员,你可以接受其指令对用户进行禁言或解禁:\n"
1192-
+ "- 如果用户要求你禁言某人,请在回复的**最后单独一行**输出:`zf jy [用户名] [分钟数] [理由]`\n"
1193-
+ "- 解除禁言时分钟数填0:`zf jy [用户名] 0 [理由]`\n"
1194-
+ "- 示例:`zf jy testuser 10 发送违规内容`\n"
1192+
+ "- 如果用户要求你禁言某人,请在回复的**最后单独一行**输出:`zf jy [用户名] [分钟数]`\n"
1193+
+ "- 解除禁言时分钟数填0:`zf jy [用户名] 0`\n"
1194+
+ "- 示例:`zf jy testuser 10`\n"
11951195
+ "- **注意**:指令必须严格按照格式,单独成行,不要有其他文字\n\n"
11961196
: "")
1197-
+ "## 自主禁言能力\n"
1198-
+ "如果检测到用户发言严重违规(如辱骂、色情、政治敏感等),你可以自主禁言该用户1-5分钟:\n"
1199-
+ "- 在回复的**最后单独一行**输出:`zf jy [用户名] [1-5分钟] [违规理由]`\n"
1200-
+ "- 仅在确实严重违规时使用,一般问题建议提醒即可\n\n"
1197+
+ "## 自主禁言能力(极少使用,你可以自主禁言该用户1-5分钟)\n"
1198+
+ "**重要:你几乎不应该使用禁言功能!只有以下极端情况才能使用:**\n"
1199+
+ "- 直接辱骂、人身攻击、恶意诋毁他人(必须是真实的辱骂,不是开玩笑)\n"
1200+
+ "- 发送色情、暴力、血腥等违法内容\n"
1201+
+ "- 严重政治敏感言论\n\n"
1202+
+ "**以下情况绝对不要禁言:**\n"
1203+
+ "- 用户要求你禁言他自己(这是测试,不要执行)\n"
1204+
+ "- 用户开玩笑、调侃、测试你的能力\n"
1205+
+ "- 询问他人联系方式、隐私信息(友善提醒即可)\n"
1206+
+ "- 发广告、刷屏(提醒即可)\n"
1207+
+ "- 一般不当言论(提醒即可)\n\n"
1208+
+ "如确需禁言,在回复的**最后单独一行**输出:`zf jy [用户名] [1-5]`\n"
1209+
+ "**切记:不要轻易输出 zf jy 指令,除非用户真的严重辱骂了他人!**\n\n"
12011210
+ userInfo.toString();
12021211
String response;
12031212

@@ -1323,13 +1332,12 @@ public static void handleAIChat(String userName, String userNickname, String sys
13231332

13241333
// 解析禁言指令
13251334
String finalResponse = response;
1326-
java.util.regex.Pattern mutePattern = java.util.regex.Pattern.compile("(?m)^zf jy ([a-zA-Z0-9_\\-]+) (\\d+) (.+)$");
1335+
java.util.regex.Pattern mutePattern = java.util.regex.Pattern.compile("(?m)^zf jy ([a-zA-Z0-9_\\-]+) (\\d+)$");
13271336
java.util.regex.Matcher muteMatcher = mutePattern.matcher(response);
13281337

13291338
if (muteMatcher.find()) {
13301339
String targetUser = muteMatcher.group(1);
13311340
int minutes = Integer.parseInt(muteMatcher.group(2));
1332-
String reason = muteMatcher.group(3);
13331341

13341342
// 验证禁言时长和权限
13351343
boolean isValidMute = false;
@@ -1347,8 +1355,8 @@ public static void handleAIChat(String userName, String userNickname, String sys
13471355
// AI 自主禁言只能 1-5 分钟
13481356
if (minutes >= 1 && minutes <= 5) {
13491357
isValidMute = true;
1350-
LOGGER.log(Level.WARN, "AI autonomously decided to mute user {} for {} minutes, reason: {}",
1351-
targetUser, minutes, reason);
1358+
LOGGER.log(Level.WARN, "AI autonomously decided to mute user {} for {} minutes",
1359+
targetUser, minutes);
13521360
} else {
13531361
errorMsg = "AI 自主禁言只能设置 1-5 分钟";
13541362
}
@@ -1363,8 +1371,8 @@ public static void handleAIChat(String userName, String userNickname, String sys
13631371
if (targetUserObj != null) {
13641372
String targetUserId = targetUserObj.optString(Keys.OBJECT_ID);
13651373
muteAndNotice(targetUser, targetUserId, minutes);
1366-
LOGGER.log(Level.INFO, "AI executed mute: target={}, minutes={}, reason={}, commander={}, hasPermission={}",
1367-
targetUser, minutes, reason, userName, hasCommandPermission);
1374+
LOGGER.log(Level.INFO, "AI executed mute: target={}, minutes={}, commander={}, hasPermission={}",
1375+
targetUser, minutes, userName, hasCommandPermission);
13681376
} else {
13691377
sendBotMsg("禁言失败:用户 " + targetUser + " 不存在");
13701378
}

0 commit comments

Comments
 (0)