diff --git a/contex.go b/contex.go index 80f0f2d..feaac9a 100644 --- a/contex.go +++ b/contex.go @@ -6,6 +6,7 @@ import ( "unsafe" "github.com/modern-go/reflect2" + "github.com/wdvxdr1123/ZeroBot/message" ) // Ctx represents the Context which hold the event. @@ -90,6 +91,14 @@ func (ctx *Ctx) Send(message interface{}) int64 { return ctx.SendPrivateMessage(ctx.Event.UserID, message) } +// SendChain 快捷发送消息-消息链 +func (ctx *Ctx) SendChain(message ...message.MessageSegment) int64 { + if ctx.Event.GroupID != 0 { + return ctx.SendGroupMessage(ctx.Event.GroupID, message) + } + return ctx.SendPrivateMessage(ctx.Event.UserID, message) +} + // FutureEvent ... func (ctx *Ctx) FutureEvent(Type string, rule ...Rule) *FutureEvent { return ctx.ma.FutureEvent(Type, rule...) diff --git a/matcher.go b/matcher.go index fbdbf91..e6a0eac 100644 --- a/matcher.go +++ b/matcher.go @@ -63,6 +63,21 @@ func (m *Matcher) SetPriority(priority int) *Matcher { return m } +// FirstPriority 设置当前 Matcher 优先级 - 0 +func (m *Matcher) FirstPriority() *Matcher { + return m.SetPriority(0) +} + +// SecondPriority 设置当前 Matcher 优先级 - 1 +func (m *Matcher) SecondPriority() *Matcher { + return m.SetPriority(1) +} + +// ThirdPriority 设置当前 Matcher 优先级 - 2 +func (m *Matcher) ThirdPriority() *Matcher { + return m.SetPriority(2) +} + // StoreMatcher store a matcher to matcher list. func StoreMatcher(m *Matcher) *Matcher { matcherLock.Lock() diff --git a/message/message.go b/message/message.go index 64c49a3..81b940b 100644 --- a/message/message.go +++ b/message/message.go @@ -1,6 +1,7 @@ package message import ( + "fmt" "strconv" "strings" @@ -75,11 +76,11 @@ func (m MessageSegment) CQCode() string { // Text 纯文本 // https://github.com/howmanybots/onebot/blob/master/v11/specs/message/segment.md#%E7%BA%AF%E6%96%87%E6%9C%AC -func Text(text string) MessageSegment { +func Text(text ...interface{}) MessageSegment { return MessageSegment{ Type: "text", Data: map[string]string{ - "text": text, + "text": fmt.Sprint(text...), }, } } @@ -142,15 +143,14 @@ func Music(mType string, id int64) MessageSegment { // CustomMusic 音乐自定义分享 // https://github.com/howmanybots/onebot/blob/master/v11/specs/message/segment.md#%E9%9F%B3%E4%B9%90%E8%87%AA%E5%AE%9A%E4%B9%89%E5%88%86%E4%BA%AB- -func CustomMusic(subType, url, audio, title string) MessageSegment { +func CustomMusic(url, audio, title string) MessageSegment { return MessageSegment{ Type: "music", Data: map[string]string{ - "type": "custom", - "sub_type": subType, - "url": url, - "audio": audio, - "title": title, + "type": "custom", + "url": url, + "audio": audio, + "title": title, }, } } @@ -267,6 +267,12 @@ func TTS(text string) MessageSegment { } } +// Add 为 MessageSegment 的 Data 增加一个字段 +func (m MessageSegment) Add(key string, val interface{}) MessageSegment { + m.Data[key] = fmt.Sprint(val) + return m +} + // ReplyWithMessage returns a reply message func ReplyWithMessage(messageID int64, m ...MessageSegment) Message { return append(Message{Reply(messageID)}, m...)