Skip to content

Commit

Permalink
fix: abnormal call if len(question)=0
Browse files Browse the repository at this point in the history
  • Loading branch information
RicheyJang committed Jan 26, 2022
1 parent 22c546f commit 6d5b127
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions plugins/chat/deal.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ func sendChatMessage(ctx *zero.Ctx, msg message.Message) {

// DIYDialogue Dealer: 用户自定义对话
func DIYDialogue(ctx *zero.Ctx, question string) message.Message {
if len(question) == 0 {
return nil
}
if !ctx.Event.IsToMe && proxy.GetConfigBool("onlytome") { // 若配置了onlytome,则仅处理onlytome消息
return nil
}
Expand Down
8 changes: 6 additions & 2 deletions plugins/chat/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var proxy *manager.PluginProxy
var info = manager.PluginInfo{
Name: "聊天",
Usage: `来闲聊吧!
如何进行自定义问答:(仅限群管理员在群中调用
如何进行自定义问答:(默认仅限群管理员在群中调用,且开头需要加上机器人昵称 如派蒙
新增问答
[问句内容]
[回答内容]:注意共三行哦,将会添加一条相应的问答
Expand All @@ -31,7 +31,7 @@ var info = manager.PluginInfo{
config-plugin文件配置项:
chat.default.self 自我介绍内容
chat.diylevel 自定义问答功能所需的最低管理员权限等级,默认为5,设为0则非群管理员用户也可自定义
chat.onlytome 在群中调用已自定义的问答时是(true)否(false)需要加上机器人名字前缀或者@机器人`,
chat.onlytome 在群中调用已自定义的问句时是(true)否(false)需要加上机器人名字前缀或者@机器人`,
}

const DIYDialogueLevelKey = "diylevel"
Expand All @@ -42,6 +42,7 @@ func init() {
return
}
proxy.OnCommands([]string{"新增对话", "新增问答"}, zero.OnlyToMe).SetBlock(true).SetPriority(5).Handle(addDialogue)
// proxy.OnRegex("^我?问(.*)你?答(.*)$", zero.OnlyToMe).SetBlock(true).SetPriority(6).Handle(addDialogue)
proxy.OnCommands([]string{"删除对话", "删除问答"}, zero.OnlyToMe).SetBlock(true).SetPriority(5).Handle(delDialogue)
proxy.OnCommands([]string{"已有对话", "已有问答"}, zero.OnlyToMe).SetBlock(true).SetPriority(5).Handle(showDialogue)
proxy.OnMessage().SetBlock(true).SetPriority(10).Handle(dealChat)
Expand Down Expand Up @@ -148,6 +149,9 @@ func analysisCtx(ctx *zero.Ctx) (question string, answer message.Message, err er
firstMsg = firstMsg[id:]
// 解析命令消息
subs := strings.SplitN(firstMsg, "\n", 3)
//if len(subs) < 3 {
// subs = utils.GetRegexpMatched(ctx)
//}
if len(subs) < 3 {
return "", nil, fmt.Errorf("too few parameters")
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/chat/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func GetDialogue(groupID int64, question string) message.Message {
rows := proxy.GetDB().Where(&GroupChatDialogue{
GroupID: groupID,
Question: question,
}).Find(&resD).RowsAffected
}, "group_id", "question").Find(&resD).RowsAffected
if rows == 0 {
return nil
}
Expand Down

0 comments on commit 6d5b127

Please sign in to comment.