Skip to content

Commit

Permalink
Beta470 (#472)
Browse files Browse the repository at this point in the history
* beta447

* beta448

* beta449

* beta450

* beta451

* beta452

* beta453

* beta454

* beta455

* btea455

* beta456

* beta457

* beta458

* beta460

* beta460

* beta461

* beta462

* beta463

* beta464

* beta465

* beta467

* beta468

* beta469

* beta470
  • Loading branch information
Hoshinonyaruko authored Jul 26, 2024
1 parent 411754b commit f04e555
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 41 deletions.
32 changes: 24 additions & 8 deletions Processor/ProcessGroupAddBot.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,22 @@ type GroupRequestEvent struct {
SubType string `json:"sub_type"`
Time int64 `json:"time"`
UserID int64 `json:"user_id"`
RealUserID string `json:"real_user_id,omitempty"` //当前真实uid
RealGroupID string `json:"real_group_id,omitempty"` //当前真实gid
}

// GroupNoticeEvent 表示群通知事件的数据结构
type GroupNoticeEvent struct {
GroupID int64 `json:"group_id"`
NoticeType string `json:"notice_type"`
OperatorID int64 `json:"operator_id"`
PostType string `json:"post_type"`
SelfID int64 `json:"self_id"`
SubType string `json:"sub_type"`
Time int64 `json:"time"`
UserID int64 `json:"user_id"`
GroupID int64 `json:"group_id"`
NoticeType string `json:"notice_type"`
OperatorID int64 `json:"operator_id"`
PostType string `json:"post_type"`
SelfID int64 `json:"self_id"`
SubType string `json:"sub_type"`
Time int64 `json:"time"`
UserID int64 `json:"user_id"`
RealUserID string `json:"real_user_id,omitempty"` //当前真实uid
RealGroupID string `json:"real_group_id,omitempty"` //当前真实gid
}

// 定义了一个符合 Client 接口的 SelfIntroduceClient 结构体
Expand Down Expand Up @@ -113,6 +117,12 @@ func (p *Processors) ProcessGroupAddBot(data *dto.GroupAddBotEvent) error {
Time: timestampInt64,
UserID: userid64,
}
//增强配置
if !config.GetNativeOb11() {
Request.RealUserID = data.OpMemberOpenID
Request.RealGroupID = data.GroupOpenID
}

Notice = GroupNoticeEvent{
GroupID: GroupID64,
NoticeType: "group_increase",
Expand All @@ -123,6 +133,12 @@ func (p *Processors) ProcessGroupAddBot(data *dto.GroupAddBotEvent) error {
Time: timestampInt64,
UserID: userid64,
}
//增强配置
if !config.GetNativeOb11() {
Notice.RealUserID = data.OpMemberOpenID
Notice.RealGroupID = data.GroupOpenID
}

groupMsgMap := structToMap(Request)
//上报信息到onebotv11应用端(正反ws)
go p.BroadcastMessageToAll(groupMsgMap, p.Apiv2, data)
Expand Down
55 changes: 55 additions & 0 deletions Processor/ProcessInlineSearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ func (p *Processors) ProcessInlineSearch(data *dto.WSInteractionData) error {
UserID: userid64,
Data: data,
}
//增强配置
if !config.GetNativeOb11() {
notice.RealUserID = fromuid
notice.RealGroupID = fromgid
}
//调试
PrintStructWithFieldNames(notice)

Expand Down Expand Up @@ -260,6 +265,31 @@ func (p *Processors) ProcessInlineSearch(data *dto.WSInteractionData) error {
// 储存和群号相关的eventid
fmt.Printf("测试:储存eventid:[%v]LongGroupID64[%v]\n", data.EventID, LongGroupID64)
echo.AddEvnetID(AppIDString, LongGroupID64, data.EventID)

// 上报事件
notice := &OnebotInteractionNotice{
GroupID: GroupID64,
NoticeType: "interaction",
PostType: "notice",
SelfID: selfid64,
SubType: "create",
Time: time.Now().Unix(),
UserID: userid64,
Data: data,
}
//增强配置
if !config.GetNativeOb11() {
notice.RealUserID = fromuid
notice.RealGroupID = fromgid
}
//调试
PrintStructWithFieldNames(notice)

// Convert OnebotGroupMessage to map and send
noticeMap := structToMap(notice)

//上报信息到onebotv11应用端(正反ws)
go p.BroadcastMessageToAll(noticeMap, p.Apiv2, data)
} else if data.UserOpenID != "" {
//私聊回调
newdata := ConvertInteractionToMessage(data)
Expand Down Expand Up @@ -338,6 +368,31 @@ func (p *Processors) ProcessInlineSearch(data *dto.WSInteractionData) error {

// 储存和用户ID相关的eventid
echo.AddEvnetID(AppIDString, LongUserID64, data.EventID)

// 上报事件
notice := &OnebotInteractionNotice{
GroupID: GroupID64,
NoticeType: "interaction",
PostType: "notice",
SelfID: selfid64,
SubType: "create",
Time: time.Now().Unix(),
UserID: userid64,
Data: data,
}
//增强配置
if !config.GetNativeOb11() {
notice.RealUserID = fromuid
notice.RealGroupID = fromgid
}
//调试
PrintStructWithFieldNames(notice)

// Convert OnebotGroupMessage to map and send
noticeMap := structToMap(notice)

//上报信息到onebotv11应用端(正反ws)
go p.BroadcastMessageToAll(noticeMap, p.Apiv2, data)
} else {
// TODO: 区分频道和频道私信 如果有人提需求
// 频道回调
Expand Down
24 changes: 13 additions & 11 deletions Processor/Processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ type OnebotGroupMessage struct {

type OnebotGroupMessageS struct {
RawMessage string `json:"raw_message"`
MessageID string `json:"message_id"`
GroupID string `json:"group_id"` // Can be either string or int depending on p.Settings.CompleteFields
MessageID string `json:"message_id"`
GroupID string `json:"group_id"` // Can be either string or int depending on p.Settings.CompleteFields
MessageType string `json:"message_type"`
PostType string `json:"post_type"`
SelfID int64 `json:"self_id"` // Can be either string or int
Expand All @@ -114,7 +114,7 @@ type OnebotGroupMessageS struct {
Message interface{} `json:"message"` // For array format
MessageSeq int `json:"message_seq"`
Font int `json:"font"`
UserID string `json:"user_id"`
UserID string `json:"user_id"`
RealMessageType string `json:"real_message_type,omitempty"` //当前信息的真实类型 group group_private guild guild_private
RealUserID string `json:"real_user_id,omitempty"` //当前真实uid
RealGroupID string `json:"real_group_id,omitempty"` //当前真实gid
Expand Down Expand Up @@ -145,14 +145,16 @@ type OnebotPrivateMessage struct {

// onebotv11标准扩展
type OnebotInteractionNotice struct {
GroupID int64 `json:"group_id,omitempty"`
NoticeType string `json:"notice_type,omitempty"`
PostType string `json:"post_type,omitempty"`
SelfID int64 `json:"self_id,omitempty"`
SubType string `json:"sub_type,omitempty"`
Time int64 `json:"time,omitempty"`
UserID int64 `json:"user_id,omitempty"`
Data *dto.WSInteractionData `json:"data,omitempty"`
GroupID int64 `json:"group_id,omitempty"`
NoticeType string `json:"notice_type,omitempty"`
PostType string `json:"post_type,omitempty"`
SelfID int64 `json:"self_id,omitempty"`
SubType string `json:"sub_type,omitempty"`
Time int64 `json:"time,omitempty"`
UserID int64 `json:"user_id,omitempty"`
Data *dto.WSInteractionData `json:"data,omitempty"`
RealUserID string `json:"real_user_id,omitempty"` //当前真实uid
RealGroupID string `json:"real_group_id,omitempty"` //当前真实gid
}

// onebotv11标准扩展
Expand Down
16 changes: 9 additions & 7 deletions handlers/send_group_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
}
}

if len(message.Params.GroupID.(string)) != 32 {
if message.Params.GroupID != nil && len(message.Params.GroupID.(string)) != 32 {
if msgType == "" && message.Params.GroupID != nil && checkZeroGroupID(message.Params.GroupID) {
msgType = GetMessageTypeByGroupid(config.GetAppIDStr(), message.Params.GroupID)
}
Expand Down Expand Up @@ -99,13 +99,13 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
var retmsg string

if len(message.Params.GroupID.(string)) == 32 {
if message.Params.GroupID != "" {
idInt64, err = idmap.GenerateRowID(message.Params.GroupID.(string), 9)
} else if message.Params.UserID != "" {
idInt64, err = idmap.GenerateRowID(message.Params.UserID.(string), 9)
}
idInt64, err = idmap.GenerateRowID(message.Params.GroupID.(string), 9)
// 临时的
msgType = "group"
} else if len(message.Params.UserID.(string)) == 32 {
idInt64, err = idmap.GenerateRowID(message.Params.UserID.(string), 9)
// 临时的
msgType = "group_private"
} else {
if message.Params.GroupID != "" {
idInt64, err = ConvertToInt64(message.Params.GroupID)
Expand Down Expand Up @@ -643,7 +643,9 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
retmsg, _ = HandleSendGuildChannelPrivateMsg(client, api, apiv2, message, &value, &RChannelID)
case "group_private":
//用userid还原出openid 这是虚拟成群的群聊私聊信息
message.Params.UserID = message.Params.GroupID.(string)
if message.Params.GroupID != nil && message.Params.GroupID.(string) != "" {
message.Params.UserID = message.Params.GroupID.(string)
}
retmsg, _ = HandleSendPrivateMsg(client, api, apiv2, message)
case "forum":
//用GroupID给ChannelID赋值,因为我们是把频道虚拟成了群
Expand Down
16 changes: 9 additions & 7 deletions handlers/send_group_msg_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func HandleSendGroupMsgRaw(client callapi.Client, api openapi.OpenAPI, apiv2 ope
}
}

if len(message.Params.GroupID.(string)) != 32 {
if message.Params.GroupID != nil && len(message.Params.GroupID.(string)) != 32 {
if msgType == "" && message.Params.GroupID != nil && checkZeroGroupID(message.Params.GroupID) {
msgType = GetMessageTypeByGroupid(config.GetAppIDStr(), message.Params.GroupID)
}
Expand Down Expand Up @@ -84,13 +84,13 @@ func HandleSendGroupMsgRaw(client callapi.Client, api openapi.OpenAPI, apiv2 ope
var retmsg string

if len(message.Params.GroupID.(string)) == 32 {
if message.Params.GroupID != "" {
idInt64, err = idmap.GenerateRowID(message.Params.GroupID.(string), 9)
} else if message.Params.UserID != "" {
idInt64, err = idmap.GenerateRowID(message.Params.UserID.(string), 9)
}
idInt64, err = idmap.GenerateRowID(message.Params.GroupID.(string), 9)
// 临时的
msgType = "group"
} else if len(message.Params.UserID.(string)) == 32 {
idInt64, err = idmap.GenerateRowID(message.Params.UserID.(string), 9)
// 临时的
msgType = "group_private"
} else {
if message.Params.GroupID != "" {
idInt64, err = ConvertToInt64(message.Params.GroupID)
Expand Down Expand Up @@ -476,7 +476,9 @@ func HandleSendGroupMsgRaw(client callapi.Client, api openapi.OpenAPI, apiv2 ope
retmsg, _ = HandleSendGuildChannelPrivateMsg(client, api, apiv2, message, &value, &RChannelID)
case "group_private":
//用userid还原出openid 这是虚拟成群的群聊私聊信息
message.Params.UserID = message.Params.GroupID.(string)
if message.Params.GroupID != nil && message.Params.GroupID.(string) != "" {
message.Params.UserID = message.Params.GroupID.(string)
}
retmsg, _ = HandleSendPrivateMsg(client, api, apiv2, message)
case "forum":
//用GroupID给ChannelID赋值,因为我们是把频道虚拟成了群
Expand Down
12 changes: 4 additions & 8 deletions handlers/send_private_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func HandleSendPrivateMsg(client callapi.Client, api openapi.OpenAPI, apiv2 open
}
}

if len(message.Params.GroupID.(string)) != 32 {
if message.Params.UserID != nil && len(message.Params.UserID.(string)) != 32 {
if msgType == "" && message.Params.UserID != nil && checkZeroUserID(message.Params.UserID) {
msgType = GetMessageTypeByUserid(config.GetAppIDStr(), message.Params.UserID)
}
Expand All @@ -81,14 +81,10 @@ func HandleSendPrivateMsg(client callapi.Client, api openapi.OpenAPI, apiv2 open
var idInt64 int64
var err error

if len(message.Params.GroupID.(string)) == 32 {
if message.Params.GroupID != "" {
idInt64, err = idmap.GenerateRowID(message.Params.GroupID.(string), 9)
} else if message.Params.UserID != "" {
idInt64, err = idmap.GenerateRowID(message.Params.UserID.(string), 9)
}
if len(message.Params.UserID.(string)) == 32 {
idInt64, err = idmap.GenerateRowID(message.Params.UserID.(string), 9)
// 临时的
msgType = "private"
msgType = "group_private"
} else {
if message.Params.GroupID != "" {
idInt64, err = ConvertToInt64(message.Params.GroupID)
Expand Down

0 comments on commit f04e555

Please sign in to comment.