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

Beta482 #488

Merged
merged 37 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a6ebe57
beta447
Hoshinonyaruko Jun 29, 2024
1d63fae
beta448
Hoshinonyaruko Jul 1, 2024
cd34627
beta449
Hoshinonyaruko Jul 4, 2024
b790b29
beta450
Hoshinonyaruko Jul 4, 2024
7a9b56a
beta451
Hoshinonyaruko Jul 4, 2024
e17d0d4
beta452
Hoshinonyaruko Jul 4, 2024
1318175
beta453
Hoshinonyaruko Jul 4, 2024
b7f291c
beta454
Hoshinonyaruko Jul 4, 2024
f921895
beta455
Hoshinonyaruko Jul 9, 2024
24108c6
btea455
Hoshinonyaruko Jul 9, 2024
7cdc968
beta456
Hoshinonyaruko Jul 9, 2024
b5d784e
beta457
Hoshinonyaruko Jul 9, 2024
61e4001
beta458
Hoshinonyaruko Jul 9, 2024
6d4116a
beta460
Hoshinonyaruko Jul 9, 2024
2c1f1b7
beta460
Hoshinonyaruko Jul 11, 2024
5c312cd
beta461
Hoshinonyaruko Jul 12, 2024
58304eb
beta462
Hoshinonyaruko Jul 13, 2024
7e7c9f3
beta463
Hoshinonyaruko Jul 15, 2024
188f250
beta464
Hoshinonyaruko Jul 15, 2024
af0296d
beta465
Hoshinonyaruko Jul 18, 2024
500135c
beta467
Hoshinonyaruko Jul 21, 2024
c1a588c
beta468
Hoshinonyaruko Jul 21, 2024
1df8e15
beta469
Hoshinonyaruko Jul 21, 2024
f57ab7b
beta470
Hoshinonyaruko Jul 26, 2024
cd21ad9
beta471
Hoshinonyaruko Aug 1, 2024
6039272
beta472
Hoshinonyaruko Aug 1, 2024
c45b450
beta473
Hoshinonyaruko Aug 1, 2024
f89d6c5
beta473
Hoshinonyaruko Aug 3, 2024
b54fdee
beta475
Hoshinonyaruko Aug 5, 2024
a30a697
beta476
Hoshinonyaruko Aug 8, 2024
ab805cc
beta478
Hoshinonyaruko Aug 8, 2024
6debefd
beta479
Hoshinonyaruko Aug 17, 2024
9cc7e5d
beta479
Hoshinonyaruko Aug 17, 2024
c0fe93c
beta480
Hoshinonyaruko Aug 18, 2024
91cf223
beta481
Hoshinonyaruko Aug 18, 2024
a3aa6c1
beta482
Hoshinonyaruko Aug 18, 2024
c49f871
Merge branch 'main' into beta482
Hoshinonyaruko Aug 18, 2024
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
364 changes: 228 additions & 136 deletions Processor/ProcessC2CMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,158 +182,250 @@ func (p *Processors) ProcessC2CMessage(data *dto.WSC2CMessageData) error {
idmap.StoreUserInfo(data.Author.ID, userdata)
} else {
//将私聊信息转化为群信息(特殊需求情况下)
if !config.GetStringOb11() {
//转换appid
AppIDString := strconv.FormatUint(p.Settings.AppID, 10)
// 获取当前时间的13位毫秒级时间戳
currentTimeMillis := time.Now().UnixNano() / 1e6
// 构造echostr,包括AppID,原始的s变量和当前时间戳
echostr := fmt.Sprintf("%s_%d_%d", AppIDString, s, currentTimeMillis)
//把userid作为群号
//映射str的userid到int
var userid64 int64
var err error
var magic int64
if config.GetIdmapPro() {
//将真实id转为int userid64
magic, userid64, err = idmap.StoreIDv2Pro("group_private", data.Author.ID)
mylog.Printf("魔法数字:%v", magic) //690426430
if err != nil {
mylog.Fatalf("Error storing ID: %v", err)
}
//当参数不全,降级时
_, _ = idmap.StoreIDv2(data.Author.ID)
//补救措施
idmap.SimplifiedStoreID(data.Author.ID)
} else {
//将真实id转为int userid64
userid64, err = idmap.StoreIDv2(data.Author.ID)
if err != nil {
mylog.Fatalf("Error storing ID: %v", err)
}
}
//转换at
messageText := handlers.RevertTransformedText(data, "group_private", p.Api, p.Apiv2, userid64, userid64, config.GetWhiteEnable(5))
if messageText == "" {
mylog.Printf("信息被自定义黑白名单拦截")
return nil
}
//框架内指令
p.HandleFrameworkCommand(messageText, data, "group_private")
//映射str的messageID到int
var messageID64 int64
if config.GetMemoryMsgid() {
messageID64, err = echo.StoreCacheInMemory(data.ID)
if err != nil {
log.Fatalf("Error storing ID: %v", err)
}
} else {
messageID64, err = idmap.StoreCachev2(data.ID)
if err != nil {
log.Fatalf("Error storing ID: %v", err)
}
}
messageID := int(messageID64)
//todo 判断array模式 然后对Message处理成array格式
IsBindedUserId := idmap.CheckValue(data.Author.ID, userid64)

//转换appid
AppIDString := strconv.FormatUint(p.Settings.AppID, 10)
// 获取当前时间的13位毫秒级时间戳
currentTimeMillis := time.Now().UnixNano() / 1e6
// 构造echostr,包括AppID,原始的s变量和当前时间戳
echostr := fmt.Sprintf("%s_%d_%d", AppIDString, s, currentTimeMillis)
//把userid作为群号
//映射str的userid到int
var userid64 int64
var err error
var magic int64
if config.GetIdmapPro() {
//将真实id转为int userid64
magic, userid64, err = idmap.StoreIDv2Pro("group_private", data.Author.ID)
mylog.Printf("魔法数字:%v", magic) //690426430
if err != nil {
mylog.Fatalf("Error storing ID: %v", err)
var selfid64 int64
if config.GetUseUin() {
selfid64 = config.GetUinint64()
} else {
selfid64 = int64(p.Settings.AppID)
}
//当参数不全,降级时
_, _ = idmap.StoreIDv2(data.Author.ID)
//补救措施
idmap.SimplifiedStoreID(data.Author.ID)
} else {
//将真实id转为int userid64
userid64, err = idmap.StoreIDv2(data.Author.ID)
if err != nil {
mylog.Fatalf("Error storing ID: %v", err)

groupMsg := OnebotGroupMessage{
RawMessage: messageText,
Message: messageText,
MessageID: messageID,
GroupID: userid64,
MessageType: "group",
PostType: "message",
SelfID: selfid64,
UserID: userid64,
Sender: Sender{
UserID: userid64,
TinyID: "0",
Sex: "0",
Age: 0,
Area: "0",
Level: "0",
},
SubType: "normal",
Time: time.Now().Unix(),
}
}
//转换at
messageText := handlers.RevertTransformedText(data, "group_private", p.Api, p.Apiv2, userid64, userid64, config.GetWhiteEnable(5))
if messageText == "" {
mylog.Printf("信息被自定义黑白名单拦截")
return nil
}
//框架内指令
p.HandleFrameworkCommand(messageText, data, "group_private")
//映射str的messageID到int
var messageID64 int64
if config.GetMemoryMsgid() {
messageID64, err = echo.StoreCacheInMemory(data.ID)
if err != nil {
log.Fatalf("Error storing ID: %v", err)
//增强配置
if !config.GetNativeOb11() {
groupMsg.RealMessageType = "group_private"
groupMsg.IsBindedUserId = IsBindedUserId
groupMsg.RealUserID = data.Author.ID
groupMsg.Avatar, _ = GenerateAvatarURLV2(data.Author.ID)
}
} else {
messageID64, err = idmap.StoreCachev2(data.ID)
if err != nil {
log.Fatalf("Error storing ID: %v", err)
//根据条件判断是否增加nick和card
var CaN = config.GetCardAndNick()
if CaN != "" {
groupMsg.Sender.Nickname = CaN
groupMsg.Sender.Card = CaN
}
}
messageID := int(messageID64)
//todo 判断array模式 然后对Message处理成array格式
IsBindedUserId := idmap.CheckValue(data.Author.ID, userid64)
// 根据条件判断是否添加Echo字段
if config.GetTwoWayEcho() {
groupMsg.Echo = echostr
//用向应用端(如果支持)发送echo,来确定客户端的send_msg对应的触发词原文
echo.AddMsgIDv3(AppIDString, echostr, messageText)
}
// 获取MasterID数组
masterIDs := config.GetMasterID()

var selfid64 int64
if config.GetUseUin() {
selfid64 = config.GetUinint64()
} else {
selfid64 = int64(p.Settings.AppID)
}
// 判断userid64是否在masterIDs数组里
isMaster := false
for _, id := range masterIDs {
if strconv.FormatInt(userid64, 10) == id {
isMaster = true
break
}
}

groupMsg := OnebotGroupMessage{
RawMessage: messageText,
Message: messageText,
MessageID: messageID,
GroupID: userid64,
MessageType: "group",
PostType: "message",
SelfID: selfid64,
UserID: userid64,
Sender: Sender{
UserID: userid64,
TinyID: "0",
Sex: "0",
Age: 0,
Area: "0",
Level: "0",
},
SubType: "normal",
Time: time.Now().Unix(),
}
//增强配置
if !config.GetNativeOb11() {
groupMsg.RealMessageType = "group_private"
groupMsg.IsBindedUserId = IsBindedUserId
groupMsg.RealUserID = data.Author.ID
groupMsg.Avatar, _ = GenerateAvatarURLV2(data.Author.ID)
}
//根据条件判断是否增加nick和card
var CaN = config.GetCardAndNick()
if CaN != "" {
groupMsg.Sender.Nickname = CaN
groupMsg.Sender.Card = CaN
}
// 根据条件判断是否添加Echo字段
if config.GetTwoWayEcho() {
groupMsg.Echo = echostr
//用向应用端(如果支持)发送echo,来确定客户端的send_msg对应的触发词原文
echo.AddMsgIDv3(AppIDString, echostr, messageText)
}
// 获取MasterID数组
masterIDs := config.GetMasterID()

// 判断userid64是否在masterIDs数组里
isMaster := false
for _, id := range masterIDs {
if strconv.FormatInt(userid64, 10) == id {
isMaster = true
break
// 根据isMaster的值为groupMsg的Sender赋值role字段
if isMaster {
groupMsg.Sender.Role = "owner"
} else {
groupMsg.Sender.Role = "member"
}
}
//将当前s和appid和message进行映射
echo.AddMsgID(AppIDString, s, data.ID)
echo.AddMsgType(AppIDString, s, "group_private")
//为不支持双向echo的ob服务端映射
echo.AddMsgID(AppIDString, userid64, data.ID)
//映射类型
echo.AddMsgType(AppIDString, userid64, "group_private")
//储存当前群或频道号的类型
idmap.WriteConfigv2(fmt.Sprint(userid64), "type", "group_private")

//懒message_id池
echo.AddLazyMessageId(strconv.FormatInt(userid64, 10), data.ID, time.Now())

// 根据isMaster的值为groupMsg的Sender赋值role字段
if isMaster {
groupMsg.Sender.Role = "owner"
//懒message_id池
echo.AddLazyMessageId(data.Author.ID, data.ID, time.Now())

//调试
PrintStructWithFieldNames(groupMsg)

// Convert OnebotGroupMessage to map and send
groupMsgMap := structToMap(groupMsg)
//上报信息到onebotv11应用端(正反ws)
go p.BroadcastMessageToAll(groupMsgMap, p.Apiv2, data)

//组合FriendData
struserid := strconv.FormatInt(userid64, 10)
userdata := structs.FriendData{
Nickname: "",
Remark: "",
UserID: struserid,
}
//缓存私信好友列表
idmap.StoreUserInfo(data.Author.ID, userdata)
} else {
groupMsg.Sender.Role = "member"
}
//将当前s和appid和message进行映射
echo.AddMsgID(AppIDString, s, data.ID)
echo.AddMsgType(AppIDString, s, "group_private")
//为不支持双向echo的ob服务端映射
echo.AddMsgID(AppIDString, userid64, data.ID)
//映射类型
echo.AddMsgType(AppIDString, userid64, "group_private")
//储存当前群或频道号的类型
idmap.WriteConfigv2(fmt.Sprint(userid64), "type", "group_private")
//转换appid
AppIDString := strconv.FormatUint(p.Settings.AppID, 10)
// 获取当前时间的13位毫秒级时间戳
currentTimeMillis := time.Now().UnixNano() / 1e6
// 构造echostr,包括AppID,原始的s变量和当前时间戳
echostr := fmt.Sprintf("%s_%d_%d", AppIDString, s, currentTimeMillis)

//懒message_id池
echo.AddLazyMessageId(strconv.FormatInt(userid64, 10), data.ID, time.Now())
var selfid64 int64
if config.GetUseUin() {
selfid64 = config.GetUinint64()
} else {
selfid64 = int64(p.Settings.AppID)
}

//懒message_id池
echo.AddLazyMessageId(data.Author.ID, data.ID, time.Now())
//转换at
messageText := handlers.RevertTransformedText(data, "group_private", p.Api, p.Apiv2, 0, 0, config.GetWhiteEnable(5))
if messageText == "" {
mylog.Printf("信息被自定义黑白名单拦截")
return nil
}

//调试
PrintStructWithFieldNames(groupMsg)
groupMsg := OnebotGroupMessageS{
RawMessage: messageText,
Message: messageText,
MessageID: data.ID,
GroupID: data.Author.ID,
MessageType: "group",
PostType: "message",
SelfID: selfid64,
UserID: data.Author.ID,
Sender: Sender{
UserID: 0,
TinyID: "0",
Sex: "0",
Age: 0,
Area: "0",
Level: "0",
},
SubType: "normal",
Time: time.Now().Unix(),
}

// Convert OnebotGroupMessage to map and send
groupMsgMap := structToMap(groupMsg)
//上报信息到onebotv11应用端(正反ws)
go p.BroadcastMessageToAll(groupMsgMap, p.Apiv2, data)
//增强配置
if !config.GetNativeOb11() {
groupMsg.RealMessageType = "group_private"
groupMsg.RealUserID = data.Author.ID
groupMsg.Avatar, _ = GenerateAvatarURLV2(data.Author.ID)
}
//根据条件判断是否增加nick和card
var CaN = config.GetCardAndNick()
if CaN != "" {
groupMsg.Sender.Nickname = CaN
groupMsg.Sender.Card = CaN
}

//组合FriendData
struserid := strconv.FormatInt(userid64, 10)
userdata := structs.FriendData{
Nickname: "",
Remark: "",
UserID: struserid,
// 根据条件判断是否添加Echo字段
if config.GetTwoWayEcho() {
groupMsg.Echo = echostr
// 用向应用端(如果支持)发送echo,来确定客户端的send_msg对应的触发词原文
echo.AddMsgIDv3(AppIDString, echostr, data.Content)
}

//将当前s和appid和message进行映射
echo.AddMsgID(AppIDString, s, data.ID)
echo.AddMsgType(AppIDString, s, "group_private")

echo.AddMsgIDv3(AppIDString, data.Author.ID, data.ID)

//储存当前群或频道号的类型
idmap.WriteConfigv2(data.Author.ID, "type", "group_private")

//懒message_id池
echo.AddLazyMessageId(data.Author.ID, data.ID, time.Now())

//调试
PrintStructWithFieldNames(groupMsg)

// Convert OnebotGroupMessage to map and send
groupMsgMap := structToMap(groupMsg)
//上报信息到onebotv11应用端(正反ws)
go p.BroadcastMessageToAll(groupMsgMap, p.Apiv2, data)

//组合FriendData
userdata := structs.FriendData{
Nickname: "",
Remark: "",
UserID: data.Author.ID,
}
//缓存私信好友列表
idmap.StoreUserInfo(data.Author.ID, userdata)
}
//缓存私信好友列表
idmap.StoreUserInfo(data.Author.ID, userdata)
}

return nil
Expand Down
Loading
Loading