Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta90 #241

Merged
merged 4 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions Processor/ProcessC2CMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ func (p *Processors) ProcessC2CMessage(data *dto.WSC2CMessageData) error {
if config.GetArrayValue() {
segmentedMessages = handlers.ConvertToSegmentedMessage(data)
}
IsBindedUserId := idmap.CheckValue(data.Author.ID, userid64)
var IsBindedUserId bool
if config.GetHashIDValue() {
IsBindedUserId = idmap.CheckValue(data.Author.ID, userid64)
} else {
IsBindedUserId = idmap.CheckValuev2(userid64)
}
privateMsg := OnebotPrivateMessage{
RawMessage: messageText,
Message: segmentedMessages,
Expand All @@ -98,11 +103,15 @@ func (p *Processors) ProcessC2CMessage(data *dto.WSC2CMessageData) error {
Nickname: "", //这个不支持,但加机器人好友,会收到一个事件,可以对应储存获取,用idmaps可以做到.
UserID: userid64,
},
SubType: "friend",
Time: time.Now().Unix(),
Avatar: "", //todo 同上
RealMessageType: "group_private",
IsBindedUserId: IsBindedUserId,
SubType: "friend",
Time: time.Now().Unix(),
}
if !config.GetNativeOb11() {
privateMsg.RealMessageType = "group_private"
privateMsg.IsBindedUserId = IsBindedUserId
if IsBindedUserId {
privateMsg.Avatar, _ = GenerateAvatarURL(userid64)
}
}
// 根据条件判断是否添加Echo字段
if config.GetTwoWayEcho() {
Expand Down
41 changes: 29 additions & 12 deletions Processor/ProcessChannelDirectMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData)
if config.GetArrayValue() {
segmentedMessages = handlers.ConvertToSegmentedMessage(data)
}
IsBindedUserId := idmap.CheckValue(data.Author.ID, userid64)
var IsBindedUserId bool
if config.GetHashIDValue() {
IsBindedUserId = idmap.CheckValue(data.Author.ID, userid64)
} else {
IsBindedUserId = idmap.CheckValuev2(userid64)
}

privateMsg := OnebotPrivateMessage{
RawMessage: messageText,
Message: segmentedMessages,
Expand All @@ -119,11 +125,14 @@ func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData)
Nickname: data.Member.Nick,
UserID: userid64,
},
SubType: "friend",
Time: time.Now().Unix(),
Avatar: data.Author.Avatar,
RealMessageType: "guild_private",
IsBindedUserId: IsBindedUserId,
SubType: "friend",
Time: time.Now().Unix(),
}
//增强字段
if !config.GetNativeOb11() {
privateMsg.RealMessageType = "guild_private"
privateMsg.IsBindedUserId = IsBindedUserId
privateMsg.Avatar = data.Author.Avatar
}
// 根据条件判断是否添加Echo字段
if config.GetTwoWayEcho() {
Expand Down Expand Up @@ -318,7 +327,12 @@ func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData)
if config.GetArrayValue() {
segmentedMessages = handlers.ConvertToSegmentedMessage(data)
}
IsBindedUserId := idmap.CheckValue(data.Author.ID, userid64)
var IsBindedUserId bool
if config.GetHashIDValue() {
IsBindedUserId = idmap.CheckValue(data.Author.ID, userid64)
} else {
IsBindedUserId = idmap.CheckValuev2(userid64)
}
groupMsg := OnebotGroupMessage{
RawMessage: messageText,
Message: segmentedMessages,
Expand All @@ -338,11 +352,14 @@ func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData)
Area: "",
Level: "0",
},
SubType: "normal",
Time: time.Now().Unix(),
Avatar: data.Author.Avatar,
RealMessageType: "guild_private",
IsBindedUserId: IsBindedUserId,
SubType: "normal",
Time: time.Now().Unix(),
}
//增强字段
if !config.GetNativeOb11() {
groupMsg.RealMessageType = "guild_private"
groupMsg.IsBindedUserId = IsBindedUserId
groupMsg.Avatar = data.Author.Avatar
}
// 根据条件判断是否添加Echo字段
if config.GetTwoWayEcho() {
Expand Down
27 changes: 19 additions & 8 deletions Processor/ProcessGroupMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,14 @@ func (p *Processors) ProcessGroupMessage(data *dto.WSGroupATMessageData) error {
if config.GetArrayValue() {
segmentedMessages = handlers.ConvertToSegmentedMessage(data)
}
IsBindedUserId := idmap.CheckValue(data.Author.ID, userid64)
IsBindedGroupId := idmap.CheckValue(data.GroupID, GroupID64)
var IsBindedUserId, IsBindedGroupId bool
if config.GetHashIDValue() {
IsBindedUserId = idmap.CheckValue(data.Author.ID, userid64)
IsBindedGroupId = idmap.CheckValue(data.GroupID, GroupID64)
} else {
IsBindedUserId = idmap.CheckValuev2(userid64)
IsBindedGroupId = idmap.CheckValuev2(GroupID64)
}
groupMsg := OnebotGroupMessage{
RawMessage: messageText,
Message: segmentedMessages,
Expand All @@ -106,12 +112,17 @@ func (p *Processors) ProcessGroupMessage(data *dto.WSGroupATMessageData) error {
Area: "0",
Level: "0",
},
SubType: "normal",
Time: time.Now().Unix(),
Avatar: "",
RealMessageType: "group",
IsBindedUserId: IsBindedUserId,
IsBindedGroupId: IsBindedGroupId,
SubType: "normal",
Time: time.Now().Unix(),
}
//增强配置
if !config.GetNativeOb11() {
groupMsg.RealMessageType = "group"
groupMsg.IsBindedUserId = IsBindedUserId
groupMsg.IsBindedGroupId = IsBindedGroupId
if IsBindedUserId {
groupMsg.Avatar, _ = GenerateAvatarURL(userid64)
}
}
//根据条件判断是否增加nick和card
var CaN = config.GetCardAndNick()
Expand Down
19 changes: 17 additions & 2 deletions Processor/ProcessGuildATMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ func (p *Processors) ProcessGuildATMessage(data *dto.WSATMessageData) error {
}
//转成int再互转
idmap.WriteConfigv2(fmt.Sprint(ChannelID64), "guild_id", data.GuildID)
//储存原来的(获取群列表需要)
idmap.WriteConfigv2(data.ChannelID, "guild_id", data.GuildID)
//转换at和图片
messageText := handlers.RevertTransformedText(data, "guild", p.Api, p.Apiv2, ChannelID64)
if messageText == "" {
Expand All @@ -178,8 +180,14 @@ func (p *Processors) ProcessGuildATMessage(data *dto.WSATMessageData) error {
if config.GetArrayValue() {
segmentedMessages = handlers.ConvertToSegmentedMessage(data)
}
IsBindedUserId := idmap.CheckValue(data.Author.ID, userid64)
IsBindedGroupId := idmap.CheckValue(data.GroupID, ChannelID64)
var IsBindedUserId, IsBindedGroupId bool
if config.GetHashIDValue() {
IsBindedUserId = idmap.CheckValue(data.Author.ID, userid64)
IsBindedGroupId = idmap.CheckValue(data.ChannelID, ChannelID64)
} else {
IsBindedUserId = idmap.CheckValuev2(userid64)
IsBindedGroupId = idmap.CheckValuev2(ChannelID64)
}
groupMsg := OnebotGroupMessage{
RawMessage: messageText,
Message: segmentedMessages,
Expand All @@ -205,6 +213,13 @@ func (p *Processors) ProcessGuildATMessage(data *dto.WSATMessageData) error {
IsBindedUserId: IsBindedUserId,
IsBindedGroupId: IsBindedGroupId,
}
//增强配置
if !config.GetNativeOb11() {
groupMsg.RealMessageType = "guild"
groupMsg.IsBindedUserId = IsBindedUserId
groupMsg.IsBindedGroupId = IsBindedGroupId
groupMsg.Avatar = data.Author.Avatar
}
// 根据条件判断是否添加Echo字段
if config.GetTwoWayEcho() {
groupMsg.Echo = echostr
Expand Down
28 changes: 19 additions & 9 deletions Processor/ProcessGuildNormalMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ func (p *Processors) ProcessGuildNormalMessage(data *dto.WSMessageData) error {
return nil
}
}

//转成int再互转
idmap.WriteConfigv2(fmt.Sprint(ChannelID64), "guild_id", data.GuildID)
//储存原来的(获取群列表需要)
idmap.WriteConfigv2(data.ChannelID, "guild_id", data.GuildID)
//转换at
messageText := handlers.RevertTransformedText(data, "guild", p.Api, p.Apiv2, ChannelID64)
if messageText == "" {
Expand All @@ -182,8 +183,14 @@ func (p *Processors) ProcessGuildNormalMessage(data *dto.WSMessageData) error {
if config.GetArrayValue() {
segmentedMessages = handlers.ConvertToSegmentedMessage(data)
}
IsBindedUserId := idmap.CheckValue(data.Author.ID, userid64)
IsBindedGroupId := idmap.CheckValue(data.GroupID, ChannelID64)
var IsBindedUserId, IsBindedGroupId bool
if config.GetHashIDValue() {
IsBindedUserId = idmap.CheckValue(data.Author.ID, userid64)
IsBindedGroupId = idmap.CheckValue(data.ChannelID, ChannelID64)
} else {
IsBindedUserId = idmap.CheckValuev2(userid64)
IsBindedGroupId = idmap.CheckValuev2(ChannelID64)
}
groupMsg := OnebotGroupMessage{
RawMessage: messageText,
Message: segmentedMessages,
Expand All @@ -202,12 +209,15 @@ func (p *Processors) ProcessGuildNormalMessage(data *dto.WSMessageData) error {
Area: "",
Level: "0",
},
SubType: "normal",
Time: time.Now().Unix(),
Avatar: data.Author.Avatar,
RealMessageType: "guild",
IsBindedUserId: IsBindedUserId,
IsBindedGroupId: IsBindedGroupId,
SubType: "normal",
Time: time.Now().Unix(),
}
//增强配置
if !config.GetNativeOb11() {
groupMsg.RealMessageType = "guild"
groupMsg.IsBindedUserId = IsBindedUserId
groupMsg.IsBindedGroupId = IsBindedGroupId
groupMsg.Avatar = data.Author.Avatar
}
// 根据条件判断是否添加Echo字段
if config.GetTwoWayEcho() {
Expand Down
49 changes: 38 additions & 11 deletions Processor/Processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/json"
"errors"
"fmt"
"math/big"
"net/http"
"reflect"
"regexp"
Expand Down Expand Up @@ -86,9 +87,9 @@ type OnebotGroupMessage struct {
MessageSeq int `json:"message_seq"`
Font int `json:"font"`
UserID int64 `json:"user_id"`
RealMessageType string `json:"real_message_type"` //当前信息的真实类型 group group_private guild guild_private
IsBindedGroupId bool `json:"is_binded_group_id"` //当前群号是否是binded后的
IsBindedUserId bool `json:"is_binded_user_id"` //当前用户号号是否是binded后的
RealMessageType string `json:"real_message_type,omitempty"` //当前信息的真实类型 group group_private guild guild_private
IsBindedGroupId bool `json:"is_binded_group_id,omitempty"` //当前群号是否是binded后的
IsBindedUserId bool `json:"is_binded_user_id,omitempty"` //当前用户号号是否是binded后的
}

// 私聊信息事件
Expand All @@ -103,12 +104,12 @@ type OnebotPrivateMessage struct {
Time int64 `json:"time"`
Avatar string `json:"avatar,omitempty"`
Echo string `json:"echo,omitempty"`
Message interface{} `json:"message"` // For array format
MessageSeq int `json:"message_seq"` // Optional field
Font int `json:"font"` // Optional field
UserID int64 `json:"user_id"` // Can be either string or int depending on logic
RealMessageType string `json:"real_message_type"` //当前信息的真实类型 group group_private guild guild_private
IsBindedUserId bool `json:"is_binded_user_id"` //当前用户号号是否是binded后的
Message interface{} `json:"message"` // For array format
MessageSeq int `json:"message_seq"` // Optional field
Font int `json:"font"` // Optional field
UserID int64 `json:"user_id"` // Can be either string or int depending on logic
RealMessageType string `json:"real_message_type,omitempty"` //当前信息的真实类型 group group_private guild guild_private
IsBindedUserId bool `json:"is_binded_user_id,omitempty"` //当前用户号号是否是binded后的
}

type PrivateSender struct {
Expand Down Expand Up @@ -261,10 +262,23 @@ func (p *Processors) BroadcastMessageToAll(message map[string]interface{}) error
return fmt.Errorf(strings.Join(errors, "; "))
}

PostMessageToUrls(message)
//判断是否填写了反向post地址
if !allEmpty(config.GetPostUrl()) {
PostMessageToUrls(message)
}
return nil
}

// allEmpty checks if all the strings in the slice are empty.
func allEmpty(addresses []string) bool {
for _, addr := range addresses {
if addr != "" {
return false
}
}
return true
}

// 上报信息给反向Http
func PostMessageToUrls(message map[string]interface{}) {
// 获取上报 URL 列表
Expand Down Expand Up @@ -536,7 +550,7 @@ func performBindOperation(cleanedMessage string, data interface{}, Type string,
if err != nil {
SendMessage(err.Error(), data, Type, p, p2)
} else {
SendMessage("绑定成功,目前状态:\n当前真实值 "+now+"\n当前虚拟值 "+new, data, Type, p, p2)
SendMessage("绑定成功,目前状态:\n当前真实值 "+new+"\n当前虚拟值 "+now, data, Type, p, p2)
}

return nil
Expand Down Expand Up @@ -825,3 +839,16 @@ func updateMappings(userid64, vuinValue, GroupID64, idValue int64) error {
}
return nil
}

// GenerateAvatarURL 生成根据给定 userID 和随机 q 值组合的 QQ 头像 URL
func GenerateAvatarURL(userID int64) (string, error) {
// 使用 crypto/rand 生成更安全的随机数
n, err := rand.Int(rand.Reader, big.NewInt(5))
if err != nil {
return "", err
}
qNumber := n.Int64() + 1 // 产生 1 到 5 的随机数

// 构建并返回 URL
return fmt.Sprintf("http://q%d.qlogo.cn/g?b=qq&nk=%d&s=640", qNumber, userID), nil
}
13 changes: 13 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ type Settings struct {
PostSecret []string `yaml:"post_secret"`
PostMaxRetries []int `yaml:"post_max_retries"`
PostRetriesInterval []int `yaml:"post_retries_interval"`
NativeOb11 bool `yaml:"native_ob11"`
}

// LoadConfig 从文件中加载配置并初始化单例配置
Expand Down Expand Up @@ -1221,3 +1222,15 @@ func GetPostRetriesInterval() []int {
}
return instance.Settings.PostRetriesInterval
}

// 获取GetTransferUrl的值
func GetNativeOb11() bool {
mu.Lock()
defer mu.Unlock()

if instance == nil {
mylog.Println("Warning: instance is nil when trying to NativeOb11 value.")
return false
}
return instance.Settings.NativeOb11
}
2 changes: 1 addition & 1 deletion handlers/send_group_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
Vuserid, ok := message.Params.UserID.(string)
if !ok {
mylog.Printf("Error illegal UserID")
return
return "", nil
}
if Vuserid != "" && config.GetIdmapPro() {
RChannelID, _, err = idmap.RetrieveRowByIDv2Pro(message.Params.ChannelID, Vuserid)
Expand Down
Loading
Loading