Skip to content

Commit

Permalink
add: chat dealer for question = plugin name
Browse files Browse the repository at this point in the history
  • Loading branch information
RicheyJang committed Jan 26, 2022
1 parent ae39c0f commit 22c546f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion basic/help/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func formSingleHelpMsg(cmd string, isSuper, isPrimary bool, priority int, blackK
}
}
if selected == nil {
return message.Text("没有找到这个功能哦")
return message.Text("没有找到这个功能哦,或在群聊中无法查看功能详情")
}
// 插件状态检查
if _, ok := blackKeys[selected.Key]; ok {
Expand Down
28 changes: 25 additions & 3 deletions plugins/chat/deal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package chat
import (
"fmt"

"github.com/RicheyJang/PaimengBot/manager"
"github.com/RicheyJang/PaimengBot/utils"

zero "github.com/wdvxdr1123/ZeroBot"
Expand All @@ -13,6 +14,7 @@ type Dealer func(ctx *zero.Ctx, question string) message.Message

var dealers = []Dealer{ // 在此添加新的Dealer即可,其它事宜会自动处理
WhoAreYou,
PluginName,
IDoNotKnow,
}

Expand All @@ -21,7 +23,7 @@ func dealChat(ctx *zero.Ctx) {
// 优先尝试自定义问答
msg := DIYDialogue(ctx, question)
if len(msg) > 0 {
ctx.SendChain(append(message.Message{message.At(ctx.Event.UserID)}, msg...)...)
sendChatMessage(ctx, msg)
return
}
// 自定义问答无内容,则仅处理OnlyToMe且非空消息
Expand All @@ -31,15 +33,23 @@ func dealChat(ctx *zero.Ctx) {
for _, deal := range dealers {
msg = deal(ctx, question)
if len(msg) > 0 {
ctx.SendChain(append(message.Message{message.At(ctx.Event.UserID)}, msg...)...)
sendChatMessage(ctx, msg)
return
}
}
}

func sendChatMessage(ctx *zero.Ctx, msg message.Message) {
if utils.IsMessagePrimary(ctx) {
ctx.Send(msg)
} else {
ctx.SendChain(append(message.Message{message.At(ctx.Event.UserID)}, msg...)...)
}
}

// DIYDialogue Dealer: 用户自定义对话
func DIYDialogue(ctx *zero.Ctx, question string) message.Message {
if !ctx.Event.IsToMe && proxy.GetConfigBool("onlytome") {
if !ctx.Event.IsToMe && proxy.GetConfigBool("onlytome") { // 若配置了onlytome,则仅处理onlytome消息
return nil
}
if utils.IsMessageGroup(ctx) {
Expand All @@ -59,6 +69,18 @@ func WhoAreYou(ctx *zero.Ctx, question string) message.Message {
return nil
}

// PluginName Dealer: 问题为插件名,返回帮助信息
func PluginName(ctx *zero.Ctx, question string) message.Message {
plugins := manager.GetAllPluginConditions()
for _, plugin := range plugins {
if question == plugin.Name {
return message.Message{message.Text(
fmt.Sprintf("这是%v的一个功能名哟,想知道这个功能怎么使用的话,请说:\n帮助 %v", utils.GetBotNickname(), question))}
}
}
return nil
}

// IDoNotKnow Dealer: XX不知道
func IDoNotKnow(ctx *zero.Ctx, question string) message.Message {
return message.Message{message.Text(fmt.Sprintf("%v不知道哦", utils.GetBotNickname()))}
Expand Down

0 comments on commit 22c546f

Please sign in to comment.