Skip to content

Commit

Permalink
修改Ctx.Message为message.Message
Browse files Browse the repository at this point in the history
  • Loading branch information
lianhong2758 committed Nov 15, 2024
1 parent b1855fc commit c9c7928
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 27 deletions.
5 changes: 3 additions & 2 deletions adapter/ob11/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ func OnlyMaster(ctx *rosm.Ctx) bool {

// 群主权限以上
func OnlyOverHost(ctx *rosm.Ctx) bool {
return OnlyMaster(ctx) || ctx.Message.(*Event).Sender.Role == "owner"
return OnlyMaster(ctx) || ctx.State["event"].(*Event).Sender.Role == "owner"
}

// 管理员权限以上
func OnlyOverAdministrator(ctx *rosm.Ctx) bool {
return OnlyMaster(ctx) || ctx.Message.(*Event).Sender.Role == "owner" || ctx.Message.(*Event).Sender.Role == "admin"
return OnlyMaster(ctx) || ctx.State["event"].(*Event).Sender.Role == "owner" ||
ctx.State["event"].(*Event).Sender.Role == "admin"
}

// 触发消息是否是回复消息
Expand Down
12 changes: 8 additions & 4 deletions adapter/ob11/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ func (c *Config) process(e *Event) {
},
MsgID: tool.BytesToString(e.RawMessageID),
},
Message: e,
State: map[string]any{"event":e},
Message: e.Message,
Bot: c,
}
ctx.Being.IsAtMe = true
Expand All @@ -57,7 +58,8 @@ func (c *Config) process(e *Event) {
},
MsgID: tool.BytesToString(e.RawMessageID),
},
Message: e,
State: map[string]any{"event":e},
Message: e.Message,
Bot: c,
}

Expand All @@ -83,7 +85,8 @@ func (c *Config) process(e *Event) {
ID: tool.Int64ToString(e.UserID),
},
},
Message: e,
State: map[string]any{"event":e},
Message: e.Message,
Bot: c,
}
log.Debug(ctx)
Expand All @@ -96,7 +99,8 @@ func (c *Config) process(e *Event) {
ID: tool.Int64ToString(e.UserID),
},
},
Message: e,
State: map[string]any{"event":e},
Message: e.Message,
Bot: c,
}
log.Debug(ctx)
Expand Down
2 changes: 1 addition & 1 deletion adapter/qq/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func (c *Config) OnlyReply(ctx *rosm.Ctx) bool {
case "GROUP_AT_MESSAGE_CREATE":
return false
case "DIRECT_MESSAGE_CREATE", "AT_MESSAGE_CREATE", "MESSAGE_CREATE":
return ctx.Message.(*RawGuildMessage).MessageReference.MessageID != ""
return ctx.State["event"].(*RawGuildMessage).MessageReference.MessageID != ""
default:
return false
}
Expand Down
2 changes: 1 addition & 1 deletion adapter/qq/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (c *Config) BotSendCustom(ctx *rosm.Ctx, count any) rosm.H {
}

