Skip to content

Commit

Permalink
Beta482 (#488)
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

* beta471

* beta472

* beta473

* beta473

* beta475

* beta476

* beta478

* beta479

* beta479

* beta480

* beta481

* beta482
  • Loading branch information
Hoshinonyaruko authored Aug 18, 2024
1 parent 09741aa commit 2561d65
Show file tree
Hide file tree
Showing 4 changed files with 420 additions and 177 deletions.
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

0 comments on commit 2561d65

Please sign in to comment.