mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-14 06:03:42 +08:00
敏感词工具类封装
This commit is contained in:
@@ -10,8 +10,8 @@ import com.abin.mallchat.common.chat.domain.enums.MessageTypeEnum;
|
||||
import com.abin.mallchat.common.chat.service.cache.MsgCache;
|
||||
import com.abin.mallchat.common.common.domain.enums.YesOrNoEnum;
|
||||
import com.abin.mallchat.common.common.utils.AssertUtil;
|
||||
import com.abin.mallchat.common.common.utils.SensitiveWordUtils;
|
||||
import com.abin.mallchat.common.common.utils.discover.PrioritizedUrlTitleDiscover;
|
||||
import com.abin.mallchat.common.common.utils.sensitiveWord.SensitiveWordBs;
|
||||
import com.abin.mallchat.common.user.domain.entity.User;
|
||||
import com.abin.mallchat.common.user.domain.enums.RoleEnum;
|
||||
import com.abin.mallchat.common.user.service.IRoleService;
|
||||
@@ -46,6 +46,8 @@ public class TextMsgHandler extends AbstractMsgHandler {
|
||||
private UserInfoCache userInfoCache;
|
||||
@Autowired
|
||||
private IRoleService iRoleService;
|
||||
@Autowired
|
||||
private SensitiveWordBs sensitiveWordBs;
|
||||
|
||||
private static final PrioritizedUrlTitleDiscover URL_TITLE_DISCOVER = new PrioritizedUrlTitleDiscover();
|
||||
|
||||
@@ -81,7 +83,7 @@ public class TextMsgHandler extends AbstractMsgHandler {
|
||||
MessageExtra extra = Optional.ofNullable(msg.getExtra()).orElse(new MessageExtra());
|
||||
Message update = new Message();
|
||||
update.setId(msg.getId());
|
||||
update.setContent(SensitiveWordUtils.filter(body.getContent()));
|
||||
update.setContent(sensitiveWordBs.filter(body.getContent()));
|
||||
update.setExtra(extra);
|
||||
//如果有回复消息
|
||||
if (Objects.nonNull(body.getReplyMsgId())) {
|
||||
|
||||
@@ -36,16 +36,18 @@ public class GPTChatAIHandler extends AbstractChatAIHandler {
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
UserInfoResp userInfo = userService.getUserInfo(chatGPTProperties.getAIUserId());
|
||||
if (userInfo == null) {
|
||||
log.error("根据AIUserId:{} 找不到用户信息", chatGPTProperties.getAIUserId());
|
||||
throw new RuntimeException("根据AIUserId: " + chatGPTProperties.getAIUserId() + " 找不到用户信息");
|
||||
if (isUse()) {
|
||||
UserInfoResp userInfo = userService.getUserInfo(chatGPTProperties.getAIUserId());
|
||||
if (userInfo == null) {
|
||||
log.error("根据AIUserId:{} 找不到用户信息", chatGPTProperties.getAIUserId());
|
||||
throw new RuntimeException("根据AIUserId: " + chatGPTProperties.getAIUserId() + " 找不到用户信息");
|
||||
}
|
||||
if (StringUtils.isBlank(userInfo.getName())) {
|
||||
log.warn("根据AIUserId:{} 找到的用户信息没有name", chatGPTProperties.getAIUserId());
|
||||
throw new RuntimeException("根据AIUserId: " + chatGPTProperties.getAIUserId() + " 找到的用户没有名字");
|
||||
}
|
||||
AI_NAME = userInfo.getName();
|
||||
}
|
||||
if (StringUtils.isBlank(userInfo.getName())) {
|
||||
log.warn("根据AIUserId:{} 找到的用户信息没有name", chatGPTProperties.getAIUserId());
|
||||
throw new RuntimeException("根据AIUserId: " + chatGPTProperties.getAIUserId() + " 找到的用户没有名字");
|
||||
}
|
||||
AI_NAME = userInfo.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,14 +92,12 @@ public class GPTChatAIHandler extends AbstractChatAIHandler {
|
||||
text = ChatGPTUtils.parseText(response);
|
||||
} catch (Exception e) {
|
||||
log.warn("gpt doChat warn:", e);
|
||||
text= "我累了,明天再聊吧";
|
||||
text = "我累了,明天再聊吧";
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean supports(Message message) {
|
||||
if (!chatGPTProperties.isUse()) {
|
||||
|
||||
@@ -4,7 +4,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.abin.mallchat.common.common.event.UserBlackEvent;
|
||||
import com.abin.mallchat.common.common.event.UserRegisterEvent;
|
||||
import com.abin.mallchat.common.common.utils.AssertUtil;
|
||||
import com.abin.mallchat.common.common.utils.SensitiveWordUtils;
|
||||
import com.abin.mallchat.common.common.utils.sensitiveWord.SensitiveWordBs;
|
||||
import com.abin.mallchat.common.user.dao.BlackDao;
|
||||
import com.abin.mallchat.common.user.dao.ItemConfigDao;
|
||||
import com.abin.mallchat.common.user.dao.UserBackpackDao;
|
||||
@@ -63,6 +63,8 @@ public class UserServiceImpl implements UserService {
|
||||
private BlackDao blackDao;
|
||||
@Autowired
|
||||
private UserSummaryCache userSummaryCache;
|
||||
@Autowired
|
||||
private SensitiveWordBs sensitiveWordBs;
|
||||
|
||||
@Override
|
||||
public UserInfoResp getUserInfo(Long uid) {
|
||||
@@ -76,7 +78,7 @@ public class UserServiceImpl implements UserService {
|
||||
public void modifyName(Long uid, ModifyNameReq req) {
|
||||
//判断名字是不是重复
|
||||
String newName = req.getName();
|
||||
AssertUtil.isFalse(SensitiveWordUtils.hasSensitiveWord(newName), "名字中包含敏感词,请重新输入"); // 判断名字中有没有敏感词
|
||||
AssertUtil.isFalse(sensitiveWordBs.hasSensitiveWord(newName), "名字中包含敏感词,请重新输入"); // 判断名字中有没有敏感词
|
||||
User oldUser = userDao.getByName(newName);
|
||||
AssertUtil.isEmpty(oldUser, "名字已经被抢占了,请换一个哦~~");
|
||||
//判断改名卡够不够
|
||||
|
||||
Reference in New Issue
Block a user