func (c *Config) GetPortraitURI(ctx *rosm.Ctx) string {
if r, ok := ctx.Message.(*RawGuildMessage); ok {
if r, ok := ctx.State["event"].(*RawGuildMessage); ok {
return r.Author.Avatar
}
return ""
Expand Down
13 changes: 7 additions & 6 deletions adapter/qq/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"strings"

"github.com/lianhong2758/RosmBot-MUL/message"
"github.com/lianhong2758/RosmBot-MUL/rosm"
log "github.com/sirupsen/logrus"
)
Expand All @@ -22,15 +23,15 @@ func (c *Config) process(playload *WebsocketPayload) {
ctx := &rosm.Ctx{
Bot: c,
BotType: "qq_group",
Message: raw,
Message: message.Message{},
Being: &rosm.Being{
GroupID: raw.Author.UserOpenid,
User: &rosm.UserData{
ID: raw.Author.UserOpenid,
},
MsgID: raw.ID,
},
State: H{"type": playload.T, "id": raw.ID},
State: H{"type": playload.T, "id": raw.ID, "event": raw},
}
word := raw.Content
//判断@
Expand All @@ -50,7 +51,7 @@ func (c *Config) process(playload *WebsocketPayload) {
ctx := &rosm.Ctx{
Bot: c,
BotType: "qq_group",
Message: raw,
Message: message.Message{},
Being: &rosm.Being{
GroupID: raw.GroupID,
User: &rosm.UserData{
Expand All @@ -59,7 +60,7 @@ func (c *Config) process(playload *WebsocketPayload) {
},
MsgID: raw.ID,
},
State: H{"type": playload.T, "id": raw.ID},
State: H{"type": playload.T, "id": raw.ID, "event": raw},
}
word := raw.Content
//判断@
Expand All @@ -85,7 +86,7 @@ func (c *Config) process(playload *WebsocketPayload) {
ctx := &rosm.Ctx{
Bot: c,
BotType: "qq_gulid",
Message: raw,
Message: message.Message{},
Being: &rosm.Being{
GroupID: raw.ChannelID,
GuildID: raw.GuildID,
Expand All @@ -96,7 +97,7 @@ func (c *Config) process(playload *WebsocketPayload) {
},
MsgID: raw.ID,
},
State: H{"type": playload.T, "id": raw.ID},
State: H{"type": playload.T, "id": raw.ID, "event": raw},
}
word := raw.Content
//判断@
Expand Down
2 changes: 1 addition & 1 deletion plugins/pixiv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func GetMustPic(ctx *rosm.Ctx) []string {
// 获取这次ctx内容的图片
func GetPicFormCtx(ctx *rosm.Ctx) []string {
var urls = []string{}
e, _ := ctx.Message.(*ob11.Event)
e, _ := ctx.State["event"].(*ob11.Event)
for _, elem := range e.Message {
if elem.Type == "image" {
if elem.Data["url"] != "" {
Expand Down
2 changes: 1 addition & 1 deletion plugins/test/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {
})
//跟随撤回
en.OnNoticeWithType(rosm.FriendRecall, rosm.GroupRecall).MUL("ob11").Handle(func(ctx *rosm.Ctx) {
if id, ok := ctx.Message.(*ob11.Event).MessageID.(int64); ok {
if id, ok := ctx.State["event"].(*ob11.Event).MessageID.(int64); ok {
if sids := rosm.GetMessageIDFormMapCache(tool.Int64ToString(id)); len(sids) > 0 {
for _, sid := range sids {
tool.WaitWhile()
Expand Down
10 changes: 6 additions & 4 deletions rosm/msg.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package rosm

import "github.com/lianhong2758/RosmBot-MUL/message"

// 上下文结构
type Ctx struct {
Bot Boter
BotType string
Message any //解析后的原始消息
Being *Being //常用消息解析,需实现
State map[string]any //框架中途产生的内容,不固定,即时有效
on bool //插件是否在本群开启
Message message.Message //Message
Being *Being //常用消息解析,需实现
State map[string]any //框架中途产生的内容,不固定,即时有效
on bool //插件是否在本群开启
}

// 常用数据
Expand Down
18 changes: 11 additions & 7 deletions rosm/mul.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,13 @@ type H = message.H

// Boter bot主接口,由server实现,Run函数由server自己调用运行
type Boter interface {
//发送消息
BotSend(*Ctx, ...message.MessageSegment) H
//特殊的发送格式
BotSendCustom(*Ctx, any) H
//头像获取
GetPortraitURI(*Ctx) string
//运行,用于开启接收消息和调用插件
Run()

//Bot信息查询
Card() *BotCard

BotRuler
BotCaller
}

// BotRuler rule的实现,如果不存在,适配器需要设置函数返回false
Expand All @@ -36,6 +30,16 @@ type BotRuler interface {
OnlyOverAdministrator(*Ctx) bool
}

// 接口调用
type BotCaller interface {
//发送消息
BotSend(*Ctx, ...message.MessageSegment) H
//特殊的发送格式
BotSendCustom(*Ctx, any) H
//头像获取
GetPortraitURI(*Ctx) string
}

type BotCard struct {
BotName string `json:"bot_name"`
BotID string `json:"bot_id,omitempty"`
Expand Down

0 comments on commit c9c7928

Please sign in to comment.