From c49f9def30fda40a6495539e9de8dff2cf9020e1 Mon Sep 17 00:00:00 2001 From: cosmo Date: Tue, 7 May 2024 18:51:04 +0800 Subject: [PATCH 01/20] beta399 --- protobufc2c/c2cpic.pb.go | 370 --------------------------------------- 1 file changed, 370 deletions(-) delete mode 100644 protobufc2c/c2cpic.pb.go diff --git a/protobufc2c/c2cpic.pb.go b/protobufc2c/c2cpic.pb.go deleted file mode 100644 index 9665e465..00000000 --- a/protobufc2c/c2cpic.pb.go +++ /dev/null @@ -1,370 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.32.0 -// protoc v4.25.3 -// source: c2cpic.proto - -package protobufc2c - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -// 定义一个Proto消息结构来解析特定的嵌套数据 -type ImageData struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // 实例化Level1消息 - NestedData *ImageData_Level1 `protobuf:"bytes,1,opt,name=nestedData,proto3" json:"nestedData,omitempty"` -} - -func (x *ImageData) Reset() { - *x = ImageData{} - if protoimpl.UnsafeEnabled { - mi := &file_c2cpic_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ImageData) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ImageData) ProtoMessage() {} - -func (x *ImageData) ProtoReflect() protoreflect.Message { - mi := &file_c2cpic_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ImageData.ProtoReflect.Descriptor instead. -func (*ImageData) Descriptor() ([]byte, []int) { - return file_c2cpic_proto_rawDescGZIP(), []int{0} -} - -func (x *ImageData) GetNestedData() *ImageData_Level1 { - if x != nil { - return x.NestedData - } - return nil -} - -// 内嵌消息定义为一级字段1的结构 -type ImageData_Level1 struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // 实例化Level3消息 - Details *ImageData_Level1_Level3 `protobuf:"bytes,3,opt,name=details,proto3" json:"details,omitempty"` -} - -func (x *ImageData_Level1) Reset() { - *x = ImageData_Level1{} - if protoimpl.UnsafeEnabled { - mi := &file_c2cpic_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ImageData_Level1) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ImageData_Level1) ProtoMessage() {} - -func (x *ImageData_Level1) ProtoReflect() protoreflect.Message { - mi := &file_c2cpic_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ImageData_Level1.ProtoReflect.Descriptor instead. -func (*ImageData_Level1) Descriptor() ([]byte, []int) { - return file_c2cpic_proto_rawDescGZIP(), []int{0, 0} -} - -func (x *ImageData_Level1) GetDetails() *ImageData_Level1_Level3 { - if x != nil { - return x.Details - } - return nil -} - -// 内嵌消息定义为二级字段3的结构 -type ImageData_Level1_Level3 struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // 可选字段,解析图片宽度 - Width int32 `protobuf:"varint,8,opt,name=width,proto3" json:"width,omitempty"` - // 可选字段,解析图片高度 - Height int32 `protobuf:"varint,9,opt,name=height,proto3" json:"height,omitempty"` - // 实例化Level29消息 - Urls *ImageData_Level1_Level3_Level29 `protobuf:"bytes,29,opt,name=urls,proto3" json:"urls,omitempty"` -} - -func (x *ImageData_Level1_Level3) Reset() { - *x = ImageData_Level1_Level3{} - if protoimpl.UnsafeEnabled { - mi := &file_c2cpic_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ImageData_Level1_Level3) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ImageData_Level1_Level3) ProtoMessage() {} - -func (x *ImageData_Level1_Level3) ProtoReflect() protoreflect.Message { - mi := &file_c2cpic_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ImageData_Level1_Level3.ProtoReflect.Descriptor instead. -func (*ImageData_Level1_Level3) Descriptor() ([]byte, []int) { - return file_c2cpic_proto_rawDescGZIP(), []int{0, 0, 0} -} - -func (x *ImageData_Level1_Level3) GetWidth() int32 { - if x != nil { - return x.Width - } - return 0 -} - -func (x *ImageData_Level1_Level3) GetHeight() int32 { - if x != nil { - return x.Height - } - return 0 -} - -func (x *ImageData_Level1_Level3) GetUrls() *ImageData_Level1_Level3_Level29 { - if x != nil { - return x.Urls - } - return nil -} - -// 内嵌消息定义为三级字段29的结构 -type ImageData_Level1_Level3_Level29 struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // 可选字段,解析图片URL - Url string `protobuf:"bytes,30,opt,name=url,proto3" json:"url,omitempty"` -} - -func (x *ImageData_Level1_Level3_Level29) Reset() { - *x = ImageData_Level1_Level3_Level29{} - if protoimpl.UnsafeEnabled { - mi := &file_c2cpic_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ImageData_Level1_Level3_Level29) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ImageData_Level1_Level3_Level29) ProtoMessage() {} - -func (x *ImageData_Level1_Level3_Level29) ProtoReflect() protoreflect.Message { - mi := &file_c2cpic_proto_msgTypes[3] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ImageData_Level1_Level3_Level29.ProtoReflect.Descriptor instead. -func (*ImageData_Level1_Level3_Level29) Descriptor() ([]byte, []int) { - return file_c2cpic_proto_rawDescGZIP(), []int{0, 0, 0, 0} -} - -func (x *ImageData_Level1_Level3_Level29) GetUrl() string { - if x != nil { - return x.Url - } - return "" -} - -var File_c2cpic_proto protoreflect.FileDescriptor - -var file_c2cpic_proto_rawDesc = []byte{ - 0x0a, 0x0c, 0x63, 0x32, 0x63, 0x70, 0x69, 0x63, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0b, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x63, 0x32, 0x63, 0x22, 0xad, 0x02, 0x0a, 0x09, - 0x49, 0x6d, 0x61, 0x67, 0x65, 0x44, 0x61, 0x74, 0x61, 0x12, 0x3d, 0x0a, 0x0a, 0x6e, 0x65, 0x73, - 0x74, 0x65, 0x64, 0x44, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x63, 0x32, 0x63, 0x2e, 0x49, 0x6d, 0x61, 0x67, - 0x65, 0x44, 0x61, 0x74, 0x61, 0x2e, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x31, 0x52, 0x0a, 0x6e, 0x65, - 0x73, 0x74, 0x65, 0x64, 0x44, 0x61, 0x74, 0x61, 0x1a, 0xe0, 0x01, 0x0a, 0x06, 0x4c, 0x65, 0x76, - 0x65, 0x6c, 0x31, 0x12, 0x3e, 0x0a, 0x07, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x18, 0x03, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x63, - 0x32, 0x63, 0x2e, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x44, 0x61, 0x74, 0x61, 0x2e, 0x4c, 0x65, 0x76, - 0x65, 0x6c, 0x31, 0x2e, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x33, 0x52, 0x07, 0x64, 0x65, 0x74, 0x61, - 0x69, 0x6c, 0x73, 0x1a, 0x95, 0x01, 0x0a, 0x06, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x33, 0x12, 0x14, - 0x0a, 0x05, 0x77, 0x69, 0x64, 0x74, 0x68, 0x18, 0x08, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x77, - 0x69, 0x64, 0x74, 0x68, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x09, - 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, 0x40, 0x0a, 0x04, - 0x75, 0x72, 0x6c, 0x73, 0x18, 0x1d, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2c, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x62, 0x75, 0x66, 0x63, 0x32, 0x63, 0x2e, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x44, 0x61, - 0x74, 0x61, 0x2e, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x31, 0x2e, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x33, - 0x2e, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x32, 0x39, 0x52, 0x04, 0x75, 0x72, 0x6c, 0x73, 0x1a, 0x1b, - 0x0a, 0x07, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x32, 0x39, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, - 0x18, 0x1e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x42, 0x30, 0x5a, 0x2e, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x6f, 0x73, 0x68, 0x69, 0x6e, - 0x6f, 0x6e, 0x79, 0x61, 0x72, 0x75, 0x6b, 0x6f, 0x2f, 0x67, 0x65, 0x6e, 0x73, 0x6f, 0x6b, 0x79, - 0x6f, 0x3b, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x63, 0x32, 0x63, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_c2cpic_proto_rawDescOnce sync.Once - file_c2cpic_proto_rawDescData = file_c2cpic_proto_rawDesc -) - -func file_c2cpic_proto_rawDescGZIP() []byte { - file_c2cpic_proto_rawDescOnce.Do(func() { - file_c2cpic_proto_rawDescData = protoimpl.X.CompressGZIP(file_c2cpic_proto_rawDescData) - }) - return file_c2cpic_proto_rawDescData -} - -var file_c2cpic_proto_msgTypes = make([]protoimpl.MessageInfo, 4) -var file_c2cpic_proto_goTypes = []interface{}{ - (*ImageData)(nil), // 0: protobufc2c.ImageData - (*ImageData_Level1)(nil), // 1: protobufc2c.ImageData.Level1 - (*ImageData_Level1_Level3)(nil), // 2: protobufc2c.ImageData.Level1.Level3 - (*ImageData_Level1_Level3_Level29)(nil), // 3: protobufc2c.ImageData.Level1.Level3.Level29 -} -var file_c2cpic_proto_depIdxs = []int32{ - 1, // 0: protobufc2c.ImageData.nestedData:type_name -> protobufc2c.ImageData.Level1 - 2, // 1: protobufc2c.ImageData.Level1.details:type_name -> protobufc2c.ImageData.Level1.Level3 - 3, // 2: protobufc2c.ImageData.Level1.Level3.urls:type_name -> protobufc2c.ImageData.Level1.Level3.Level29 - 3, // [3:3] is the sub-list for method output_type - 3, // [3:3] is the sub-list for method input_type - 3, // [3:3] is the sub-list for extension type_name - 3, // [3:3] is the sub-list for extension extendee - 0, // [0:3] is the sub-list for field type_name -} - -func init() { file_c2cpic_proto_init() } -func file_c2cpic_proto_init() { - if File_c2cpic_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_c2cpic_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ImageData); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_c2cpic_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ImageData_Level1); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_c2cpic_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ImageData_Level1_Level3); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_c2cpic_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ImageData_Level1_Level3_Level29); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_c2cpic_proto_rawDesc, - NumEnums: 0, - NumMessages: 4, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_c2cpic_proto_goTypes, - DependencyIndexes: file_c2cpic_proto_depIdxs, - MessageInfos: file_c2cpic_proto_msgTypes, - }.Build() - File_c2cpic_proto = out.File - file_c2cpic_proto_rawDesc = nil - file_c2cpic_proto_goTypes = nil - file_c2cpic_proto_depIdxs = nil -} From 9aa4f7815559918e25ac0bb84a46085bcd15e629 Mon Sep 17 00:00:00 2001 From: cosmo Date: Thu, 9 May 2024 15:57:37 +0800 Subject: [PATCH 02/20] beta400 --- Processor/ProcessGroupAddBot.go | 4 +- Processor/ProcessGroupMsgReceive.go | 232 +++++++++++++++++++++++++++ Processor/ProcessGroupMsgReject.go | 233 ++++++++++++++++++++++++++++ Processor/ProcessInlineSearch.go | 60 ++++--- Processor/Processor.go | 24 +++ botgo/dto/forum.go | 3 +- botgo/dto/interaction.go | 1 + botgo/dto/message.go | 15 ++ botgo/dto/websocket_event.go | 2 + botgo/event/event.go | 52 ++++++- botgo/event/register.go | 20 ++- config/config.go | 32 ++++ handlers/send_msg.go | 5 +- main.go | 22 ++- structs/structs.go | 15 +- template/config_template.go | 5 +- 16 files changed, 681 insertions(+), 44 deletions(-) create mode 100644 Processor/ProcessGroupMsgReceive.go create mode 100644 Processor/ProcessGroupMsgReject.go diff --git a/Processor/ProcessGroupAddBot.go b/Processor/ProcessGroupAddBot.go index 96d96a87..973af06e 100644 --- a/Processor/ProcessGroupAddBot.go +++ b/Processor/ProcessGroupAddBot.go @@ -135,9 +135,9 @@ func (p *Processors) ProcessGroupAddBot(data *dto.GroupAddBotEvent) error { AppIDString := strconv.FormatUint(p.Settings.AppID, 10) // 储存和群号相关的eventid - echo.AddEvnetID(AppIDString, GroupID64, data.ID) + echo.AddEvnetID(AppIDString, GroupID64, data.EventID) - mylog.Printf("Bot被[%v]邀请进入群[%v]eventid[%v]", userid64, GroupID64, data.ID) + mylog.Printf("Bot被[%v]邀请进入群[%v]eventid[%v]", userid64, GroupID64, data.EventID) // 调用GetSelfIntroduce函数 intros := config.GetSelfIntroduce() diff --git a/Processor/ProcessGroupMsgReceive.go b/Processor/ProcessGroupMsgReceive.go new file mode 100644 index 00000000..b1c6425c --- /dev/null +++ b/Processor/ProcessGroupMsgReceive.go @@ -0,0 +1,232 @@ +// 处理收到的回调事件 +package Processor + +import ( + "fmt" + "strconv" + "time" + + "github.com/hoshinonyaruko/gensokyo/config" + "github.com/hoshinonyaruko/gensokyo/echo" + "github.com/hoshinonyaruko/gensokyo/handlers" + "github.com/hoshinonyaruko/gensokyo/idmap" + "github.com/hoshinonyaruko/gensokyo/mylog" + "github.com/tencent-connect/botgo/dto" + "github.com/tencent-connect/botgo/websocket/client" +) + +// ProcessInlineSearch 处理内联查询 +func (p *Processors) ProcessGroupMsgRecive(data *dto.GroupMsgReceiveEvent) error { + // 转换appid + var userid64 int64 + var GroupID64 int64 + var LongGroupID64 int64 + var err error + var fromgid, fromuid string + if data.GroupOpenID != "" { + fromgid = data.GroupOpenID + fromuid = data.OpMemberOpenID + } + + // 获取s + s := client.GetGlobalS() + // 转换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) + + if config.GetIdmapPro() { + //将真实id转为int userid64 + GroupID64, userid64, err = idmap.StoreIDv2Pro(fromgid, fromuid) + if err != nil { + mylog.Fatalf("Error storing ID: %v", err) + } + + // 当哈希碰撞 因为获取时候是用的非idmap的get函数 + LongGroupID64, _ = idmap.StoreIDv2(fromgid) + _, _ = idmap.StoreIDv2(fromuid) + if !config.GetHashIDValue() { + mylog.Fatalf("避坑日志:你开启了高级id转换,请设置hash_id为true,并且删除idmaps并重启") + } + } else { + // 映射str的GroupID到int + GroupID64, err = idmap.StoreIDv2(fromgid) + if err != nil { + mylog.Errorf("failed to convert ChannelID to int: %v", err) + return nil + } + // 映射str的userid到int + userid64, err = idmap.StoreIDv2(fromuid) + if err != nil { + mylog.Printf("Error storing ID: %v", err) + return nil + } + } + var selfid64 int64 + if config.GetUseUin() { + selfid64 = config.GetUinint64() + } else { + selfid64 = int64(p.Settings.AppID) + } + + if !config.GetGlobalGroupMsgRejectReciveEventToMessage() { + notice := &OnebotGroupReceiveNotice{ + GroupID: GroupID64, + NoticeType: "interaction", + PostType: "notice", + SelfID: selfid64, + SubType: "create", + Time: time.Now().Unix(), + UserID: userid64, + Data: data, + } + //调试 + PrintStructWithFieldNames(notice) + + // Convert OnebotGroupMessage to map and send + noticeMap := structToMap(notice) + + //上报信息到onebotv11应用端(正反ws) + p.BroadcastMessageToAll(noticeMap) + + // 转换appid + AppIDString := strconv.FormatUint(p.Settings.AppID, 10) + + // 储存和群号相关的eventid + // idmap-pro的设计其实是有问题的,和idmap冲突,并且也还是会哈希碰撞 需要用一个不会碰撞的id去存 + echo.AddEvnetID(AppIDString, LongGroupID64, data.EventID) + } else { + if data.GroupOpenID != "" { + //群回调 + newdata := ConvertReceiveToMessage(data) + //mylog.Printf("回调测试111-newdata:%v\n", newdata) + + // 如果在Array模式下, 则处理Message为Segment格式 + var segmentedMessages interface{} = newdata.Content + if config.GetArrayValue() { + segmentedMessages = handlers.ConvertToSegmentedMessage(newdata) + } + + var IsBindedUserId, IsBindedGroupId bool + if config.GetHashIDValue() { + IsBindedUserId = idmap.CheckValue(data.OpMemberOpenID, userid64) + IsBindedGroupId = idmap.CheckValue(data.GroupOpenID, GroupID64) + } else { + IsBindedUserId = idmap.CheckValuev2(userid64) + IsBindedGroupId = idmap.CheckValuev2(GroupID64) + } + //平台事件,不是真实信息,无需messageID + messageID64 := 123 + messageID := int(messageID64) + var selfid64 int64 + if config.GetUseUin() { + selfid64 = config.GetUinint64() + } else { + selfid64 = int64(p.Settings.AppID) + } + //mylog.Printf("回调测试-interaction:%v\n", segmentedMessages) + groupMsg := OnebotGroupMessage{ + RawMessage: newdata.Content, + Message: segmentedMessages, + MessageID: messageID, + GroupID: GroupID64, + MessageType: "group", + PostType: "message", + SelfID: selfid64, + UserID: userid64, + Sender: Sender{ + UserID: userid64, + Sex: "0", + Age: 0, + Area: "0", + Level: "0", + }, + SubType: "normal", + Time: time.Now().Unix(), + } + //增强配置 + if !config.GetNativeOb11() { + groupMsg.RealMessageType = "interaction" + groupMsg.IsBindedUserId = IsBindedUserId + groupMsg.IsBindedGroupId = IsBindedGroupId + groupMsg.RealGroupID = data.GroupOpenID + groupMsg.RealUserID = data.OpMemberOpenID + groupMsg.Avatar, _ = GenerateAvatarURLV2(data.OpMemberOpenID) + } + //根据条件判断是否增加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, newdata.Content) + } + // 获取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" + } + + // 映射消息类型 + echo.AddMsgType(AppIDString, s, "group") + + //储存当前群或频道号的类型 + idmap.WriteConfigv2(fmt.Sprint(GroupID64), "type", "group") + + //映射类型 + echo.AddMsgType(AppIDString, GroupID64, "group") + + // 调试 + PrintStructWithFieldNames(groupMsg) + + // Convert OnebotGroupMessage to map and send + groupMsgMap := structToMap(groupMsg) + //上报信息到onebotv11应用端(正反ws) + p.BroadcastMessageToAll(groupMsgMap) + + // 转换appid + AppIDString := strconv.FormatUint(p.Settings.AppID, 10) + + // 储存和群号相关的eventid + fmt.Printf("测试:储存eventid:[%v]LongGroupID64[%v]\n", data.EventID, LongGroupID64) + echo.AddEvnetID(AppIDString, LongGroupID64, data.EventID) + } + } + + return nil +} + +// ConvertReceiveToMessage 转换 Receive 到 Message +func ConvertReceiveToMessage(r *dto.GroupMsgReceiveEvent) *dto.Message { + var message dto.Message + + // 直接映射的字段 + message.GroupID = r.GroupOpenID + + // 特殊处理的字段 + message.Content = config.GetGlobalGroupMsgReceiveMessage() + message.DirectMessage = false + + return &message +} diff --git a/Processor/ProcessGroupMsgReject.go b/Processor/ProcessGroupMsgReject.go new file mode 100644 index 00000000..e222152c --- /dev/null +++ b/Processor/ProcessGroupMsgReject.go @@ -0,0 +1,233 @@ +// 处理收到的回调事件 +package Processor + +import ( + "fmt" + "strconv" + "time" + + "github.com/hoshinonyaruko/gensokyo/config" + "github.com/hoshinonyaruko/gensokyo/echo" + "github.com/hoshinonyaruko/gensokyo/handlers" + "github.com/hoshinonyaruko/gensokyo/idmap" + "github.com/hoshinonyaruko/gensokyo/mylog" + "github.com/tencent-connect/botgo/dto" + "github.com/tencent-connect/botgo/websocket/client" +) + +// ProcessGroupMsgReject 处理群关闭机器人推送 +func (p *Processors) ProcessGroupMsgReject(data *dto.GroupMsgRejectEvent) error { + // 转换appid + var userid64 int64 + var GroupID64 int64 + var LongGroupID64 int64 + var err error + var fromgid, fromuid string + if data.GroupOpenID != "" { + fromgid = data.GroupOpenID + fromuid = data.OpMemberOpenID + } + + // 获取s + s := client.GetGlobalS() + // 转换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) + + fmt.Printf("快乐测试[%v][%v]\n", fromgid, fromuid) + + if config.GetIdmapPro() { + //将真实id转为int userid64 + GroupID64, userid64, err = idmap.StoreIDv2Pro(fromgid, fromuid) + if err != nil { + mylog.Fatalf("Error storing ID: %v", err) + } + // 当哈希碰撞 因为获取时候是用的非idmap的get函数 + LongGroupID64, _ = idmap.StoreIDv2(fromgid) + _, _ = idmap.StoreIDv2(fromuid) + if !config.GetHashIDValue() { + mylog.Fatalf("避坑日志:你开启了高级id转换,请设置hash_id为true,并且删除idmaps并重启") + } + } else { + // 映射str的GroupID到int + GroupID64, err = idmap.StoreIDv2(fromgid) + if err != nil { + mylog.Errorf("failed to convert ChannelID to int: %v", err) + return nil + } + // 映射str的userid到int + userid64, err = idmap.StoreIDv2(fromuid) + if err != nil { + mylog.Printf("Error storing ID: %v", err) + return nil + } + } + var selfid64 int64 + if config.GetUseUin() { + selfid64 = config.GetUinint64() + } else { + selfid64 = int64(p.Settings.AppID) + } + + if !config.GetGlobalGroupMsgRejectReciveEventToMessage() { + notice := &OnebotGroupRejectNotice{ + GroupID: GroupID64, + NoticeType: "interaction", + PostType: "notice", + SelfID: selfid64, + SubType: "create", + Time: time.Now().Unix(), + UserID: userid64, + Data: data, + } + //调试 + PrintStructWithFieldNames(notice) + + // Convert OnebotGroupMessage to map and send + noticeMap := structToMap(notice) + + //上报信息到onebotv11应用端(正反ws) + p.BroadcastMessageToAll(noticeMap) + + // 转换appid + AppIDString := strconv.FormatUint(p.Settings.AppID, 10) + + // 储存和群号相关的eventid + // idmap-pro的设计其实是有问题的,和idmap冲突,并且也还是会哈希碰撞 需要用一个不会碰撞的id去存 + echo.AddEvnetID(AppIDString, LongGroupID64, data.EventID) + } else { + if data.GroupOpenID != "" { + //群回调 + newdata := ConvertRejectToMessage(data) + //mylog.Printf("回调测试111-newdata:%v\n", newdata) + + // 如果在Array模式下, 则处理Message为Segment格式 + var segmentedMessages interface{} = newdata.Content + if config.GetArrayValue() { + segmentedMessages = handlers.ConvertToSegmentedMessage(newdata) + } + + var IsBindedUserId, IsBindedGroupId bool + if config.GetHashIDValue() { + IsBindedUserId = idmap.CheckValue(data.OpMemberOpenID, userid64) + IsBindedGroupId = idmap.CheckValue(data.GroupOpenID, GroupID64) + } else { + IsBindedUserId = idmap.CheckValuev2(userid64) + IsBindedGroupId = idmap.CheckValuev2(GroupID64) + } + //平台事件,不是真实信息,无需messageID + messageID64 := 123 + messageID := int(messageID64) + var selfid64 int64 + if config.GetUseUin() { + selfid64 = config.GetUinint64() + } else { + selfid64 = int64(p.Settings.AppID) + } + //mylog.Printf("回调测试-interaction:%v\n", segmentedMessages) + groupMsg := OnebotGroupMessage{ + RawMessage: newdata.Content, + Message: segmentedMessages, + MessageID: messageID, + GroupID: GroupID64, + MessageType: "group", + PostType: "message", + SelfID: selfid64, + UserID: userid64, + Sender: Sender{ + UserID: userid64, + Sex: "0", + Age: 0, + Area: "0", + Level: "0", + }, + SubType: "normal", + Time: time.Now().Unix(), + } + //增强配置 + if !config.GetNativeOb11() { + groupMsg.RealMessageType = "interaction" + groupMsg.IsBindedUserId = IsBindedUserId + groupMsg.IsBindedGroupId = IsBindedGroupId + groupMsg.RealGroupID = data.GroupOpenID + groupMsg.RealUserID = data.OpMemberOpenID + groupMsg.Avatar, _ = GenerateAvatarURLV2(data.OpMemberOpenID) + } + //根据条件判断是否增加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, newdata.Content) + } + // 获取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" + } + + // 映射消息类型 + echo.AddMsgType(AppIDString, s, "group") + + //储存当前群或频道号的类型 + idmap.WriteConfigv2(fmt.Sprint(GroupID64), "type", "group") + + //映射类型 + echo.AddMsgType(AppIDString, GroupID64, "group") + + // 调试 + PrintStructWithFieldNames(groupMsg) + + // Convert OnebotGroupMessage to map and send + groupMsgMap := structToMap(groupMsg) + //上报信息到onebotv11应用端(正反ws) + p.BroadcastMessageToAll(groupMsgMap) + + // 转换appid + AppIDString := strconv.FormatUint(p.Settings.AppID, 10) + + // 储存和群号相关的eventid + fmt.Printf("测试:储存eventid:[%v]LongGroupID64[%v]\n", data.EventID, LongGroupID64) + echo.AddEvnetID(AppIDString, LongGroupID64, data.EventID) + } + } + + return nil +} + +// ConvertRejectToMessage 转换 Reject 到 Message +func ConvertRejectToMessage(r *dto.GroupMsgRejectEvent) *dto.Message { + var message dto.Message + + // 直接映射的字段 + message.GroupID = r.GroupOpenID + + // 特殊处理的字段 + message.Content = config.GetGlobalGroupMsgRejectMessage() + message.DirectMessage = false + + return &message +} diff --git a/Processor/ProcessInlineSearch.go b/Processor/ProcessInlineSearch.go index f4574f63..c7a4d867 100644 --- a/Processor/ProcessInlineSearch.go +++ b/Processor/ProcessInlineSearch.go @@ -29,6 +29,8 @@ func (p *Processors) ProcessInlineSearch(data *dto.WSInteractionData) error { // 转换appid var userid64 int64 var GroupID64 int64 + var LongGroupID64 int64 + var LongUserID64 int64 var err error var fromgid, fromuid string if data.GroupOpenID != "" { @@ -60,9 +62,9 @@ func (p *Processors) ProcessInlineSearch(data *dto.WSInteractionData) error { if err != nil { mylog.Fatalf("Error storing ID: %v", err) } - //当参数不全 - _, _ = idmap.StoreIDv2(fromgid) - _, _ = idmap.StoreIDv2(fromuid) + // 当哈希碰撞 因为获取时候是用的非idmap的get函数 + LongGroupID64, _ = idmap.StoreIDv2(fromgid) + LongUserID64, _ = idmap.StoreIDv2(fromuid) if !config.GetHashIDValue() { mylog.Fatalf("避坑日志:你开启了高级id转换,请设置hash_id为true,并且删除idmaps并重启") } @@ -111,13 +113,20 @@ func (p *Processors) ProcessInlineSearch(data *dto.WSInteractionData) error { AppIDString := strconv.FormatUint(p.Settings.AppID, 10) // 储存和群号相关的eventid - echo.AddEvnetID(AppIDString, GroupID64, data.ID) + // idmap-pro的设计其实是有问题的,和idmap冲突,并且也还是会哈希碰撞 需要用一个不会碰撞的id去存 + echo.AddEvnetID(AppIDString, LongGroupID64, data.EventID) } else { if data.GroupOpenID != "" { //群回调 newdata := ConvertInteractionToMessage(data) //mylog.Printf("回调测试111-newdata:%v\n", newdata) - segmentedMessages := handlers.ConvertToSegmentedMessage(newdata) + + // 如果在Array模式下, 则处理Message为Segment格式 + var segmentedMessages interface{} = data.Data.Resolved.ButtonData + if config.GetArrayValue() { + segmentedMessages = handlers.ConvertToSegmentedMessage(newdata) + } + var IsBindedUserId, IsBindedGroupId bool if config.GetHashIDValue() { IsBindedUserId = idmap.CheckValue(data.GroupMemberOpenID, userid64) @@ -126,12 +135,10 @@ func (p *Processors) ProcessInlineSearch(data *dto.WSInteractionData) error { IsBindedUserId = idmap.CheckValuev2(userid64) IsBindedGroupId = idmap.CheckValuev2(GroupID64) } - //映射str的messageID到int - messageID64, err := idmap.StoreIDv2(data.ID) - if err != nil { - mylog.Printf("Error storing ID: %v", err) - return nil - } + + //平台事件,不是真实信息,无需messageID + messageID64 := 123 + messageID := int(messageID64) var selfid64 int64 if config.GetUseUin() { @@ -220,23 +227,28 @@ func (p *Processors) ProcessInlineSearch(data *dto.WSInteractionData) error { AppIDString := strconv.FormatUint(p.Settings.AppID, 10) // 储存和群号相关的eventid - echo.AddEvnetID(AppIDString, GroupID64, data.ID) + fmt.Printf("测试:储存eventid:[%v]LongGroupID64[%v]\n", data.EventID, LongGroupID64) + echo.AddEvnetID(AppIDString, LongGroupID64, data.EventID) } else if data.UserOpenID != "" { //私聊回调 newdata := ConvertInteractionToMessage(data) - segmentedMessages := handlers.ConvertToSegmentedMessage(newdata) + + // 如果在Array模式下, 则处理Message为Segment格式 + var segmentedMessages interface{} = data.Data.Resolved.ButtonData + if config.GetArrayValue() { + segmentedMessages = handlers.ConvertToSegmentedMessage(newdata) + } + var IsBindedUserId bool if config.GetHashIDValue() { IsBindedUserId = idmap.CheckValue(data.UserOpenID, userid64) } else { IsBindedUserId = idmap.CheckValuev2(userid64) } - //映射str的messageID到int - messageID64, err := idmap.StoreIDv2(data.ID) - if err != nil { - mylog.Printf("Error storing ID: %v", err) - return nil - } + + //平台事件,不是真实信息,无需messageID + messageID64 := 123 + messageID := int(messageID64) var selfid64 int64 if config.GetUseUin() { @@ -294,13 +306,19 @@ func (p *Processors) ProcessInlineSearch(data *dto.WSInteractionData) error { AppIDString := strconv.FormatUint(p.Settings.AppID, 10) // 储存和用户ID相关的eventid - echo.AddEvnetID(AppIDString, userid64, data.ID) + echo.AddEvnetID(AppIDString, LongUserID64, data.EventID) } else { // TODO: 区分频道和频道私信 如果有人提需求 // 频道回调 // 处理onebot_channel_message逻辑 newdata := ConvertInteractionToMessage(data) - segmentedMessages := handlers.ConvertToSegmentedMessage(newdata) + + // 如果在Array模式下, 则处理Message为Segment格式 + var segmentedMessages interface{} = data.Data.Resolved.ButtonData + if config.GetArrayValue() { + segmentedMessages = handlers.ConvertToSegmentedMessage(newdata) + } + var selfid64 int64 if config.GetUseUin() { selfid64 = config.GetUinint64() diff --git a/Processor/Processor.go b/Processor/Processor.go index 1f6466e6..e4558ae1 100644 --- a/Processor/Processor.go +++ b/Processor/Processor.go @@ -130,6 +130,30 @@ type OnebotInteractionNotice struct { Data *dto.WSInteractionData `json:"data,omitempty"` } +// onebotv11标准扩展 +type OnebotGroupRejectNotice 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.GroupMsgRejectEvent `json:"data,omitempty"` +} + +// onebotv11标准扩展 +type OnebotGroupReceiveNotice 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.GroupMsgReceiveEvent `json:"data,omitempty"` +} + type PrivateSender struct { Nickname string `json:"nickname"` UserID int64 `json:"user_id"` // Can be either string or int depending on logic diff --git a/botgo/dto/forum.go b/botgo/dto/forum.go index a8f5fcf9..1ec6c8b5 100644 --- a/botgo/dto/forum.go +++ b/botgo/dto/forum.go @@ -53,7 +53,8 @@ type Thread struct { ChannelID string `json:"channel_id"` AuthorID string `json:"author_id"` ThreadInfo ThreadInfo `json:"thread_info"` - ID string `json:"id,omitempty"` // 新增字段以存储ID + ID string `json:"id,omitempty"` // 新增字段以存储ID + EventID string `json:"event_id,omitempty"` // 新增字段以存储EventID } // Post 帖子事件主体内容 diff --git a/botgo/dto/interaction.go b/botgo/dto/interaction.go index 31544046..f56ebded 100644 --- a/botgo/dto/interaction.go +++ b/botgo/dto/interaction.go @@ -3,6 +3,7 @@ package dto // Interaction 互动行为对象 type Interaction struct { ID string `json:"id,omitempty"` // 平台方事件 ID + EventID string `json:"event_id,omitempty"` // 外层event_id Type InteractionType `json:"type,omitempty"` // 消息按钮: 11, 单聊快捷菜单: 12 Scene string `json:"scene,omitempty"` // 事件发生的场景 ChatType int `json:"chat_type,omitempty"` // 频道场景: 0, 群聊场景: 1, 单聊场景: 2 diff --git a/botgo/dto/message.go b/botgo/dto/message.go index 91b4b8d3..e57ddd46 100644 --- a/botgo/dto/message.go +++ b/botgo/dto/message.go @@ -54,6 +54,21 @@ type Forum struct { // GroupAddBotEvent 表示群添加机器人事件的数据结构 type GroupAddBotEvent struct { ID string `json:"id"` + EventID string `json:"event_id"` + GroupOpenID string `json:"group_openid"` + OpMemberOpenID string `json:"op_member_openid"` + Timestamp interface{} `json:"timestamp"` +} + +type GroupMsgRejectEvent struct { + EventID string `json:"event_id"` + GroupOpenID string `json:"group_openid"` + OpMemberOpenID string `json:"op_member_openid"` + Timestamp interface{} `json:"timestamp"` +} + +type GroupMsgReceiveEvent struct { + EventID string `json:"event_id"` GroupOpenID string `json:"group_openid"` OpMemberOpenID string `json:"op_member_openid"` Timestamp interface{} `json:"timestamp"` diff --git a/botgo/dto/websocket_event.go b/botgo/dto/websocket_event.go index 443d8259..5c89c40e 100644 --- a/botgo/dto/websocket_event.go +++ b/botgo/dto/websocket_event.go @@ -42,6 +42,8 @@ const ( EventC2CMessageCreate EventType = "C2C_MESSAGE_CREATE" EventGroupAddRobot EventType = "GROUP_ADD_ROBOT" EventGroupDelRobot EventType = "GROUP_DEL_ROBOT" + EventGroupMsgReject EventType = "GROUP_MSG_REJECT" + EventGroupMsgReceive EventType = "GROUP_MSG_RECEIVE" ) // intentEventMap 不同 intent 对应的事件定义 diff --git a/botgo/event/event.go b/botgo/event/event.go index b1bb4fd5..e4c094e6 100644 --- a/botgo/event/event.go +++ b/botgo/event/event.go @@ -56,6 +56,8 @@ var eventParseFuncMap = map[dto.OPCode]map[dto.EventType]eventParseFunc{ dto.EventC2CMessageCreate: c2cMessageHandler, dto.EventGroupAddRobot: groupaddbothandler, dto.EventGroupDelRobot: groupdelbothandler, + dto.EventGroupMsgReject: groupMsgRejecthandler, + dto.EventGroupMsgReceive: groupMsgReceivehandler, }, } @@ -78,8 +80,8 @@ func ParseAndHandle(payload *dto.WSPayload) error { func ParseData(message []byte, target interface{}) error { // 获取数据部分 data := gjson.Get(string(message), "d") - // 外层ID 与内层ID不同 - id := gjson.Get(string(message), "id").String() + // 外层ID 与内层ID不同 外层id是event_id 用于发送参数 d内层id是id,用于put回调接口 + eventid := gjson.Get(string(message), "id").String() // 使用switch语句处理不同类型 switch v := target.(type) { @@ -89,7 +91,7 @@ func ParseData(message []byte, target interface{}) error { return err } // 设置ID字段 - v.ID = id + v.EventID = eventid return nil case *dto.GroupAddBotEvent: @@ -98,7 +100,7 @@ func ParseData(message []byte, target interface{}) error { return err } // 设置ID字段 - v.ID = id + v.EventID = eventid return nil case *dto.WSInteractionData: @@ -107,7 +109,25 @@ func ParseData(message []byte, target interface{}) error { return err } // 设置ID字段 - v.ID = id + v.EventID = eventid + return nil + + case *dto.GroupMsgRejectEvent: + // 特殊处理dto.GroupMsgRejectEvent + if err := json.Unmarshal([]byte(data.String()), v); err != nil { + return err + } + // 设置ID字段 + v.EventID = eventid + return nil + + case *dto.GroupMsgReceiveEvent: + // 特殊处理dto.GroupMsgReceiveEvent + if err := json.Unmarshal([]byte(data.String()), v); err != nil { + return err + } + // 设置ID字段 + v.EventID = eventid return nil default: @@ -346,3 +366,25 @@ func interactionHandler(payload *dto.WSPayload, message []byte) error { } return nil } + +func groupMsgRejecthandler(payload *dto.WSPayload, message []byte) error { + data := &dto.GroupMsgRejectEvent{} + if err := ParseData(message, data); err != nil { + return err + } + if DefaultHandlers.GroupMsgReject != nil { + return DefaultHandlers.GroupMsgReject(payload, data) + } + return nil +} + +func groupMsgReceivehandler(payload *dto.WSPayload, message []byte) error { + data := &dto.GroupMsgReceiveEvent{} + if err := ParseData(message, data); err != nil { + return err + } + if DefaultHandlers.GroupMsgReceive != nil { + return DefaultHandlers.GroupMsgReceive(payload, data) + } + return nil +} diff --git a/botgo/event/register.go b/botgo/event/register.go index 03b7f6dc..bfff4804 100644 --- a/botgo/event/register.go +++ b/botgo/event/register.go @@ -32,10 +32,12 @@ var DefaultHandlers struct { Interaction InteractionEventHandler - GroupATMessage GroupATMessageEventHandler - C2CMessage C2CMessageEventHandler - GroupAddbot GroupAddRobotEventHandler - GroupDelbot GroupDelRobotEventHandler + GroupATMessage GroupATMessageEventHandler + C2CMessage C2CMessageEventHandler + GroupAddbot GroupAddRobotEventHandler + GroupDelbot GroupDelRobotEventHandler + GroupMsgReject GroupMsgRejectHandler + GroupMsgReceive GroupMsgReceiveHandler } // ReadyHandler 可以处理 ws 的 ready 事件 @@ -113,6 +115,12 @@ type GroupAddRobotEventHandler func(event *dto.WSPayload, data *dto.GroupAddBotE // GroupDelRobot 机器人删除事件 handler type GroupDelRobotEventHandler func(event *dto.WSPayload, data *dto.GroupAddBotEvent) error +// GroupMsgRejectHandler 机器人推送关闭事件 handler +type GroupMsgRejectHandler func(event *dto.WSPayload, data *dto.GroupMsgRejectEvent) error + +// GroupMsgReceiveHandler 机器人推送开启事件 handler +type GroupMsgReceiveHandler func(event *dto.WSPayload, data *dto.GroupMsgReceiveEvent) error + // ************************************************ // RegisterHandlers 注册事件回调,并返回 intent 用于 websocket 的鉴权 @@ -139,6 +147,10 @@ func RegisterHandlers(handlers ...interface{}) dto.Intent { DefaultHandlers.GroupAddbot = handle case GroupDelRobotEventHandler: DefaultHandlers.GroupDelbot = handle + case GroupMsgRejectHandler: + DefaultHandlers.GroupMsgReject = handle + case GroupMsgReceiveHandler: + DefaultHandlers.GroupMsgReceive = handle default: } } diff --git a/config/config.go b/config/config.go index f26eafe1..05488837 100644 --- a/config/config.go +++ b/config/config.go @@ -2130,3 +2130,35 @@ func GetEnableChangeWord() bool { } return instance.Settings.EnableChangeWord } + +// 获取GlobalGroupMsgRejectReciveEventToMessage状态 +func GetGlobalGroupMsgRejectReciveEventToMessage() bool { + mu.Lock() + defer mu.Unlock() + + if instance == nil { + mylog.Println("Warning: instance is nil when trying to GlobalGroupMsgRejectReciveEventToMessage.") + return false + } + return instance.Settings.GlobalGroupMsgRejectReciveEventToMessage +} + +// 获取GlobalGroupMsgRejectMessage +func GetGlobalGroupMsgRejectMessage() string { + mu.Lock() + defer mu.Unlock() + if instance != nil { + return instance.Settings.GlobalGroupMsgRejectMessage + } + return "" +} + +// 获取GlobalGroupMsgRejectMessage +func GetGlobalGroupMsgReceiveMessage() string { + mu.Lock() + defer mu.Unlock() + if instance != nil { + return instance.Settings.GlobalGroupMsgReceiveMessage + } + return "" +} diff --git a/handlers/send_msg.go b/handlers/send_msg.go index 7afceb22..24565eff 100644 --- a/handlers/send_msg.go +++ b/handlers/send_msg.go @@ -224,7 +224,7 @@ func GetMessageIDByUseridOrGroupid(appID string, userID interface{}) string { return messageid } -// 通过user_id获取EventID 私聊,群,频道,通用 userID可以是三者之一 这是不需要区分群+用户的 只需要精准到群 私聊只需要精准到用户 +// 通过user_id获取EventID 私聊,群,频道,通用 userID可以是三者之一 这是不需要区分群+用户的 只需要精准到群 私聊只需要精准到用户 idmap不开启的用户使用 func GetEventIDByUseridOrGroupid(appID string, userID interface{}) string { // 从appID和userID生成key var userIDStr string @@ -241,7 +241,7 @@ func GetEventIDByUseridOrGroupid(appID string, userID interface{}) string { // 可能需要处理其他类型或报错 return "" } - //将真实id转为int + //将真实id转为int 这是非idmap-pro的方式 userid64, err := idmap.StoreIDv2(userIDStr) if err != nil { mylog.Printf("Error storing ID 241: %v", err) @@ -251,6 +251,7 @@ func GetEventIDByUseridOrGroupid(appID string, userID interface{}) string { mylog.Printf("GetEventIDByUseridOrGroupid_key:%v", key) eventid := echo.GetEventIDByKey(key) if eventid == "" { + // 用原始id获取,这个分支应该是没有用的. key := appID + "_" + userIDStr mylog.Printf("GetEventIDByUseridOrGroupid_key_2:%v", key) eventid = echo.GetEventIDByKey(key) diff --git a/main.go b/main.go index 3d144294..85636ad7 100644 --- a/main.go +++ b/main.go @@ -653,6 +653,20 @@ func GroupDelRobotEventHandler() event.GroupDelRobotEventHandler { } } +// GroupMsgRejectHandler 实现处理 群请求关闭机器人主动推送 事件的回调 +func GroupMsgRejectHandler() event.GroupMsgRejectHandler { + return func(event *dto.WSPayload, data *dto.GroupMsgRejectEvent) error { + return p.ProcessGroupMsgReject(data) + } +} + +// GroupMsgReceiveHandler 实现处理 群请求开启机器人主动推送 事件的回调 +func GroupMsgReceiveHandler() event.GroupMsgReceiveHandler { + return func(event *dto.WSPayload, data *dto.GroupMsgReceiveEvent) error { + return p.ProcessGroupMsgRecive(data) + } +} + func getHandlerByName(handlerName string) (interface{}, bool) { switch handlerName { case "ReadyHandler": //连接成功 @@ -679,10 +693,14 @@ func getHandlerByName(handlerName string) (interface{}, bool) { return GroupATMessageEventHandler(), true case "C2CMessageEventHandler": //群私聊 return C2CMessageEventHandler(), true - case "GroupAddRobotEventHandler": //群私聊 + case "GroupAddRobotEventHandler": //群添加机器人 return GroupAddRobotEventHandler(), true - case "GroupDelRobotEventHandler": //群私聊 + case "GroupDelRobotEventHandler": //群删除机器人 return GroupDelRobotEventHandler(), true + case "GroupMsgRejectHandler": //群请求关闭机器人主动推送 + return GroupMsgRejectHandler(), true + case "GroupMsgReceiveHandler": //群请求开启机器人主动推送 + return GroupMsgReceiveHandler(), true default: log.Printf("Unknown handler: %s\n", handlerName) return nil, false diff --git a/structs/structs.go b/structs/structs.go index 4e5eae54..14e41dc1 100644 --- a/structs/structs.go +++ b/structs/structs.go @@ -24,12 +24,15 @@ type Settings struct { //事件订阅类 TextIntent []string `yaml:"text_intent"` //转换类 - GlobalChannelToGroup bool `yaml:"global_channel_to_group"` - GlobalPrivateToChannel bool `yaml:"global_private_to_channel"` - GlobalForumToChannel bool `yaml:"global_forum_to_channel"` - GlobalInteractionToMessage bool `yaml:"global_interaction_to_message"` - HashID bool `yaml:"hash_id"` - IdmapPro bool `yaml:"idmap_pro"` + GlobalChannelToGroup bool `yaml:"global_channel_to_group"` + GlobalPrivateToChannel bool `yaml:"global_private_to_channel"` + GlobalForumToChannel bool `yaml:"global_forum_to_channel"` + GlobalInteractionToMessage bool `yaml:"global_interaction_to_message"` + GlobalGroupMsgRejectReciveEventToMessage bool `yaml:"global_group_msg_rre_to_message"` + GlobalGroupMsgRejectMessage string `yaml:"global_group_msg_reject_message"` + GlobalGroupMsgReceiveMessage string `yaml:"global_group_msg_receive_message"` + HashID bool `yaml:"hash_id"` + IdmapPro bool `yaml:"idmap_pro"` //gensokyo互联类 Server_dir string `yaml:"server_dir"` Port string `yaml:"port"` diff --git a/template/config_template.go b/template/config_template.go index a7b1e277..c3842272 100644 --- a/template/config_template.go +++ b/template/config_template.go @@ -39,8 +39,11 @@ settings: global_private_to_channel: false # 是否将私聊转换成频道 如果是群场景 会将私聊转为群(方便提审\测试) global_forum_to_channel: false # 是否将频道帖子信息转化为频道 子频道信息 如果开启global_channel_to_group会进一步转换为群信息 global_interaction_to_message : false # 是否将按钮和表态回调转化为消息 仅在设置了按钮回调中的message时有效 + global_group_msg_rre_to_message : false # 是否将用户开关机器人资料页的机器人推送开关 产生的事件转换为文本信息并发送给应用端.false将使用onebotv11的notice类型上报. + global_group_msg_reject_message : "机器人主动消息被关闭" # 当开启 global_group_msg_rre_to_message 时,机器人主动信息被关闭将上报的信息. 自行添加intent - GroupMsgRejectHandler + global_group_msg_receive_message : "机器人主动消息被开启" # 建议设置为无规则复杂随机内容,避免用户指令内容碰撞. 自行添加 intent - GroupMsgReceiveHandler hash_id : false # 使用hash来进行idmaps转换,可以让user_id不是123开始的递增值 - idmap_pro : false #需开启hash_id配合,高级id转换增强,可以多个真实值bind到同一个虚拟值,对于每个用户,每个群\私聊\判断私聊\频道,都会产生新的虚拟值,但可以多次bind,bind到同一个数字.数据库负担会变大. + idmap_pro : false # 需开启hash_id配合,高级id转换增强,可以多个真实值bind到同一个虚拟值,对于每个用户,每个群\私聊\判断私聊\频道,都会产生新的虚拟值,但可以多次bind,bind到同一个数字.数据库负担会变大. #Gensokyo互联类 server_dir: "" # Lotus地址.不带http头的域名或ip,提供图片上传服务的服务器(图床)需要带端口号. 如果需要发base64图,需为公网ip,且开放对应端口 From bf13e563807fd9b024456e6c5f6b5e1fe3632c73 Mon Sep 17 00:00:00 2001 From: cosmo Date: Fri, 10 May 2024 11:01:40 +0800 Subject: [PATCH 03/20] beta401 --- Processor/ProcessGroupMsgReceive.go | 6 +- Processor/ProcessGroupMsgReject.go | 6 +- config/config.go | 222 ++++++++++++++++++++-------- go.mod | 3 +- go.sum | 2 + main.go | 45 +++++- 6 files changed, 214 insertions(+), 70 deletions(-) diff --git a/Processor/ProcessGroupMsgReceive.go b/Processor/ProcessGroupMsgReceive.go index b1c6425c..3df37683 100644 --- a/Processor/ProcessGroupMsgReceive.go +++ b/Processor/ProcessGroupMsgReceive.go @@ -65,6 +65,8 @@ func (p *Processors) ProcessGroupMsgRecive(data *dto.GroupMsgReceiveEvent) error mylog.Printf("Error storing ID: %v", err) return nil } + // 修复不开启idmap-pro问题 + LongGroupID64 = GroupID64 } var selfid64 int64 if config.GetUseUin() { @@ -76,7 +78,7 @@ func (p *Processors) ProcessGroupMsgRecive(data *dto.GroupMsgReceiveEvent) error if !config.GetGlobalGroupMsgRejectReciveEventToMessage() { notice := &OnebotGroupReceiveNotice{ GroupID: GroupID64, - NoticeType: "interaction", + NoticeType: "group_receive", PostType: "notice", SelfID: selfid64, SubType: "create", @@ -150,7 +152,7 @@ func (p *Processors) ProcessGroupMsgRecive(data *dto.GroupMsgReceiveEvent) error } //增强配置 if !config.GetNativeOb11() { - groupMsg.RealMessageType = "interaction" + groupMsg.RealMessageType = "group_receive" groupMsg.IsBindedUserId = IsBindedUserId groupMsg.IsBindedGroupId = IsBindedGroupId groupMsg.RealGroupID = data.GroupOpenID diff --git a/Processor/ProcessGroupMsgReject.go b/Processor/ProcessGroupMsgReject.go index e222152c..ae53d668 100644 --- a/Processor/ProcessGroupMsgReject.go +++ b/Processor/ProcessGroupMsgReject.go @@ -66,6 +66,8 @@ func (p *Processors) ProcessGroupMsgReject(data *dto.GroupMsgRejectEvent) error mylog.Printf("Error storing ID: %v", err) return nil } + // 修复不开启idmap-pro问题 + LongGroupID64 = GroupID64 } var selfid64 int64 if config.GetUseUin() { @@ -77,7 +79,7 @@ func (p *Processors) ProcessGroupMsgReject(data *dto.GroupMsgRejectEvent) error if !config.GetGlobalGroupMsgRejectReciveEventToMessage() { notice := &OnebotGroupRejectNotice{ GroupID: GroupID64, - NoticeType: "interaction", + NoticeType: "group_reject", PostType: "notice", SelfID: selfid64, SubType: "create", @@ -151,7 +153,7 @@ func (p *Processors) ProcessGroupMsgReject(data *dto.GroupMsgRejectEvent) error } //增强配置 if !config.GetNativeOb11() { - groupMsg.RealMessageType = "interaction" + groupMsg.RealMessageType = "group_reject" groupMsg.IsBindedUserId = IsBindedUserId groupMsg.IsBindedGroupId = IsBindedGroupId groupMsg.RealGroupID = data.GroupOpenID diff --git a/config/config.go b/config/config.go index 05488837..e3bc138f 100644 --- a/config/config.go +++ b/config/config.go @@ -35,47 +35,141 @@ type CommentBlock struct { Offset int // 注释与目标键之间的行数 } +// 不支持配置热重载的配置项 +var restartRequiredFields = []string{ + "WsAddress", "WsToken", "ReconnectTimes", "HeartBeatInterval", "LaunchReconnectTimes", + "AppID", "Uin", "Token", "ClientSecret", "ShardCount", "ShardID", "UseUin", + "TextIntent", + "ServerDir", "Port", "BackupPort", "Lotus", "LotusPassword", "LotusWithoutIdmaps", + "WsServerPath", "EnableWsServer", "WsServerToken", + "IdentifyFile", "IdentifyAppids", "Crt", "Key", + "DeveloperLog", "LogLevel", "SaveLogs", + "DisableWebui", "Username", "Password", + "Title", // 继续检查和增加 +} + // LoadConfig 从文件中加载配置并初始化单例配置 -func LoadConfig(path string) (*Config, error) { +func LoadConfig(path string, fastload bool) (*Config, error) { mu.Lock() defer mu.Unlock() - // 如果单例已经被初始化了,直接返回 - if instance != nil { - return instance, nil - } - configData, err := os.ReadFile(path) if err != nil { return nil, err } - //todo remove it 破坏性变更的擦屁股代码 - var ischange bool - configData, ischange = replaceVisualPrefixsLine(configData) - if ischange { - err = os.WriteFile(path, configData, 0644) - if err != nil { - // 处理写入错误 - return nil, err - } - } - //mylog.Printf("dev_ischange:%v", ischange) + + // 检查并替换视觉前缀行,如果有必要,后期会注释 + // var isChange bool + // configData, isChange = replaceVisualPrefixsLine(configData) + // if isChange { + // // 如果配置文件已修改,重新写入修正后的数据 + // if err = os.WriteFile(path, configData, 0644); err != nil { + // return nil, err // 处理写入错误 + // } + // } + + // 尝试解析配置数据 conf := &Config{} - err = yaml.Unmarshal(configData, conf) - if err != nil { + if err = yaml.Unmarshal(configData, conf); err != nil { return nil, err } - // 确保配置完整性 - if err := ensureConfigComplete(path); err != nil { - return nil, err + if !fastload { + // 确保本地配置文件的完整性,添加新的字段 + if err = ensureConfigComplete(path); err != nil { + return nil, err + } + } else { + if isValidConfig(conf) { + //log.Printf("instance.Settings:%v", instance.Settings) + // 用现有的instance比对即将覆盖赋值的conf,用[]string返回配置发生了变化的配置项 + changedFields := compareConfigChanges("Settings", instance.Settings, conf.Settings) + // 根据changedFields进行进一步的操作,在不支持热重载的字段实现自动重启 + if len(changedFields) > 0 { + log.Printf("配置已变更的字段:%v", changedFields) + checkForRestart(changedFields) // 检查变更字段是否需要重启 + } + } //conf为空时不对比 + } + + // 更新单例实例,即使它已经存在 更新前检查是否有效,vscode对文件的更新行为会触发2次文件变动 + // 第一次会让configData为空,迅速的第二次才是正常有值的configData + if isValidConfig(conf) { + instance = conf } - // 设置单例实例 - instance = conf return instance, nil } +func isValidConfig(conf *Config) bool { + // 确认config不为空且必要字段已设置 + return conf != nil && conf.Version != 0 +} + +// 去除Settings前缀 +func stripSettingsPrefix(fieldName string) string { + return strings.TrimPrefix(fieldName, "Settings.") +} + +// compareConfigChanges 检查并返回发生变化的配置字段,处理嵌套结构体 +func compareConfigChanges(prefix string, oldConfig interface{}, newConfig interface{}) []string { + var changedFields []string + + oldVal := reflect.ValueOf(oldConfig) + newVal := reflect.ValueOf(newConfig) + + // 解引用指针 + if oldVal.Kind() == reflect.Ptr { + oldVal = oldVal.Elem() + } + if newVal.Kind() == reflect.Ptr { + newVal = newVal.Elem() + } + + // 遍历所有字段 + for i := 0; i < oldVal.NumField(); i++ { + oldField := oldVal.Field(i) + newField := newVal.Field(i) + fieldType := oldVal.Type().Field(i) + fieldName := fieldType.Name + + fullFieldName := fieldName + if prefix != "" { + fullFieldName = fmt.Sprintf("%s.%s", prefix, fieldName) + } + + // 对于结构体字段递归比较 + if oldField.Kind() == reflect.Struct || newField.Kind() == reflect.Struct { + subChanges := compareConfigChanges(fullFieldName, oldField.Interface(), newField.Interface()) + changedFields = append(changedFields, subChanges...) + } else { + // 打印将要比较的字段和它们的值 + //fmt.Printf("Comparing field: %s\nOld value: %v\nNew value: %v\n", fullFieldName, oldField.Interface(), newField.Interface()) + if !reflect.DeepEqual(oldField.Interface(), newField.Interface()) { + //fmt.Println("-> Field changed") + // 去除Settings前缀后添加到变更字段列表 + changedField := stripSettingsPrefix(fullFieldName) + changedFields = append(changedFields, changedField) + } + } + } + + return changedFields +} + +// 检查是否需要重启 +func checkForRestart(changedFields []string) { + for _, field := range changedFields { + for _, restartField := range restartRequiredFields { + if field == restartField { + fmt.Println("Configuration change requires restart:", field) + sys.RestartApplication() // 调用重启函数 + return + } + } + } +} + func CreateAndWriteConfigTemp() error { // 读取config.yml configFile, err := os.ReadFile("config.yml") @@ -1426,46 +1520,46 @@ func GetQrSize() int { return instance.Settings.QrSize } -func replaceVisualPrefixsLine(configData []byte) ([]byte, bool) { - // 定义新的 visual_prefixs 部分 - newVisualPrefixs := ` visual_prefixs : #虚拟前缀 与white_prefixs配合使用 处理流程自动忽略该前缀 remove_prefix remove_at 需为true时生效 - - prefix: "" #虚拟前缀开头 例 你有3个指令 帮助 测试 查询 将 prefix 设置为 工具类 后 则可通过 工具类 帮助 触发机器人 - whiteList: [""] #开关状态取决于 white_prefix_mode 为每一个二级指令头设计独立的白名单 - No_White_Response : "" - - prefix: "" - whiteList: [""] - No_White_Response : "" - - prefix: "" - whiteList: [""] - No_White_Response : "" ` - - // 将 byte 数组转换为字符串 - configStr := string(configData) - - // 按行分割 configStr - lines := strings.Split(configStr, "\n") - - // 创建一个新的字符串构建器 - var newConfigData strings.Builder - - // 标记是否进行了替换 - replaced := false - - // 遍历所有行 - for _, line := range lines { - // 检查是否是 visual_prefixs 开头的行 - if strings.HasPrefix(strings.TrimSpace(line), "visual_prefixs : [") { - // 替换为新的 visual_prefixs 部分 - newConfigData.WriteString(newVisualPrefixs + "\n") - replaced = true - continue // 跳过原有行 - } - newConfigData.WriteString(line + "\n") - } - - // 返回新配置和是否发生了替换的标记 - return []byte(newConfigData.String()), replaced -} +// func replaceVisualPrefixsLine(configData []byte) ([]byte, bool) { +// // 定义新的 visual_prefixs 部分 +// newVisualPrefixs := ` visual_prefixs : #虚拟前缀 与white_prefixs配合使用 处理流程自动忽略该前缀 remove_prefix remove_at 需为true时生效 +// - prefix: "" #虚拟前缀开头 例 你有3个指令 帮助 测试 查询 将 prefix 设置为 工具类 后 则可通过 工具类 帮助 触发机器人 +// whiteList: [""] #开关状态取决于 white_prefix_mode 为每一个二级指令头设计独立的白名单 +// No_White_Response : "" +// - prefix: "" +// whiteList: [""] +// No_White_Response : "" +// - prefix: "" +// whiteList: [""] +// No_White_Response : "" ` + +// // 将 byte 数组转换为字符串 +// configStr := string(configData) + +// // 按行分割 configStr +// lines := strings.Split(configStr, "\n") + +// // 创建一个新的字符串构建器 +// var newConfigData strings.Builder + +// // 标记是否进行了替换 +// replaced := false + +// // 遍历所有行 +// for _, line := range lines { +// // 检查是否是 visual_prefixs 开头的行 +// if strings.HasPrefix(strings.TrimSpace(line), "visual_prefixs : [") { +// // 替换为新的 visual_prefixs 部分 +// newConfigData.WriteString(newVisualPrefixs + "\n") +// replaced = true +// continue // 跳过原有行 +// } +// newConfigData.WriteString(line + "\n") +// } + +// // 返回新配置和是否发生了替换的标记 +// return []byte(newConfigData.String()), replaced +// } // 获取GetWhiteBypassRevers的值 func GetWhiteBypassRevers() bool { diff --git a/go.mod b/go.mod index c41d3ff0..df8ad2a7 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/aliyun/aliyun-oss-go-sdk v3.0.1+incompatible github.com/baidubce/bce-sdk-go v0.9.161 github.com/fatih/color v1.15.0 + github.com/fsnotify/fsnotify v1.7.0 github.com/gin-gonic/gin v1.9.1 github.com/google/uuid v1.4.0 github.com/gorilla/websocket v1.4.2 @@ -69,6 +70,6 @@ require ( golang.org/x/net v0.10.0 golang.org/x/sys v0.13.0 golang.org/x/text v0.9.0 // indirect - google.golang.org/protobuf v1.32.0 + google.golang.org/protobuf v1.32.0 // indirect mvdan.cc/xurls v1.1.0 ) diff --git a/go.sum b/go.sum index 401b1c22..7ba6f44c 100644 --- a/go.sum +++ b/go.sum @@ -34,6 +34,8 @@ github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBD github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= diff --git a/main.go b/main.go index 85636ad7..2e6d82c5 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,7 @@ import ( "time" "github.com/fatih/color" + "github.com/fsnotify/fsnotify" "github.com/hoshinonyaruko/gensokyo/Processor" "github.com/hoshinonyaruko/gensokyo/acnode" "github.com/hoshinonyaruko/gensokyo/botstats" @@ -93,10 +94,14 @@ func main() { // 主逻辑 // 加载配置 - conf, err := config.LoadConfig("config.yml") + conf, err := config.LoadConfig("config.yml", false) if err != nil { log.Fatalf("error: %v", err) } + + // 配置热重载 + go setupConfigWatcher("config.yml") + sys.SetTitle(conf.Settings.Title) webuiURL := config.ComposeWebUIURL(conf.Settings.Lotus) // 调用函数获取URL webuiURLv2 := config.ComposeWebUIURLv2(conf.Settings.Lotus) // 调用函数获取URL @@ -716,3 +721,41 @@ func allEmpty(addresses []string) bool { } return true } + +func setupConfigWatcher(configFilePath string) { + watcher, err := fsnotify.NewWatcher() + if err != nil { + log.Fatalf("Error setting up watcher: %v", err) + } + + // 添加一个100毫秒的Debouncing + //fileLoader := &config.ConfigFileLoader{EventDelay: 100 * time.Millisecond} + + // Start the goroutine to handle file system events. + go func() { + for { + select { + case event, ok := <-watcher.Events: + if !ok { + return // Exit if channel is closed. + } + if event.Op&fsnotify.Write == fsnotify.Write { + fmt.Println("检测到配置文件变动:", event.Name) + //fileLoader.LoadConfigF(configFilePath) + config.LoadConfig(configFilePath, true) + } + case err, ok := <-watcher.Errors: + if !ok { + return // Exit if channel is closed. + } + log.Println("Watcher error:", err) + } + } + }() + + // Add the config file to the list of watched files. + err = watcher.Add(configFilePath) + if err != nil { + log.Fatalf("Error adding watcher: %v", err) + } +} From f1026ae83372ac3964bc4322c7b2b56f8faf17b7 Mon Sep 17 00:00:00 2001 From: cosmo Date: Fri, 10 May 2024 17:13:09 +0800 Subject: [PATCH 04/20] beta402 --- handlers/send_group_msg.go | 88 ++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 38 deletions(-) diff --git a/handlers/send_group_msg.go b/handlers/send_group_msg.go index 77597bce..d7970630 100644 --- a/handlers/send_group_msg.go +++ b/handlers/send_group_msg.go @@ -246,6 +246,7 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap } if imageCount == 1 && messageText != "" { + var groupMessage *dto.MessageToCreate mylog.Printf("发图文混合信息-群") // 创建包含单个图片的 singleItem singleItem[imageType] = []string{imageUrl} @@ -254,11 +255,15 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap groupReply := generateGroupMessage(messageID, eventID, singleItem, "", msgseq+1, apiv2, message.Params.GroupID.(string)) // 进行类型断言 richMediaMessage, ok := groupReply.(*dto.RichMediaMessage) + // 如果断言为RichMediaMessage失败 if !ok { - mylog.Printf("Error: Expected RichMediaMessage type for key ") - return "", nil + // 尝试断言为MessageToCreate + groupMessage, ok = groupReply.(*dto.MessageToCreate) + if !ok { + mylog.Printf("Error: Expected RichMediaMessage type for key,value:%v", groupReply) + return "", nil + } } - var groupMessage *dto.MessageToCreate var transmd bool var md *dto.Markdown var kb *keyboard.MessageKeyboard @@ -266,46 +271,53 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap if config.GetTwoWayEcho() { md, kb, transmd = auto_md(message, messageText, richMediaMessage) } + // 如果groupMessage是nil 说明groupReply是richMediaMessage类型 如果groupMessage不是nil 说明groupReply是MessageToCreate + if groupMessage == nil { + //如果没有转换成md发送 + if !transmd { + // 上传图片并获取FileInfo + fileInfo, err := uploadMedia(context.TODO(), message.Params.GroupID.(string), richMediaMessage, apiv2) + if err != nil { + mylog.Printf("上传图片失败: %v", err) + return "", nil // 或其他错误处理 + } + // 创建包含文本和图像信息的消息 + msgseq = echo.GetMappingSeq(messageID) + echo.AddMappingSeq(messageID, msgseq+1) + groupMessage = &dto.MessageToCreate{ + Content: messageText, // 添加文本内容 + Media: dto.Media{ + FileInfo: fileInfo, // 添加图像信息 + }, + MsgID: messageID, + EventID: eventID, + MsgSeq: msgseq, + MsgType: 7, // 假设7是组合消息类型 + } + groupMessage.Timestamp = time.Now().Unix() // 设置时间戳 + } else { + //将kb和md组合成groupMessage并用MsgType=2发送 - //如果没有转换成md发送 - if !transmd { - // 上传图片并获取FileInfo - fileInfo, err := uploadMedia(context.TODO(), message.Params.GroupID.(string), richMediaMessage, apiv2) - if err != nil { - mylog.Printf("上传图片失败: %v", err) - return "", nil // 或其他错误处理 - } - // 创建包含文本和图像信息的消息 - msgseq = echo.GetMappingSeq(messageID) - echo.AddMappingSeq(messageID, msgseq+1) - groupMessage = &dto.MessageToCreate{ - Content: messageText, // 添加文本内容 - Media: dto.Media{ - FileInfo: fileInfo, // 添加图像信息 - }, - MsgID: messageID, - EventID: eventID, - MsgSeq: msgseq, - MsgType: 7, // 假设7是组合消息类型 - } - groupMessage.Timestamp = time.Now().Unix() // 设置时间戳 - } else { - //将kb和md组合成groupMessage并用MsgType=2发送 + msgseq = echo.GetMappingSeq(messageID) + echo.AddMappingSeq(messageID, msgseq+1) + groupMessage = &dto.MessageToCreate{ + Content: "markdown", // 添加文本内容 + MsgID: messageID, + EventID: eventID, + MsgSeq: msgseq, + Markdown: md, + Keyboard: kb, + MsgType: 2, // 假设7是组合消息类型 + } + groupMessage.Timestamp = time.Now().Unix() // 设置时间戳 - msgseq = echo.GetMappingSeq(messageID) - echo.AddMappingSeq(messageID, msgseq+1) - groupMessage = &dto.MessageToCreate{ - Content: "markdown", // 添加文本内容 - MsgID: messageID, - EventID: eventID, - MsgSeq: msgseq, - Markdown: md, - Keyboard: kb, - MsgType: 2, // 假设7是组合消息类型 } + } else { + // 为groupMessage附加内容 变成图文信息 + groupMessage.Content = messageText groupMessage.Timestamp = time.Now().Unix() // 设置时间戳 - } + // 发送组合消息 resp, err := apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) if err != nil { From a77b628f23d968d328325a2d3a626a8a7497ed81 Mon Sep 17 00:00:00 2001 From: cosmo Date: Fri, 10 May 2024 17:56:06 +0800 Subject: [PATCH 05/20] beta403 --- handlers/send_group_msg.go | 10 +++++----- handlers/send_group_msg_raw.go | 6 +++--- handlers/send_msg.go | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/handlers/send_group_msg.go b/handlers/send_group_msg.go index d7970630..044afd83 100644 --- a/handlers/send_group_msg.go +++ b/handlers/send_group_msg.go @@ -125,7 +125,7 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap messageID = echo.GetLazyMessagesId(message.Params.GroupID.(string)) mylog.Printf("GetLazyMessagesId: %v", messageID) //如果应用端传递了user_id 就让at不要顺序乱套 - if message.Params.UserID != nil { + if message.Params.UserID != nil && message.Params.UserID.(string) != "" && message.Params.UserID.(string) != "0" { messageID = echo.GetLazyMessagesIdv2(message.Params.GroupID.(string), message.Params.UserID.(string)) mylog.Printf("GetLazyMessagesIdv2: %v", messageID) } else { @@ -148,7 +148,7 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap } var originalGroupID, originalUserID string // 检查UserID是否为nil - if message.Params.UserID != nil && config.GetIdmapPro() { + if message.Params.UserID != nil && config.GetIdmapPro() && message.Params.UserID.(string) != "" && message.Params.UserID.(string) != "0" { // 如果UserID不是nil且配置为使用Pro版本,则调用RetrieveRowByIDv2Pro originalGroupID, originalUserID, err = idmap.RetrieveRowByIDv2Pro(message.Params.GroupID.(string), message.Params.UserID.(string)) if err != nil { @@ -198,7 +198,7 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap //mylog.Println("foundItems:", foundItems) if messageID == "" { // 检查 UserID 是否为 nil - if message.Params.UserID != nil { + if message.Params.UserID != nil && message.Params.UserID.(string) != "" && message.Params.UserID.(string) != "0" { messageID = GetMessageIDByUseridAndGroupid(config.GetAppIDStr(), message.Params.UserID, message.Params.GroupID) mylog.Println("通过GetMessageIDByUseridAndGroupid函数获取的message_id:", message.Params.GroupID, messageID) } else { @@ -481,7 +481,7 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap //用GroupID给ChannelID赋值,因为我们是把频道虚拟成了群 message.Params.ChannelID = message.Params.GroupID.(string) var RChannelID string - if message.Params.UserID != nil && config.GetIdmapPro() { + if message.Params.UserID != nil && config.GetIdmapPro() && message.Params.UserID.(string) != "" && message.Params.UserID.(string) != "0" { RChannelID, _, err = idmap.RetrieveRowByIDv2Pro(message.Params.ChannelID.(string), message.Params.UserID.(string)) mylog.Printf("测试,通过Proid获取的RChannelID:%v", RChannelID) } @@ -531,7 +531,7 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap //用GroupID给ChannelID赋值,因为我们是把频道虚拟成了群 message.Params.ChannelID = message.Params.GroupID.(string) var RChannelID string - if message.Params.UserID != nil && config.GetIdmapPro() { + if message.Params.UserID != nil && config.GetIdmapPro() && message.Params.UserID.(string) != "" && message.Params.UserID.(string) != "0" { RChannelID, _, err = idmap.RetrieveRowByIDv2Pro(message.Params.ChannelID.(string), message.Params.UserID.(string)) mylog.Printf("测试,通过Proid获取的RChannelID:%v", RChannelID) } diff --git a/handlers/send_group_msg_raw.go b/handlers/send_group_msg_raw.go index 9cc1c4b2..714edc57 100644 --- a/handlers/send_group_msg_raw.go +++ b/handlers/send_group_msg_raw.go @@ -110,7 +110,7 @@ func HandleSendGroupMsgRaw(client callapi.Client, api openapi.OpenAPI, apiv2 ope var originalGroupID, originalUserID string // 检查UserID是否为nil - if message.Params.UserID != nil && config.GetIdmapPro() { + if message.Params.UserID != nil && config.GetIdmapPro() && message.Params.UserID.(string) != "" && message.Params.UserID.(string) != "0" { // 如果UserID不是nil且配置为使用Pro版本,则调用RetrieveRowByIDv2Pro originalGroupID, originalUserID, err = idmap.RetrieveRowByIDv2Pro(message.Params.GroupID.(string), message.Params.UserID.(string)) if err != nil { @@ -410,7 +410,7 @@ func HandleSendGroupMsgRaw(client callapi.Client, api openapi.OpenAPI, apiv2 ope //用GroupID给ChannelID赋值,因为我们是把频道虚拟成了群 message.Params.ChannelID = message.Params.GroupID.(string) var RChannelID string - if message.Params.UserID != nil && config.GetIdmapPro() { + if message.Params.UserID != nil && config.GetIdmapPro() && message.Params.UserID.(string) != "" && message.Params.UserID.(string) != "0" { RChannelID, _, err = idmap.RetrieveRowByIDv2Pro(message.Params.ChannelID.(string), message.Params.UserID.(string)) mylog.Printf("测试,通过Proid获取的RChannelID:%v", RChannelID) } @@ -460,7 +460,7 @@ func HandleSendGroupMsgRaw(client callapi.Client, api openapi.OpenAPI, apiv2 ope //用GroupID给ChannelID赋值,因为我们是把频道虚拟成了群 message.Params.ChannelID = message.Params.GroupID.(string) var RChannelID string - if message.Params.UserID != nil && config.GetIdmapPro() { + if message.Params.UserID != nil && config.GetIdmapPro() && message.Params.UserID.(string) != "" && message.Params.UserID.(string) != "0" { RChannelID, _, err = idmap.RetrieveRowByIDv2Pro(message.Params.ChannelID.(string), message.Params.UserID.(string)) mylog.Printf("测试,通过Proid获取的RChannelID:%v", RChannelID) } diff --git a/handlers/send_msg.go b/handlers/send_msg.go index 24565eff..a2e67a14 100644 --- a/handlers/send_msg.go +++ b/handlers/send_msg.go @@ -124,7 +124,7 @@ func HandleSendMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openapi.Ope //用GroupID给ChannelID赋值,因为我们是把频道虚拟成了群 message.Params.ChannelID = message.Params.GroupID.(string) var RChannelID string - if message.Params.UserID != nil && config.GetIdmapPro() { + if message.Params.UserID != nil && config.GetIdmapPro() && message.Params.UserID.(string) != "" && message.Params.UserID.(string) != "0" { RChannelID, _, err = idmap.RetrieveRowByIDv2Pro(message.Params.ChannelID.(string), message.Params.UserID.(string)) mylog.Printf("测试,通过Proid获取的RChannelID:%v", RChannelID) } @@ -150,7 +150,7 @@ func HandleSendMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openapi.Ope //用GroupID给ChannelID赋值,因为我们是把频道虚拟成了群 message.Params.ChannelID = message.Params.GroupID.(string) var RChannelID string - if message.Params.UserID != nil && config.GetIdmapPro() { + if message.Params.UserID != nil && config.GetIdmapPro() && message.Params.UserID.(string) != "" && message.Params.UserID.(string) != "0" { RChannelID, _, err = idmap.RetrieveRowByIDv2Pro(message.Params.ChannelID.(string), message.Params.UserID.(string)) mylog.Printf("测试,通过Proid获取的RChannelID:%v", RChannelID) } From d2448e1cc3cacae6c25a8805cbd61279be923ac4 Mon Sep 17 00:00:00 2001 From: cosmo Date: Sat, 11 May 2024 15:51:15 +0800 Subject: [PATCH 06/20] beta404 --- config/config.go | 24 ++++++++++++++++++++++++ handlers/send_group_msg.go | 36 ++++++++++++++++++++++++++---------- structs/structs.go | 2 ++ template/config_template.go | 4 +++- 4 files changed, 55 insertions(+), 11 deletions(-) diff --git a/config/config.go b/config/config.go index e3bc138f..5eb2fe50 100644 --- a/config/config.go +++ b/config/config.go @@ -2256,3 +2256,27 @@ func GetGlobalGroupMsgReceiveMessage() string { } return "" } + +// 获取EntersAsBlock状态 +func GetEntersAsBlock() bool { + mu.Lock() + defer mu.Unlock() + + if instance == nil { + mylog.Println("Warning: instance is nil when trying to EntersAsBlock.") + return false + } + return instance.Settings.EntersAsBlock +} + +// 获取NativeMD状态 +func GetNativeMD() bool { + mu.Lock() + defer mu.Unlock() + + if instance == nil { + mylog.Println("Warning: instance is nil when trying to NativeMD.") + return false + } + return instance.Settings.NativeMD +} diff --git a/handlers/send_group_msg.go b/handlers/send_group_msg.go index 044afd83..17a72838 100644 --- a/handlers/send_group_msg.go +++ b/handlers/send_group_msg.go @@ -1335,6 +1335,7 @@ func auto_md(message callapi.ActionMessage, messageText string, richMediaMessage mylog.Printf("获取图片宽高出错") } imgDesc := fmt.Sprintf("图片 #%dpx #%dpx", width, height) + // 将所有的\r\n替换为\r messageText = strings.ReplaceAll(messageText, "\r\n", "\r") // 将所有的\n替换为\r @@ -1343,18 +1344,33 @@ func auto_md(message callapi.ActionMessage, messageText string, richMediaMessage if !strings.HasPrefix(messageText, "\r") { messageText = "\r" + messageText } - // 创建 MarkdownParams 的实例 - mdParams := []*dto.MarkdownParams{ - {Key: "text_start", Values: []string{" "}}, //空着 - {Key: "img_dec", Values: []string{imgDesc}}, - {Key: "img_url", Values: []string{imgURL}}, - {Key: "text_end", Values: []string{messageText}}, + if config.GetEntersAsBlock() { + messageText = strings.ReplaceAll(messageText, "\r", " ") } - // 组合模板 Markdown - md = &dto.Markdown{ - CustomTemplateID: CustomTemplateID, - Params: mdParams, + + // 根据配置决定如何生成Markdown内容 + if !config.GetNativeMD() { + // 创建 MarkdownParams 的实例 + mdParams := []*dto.MarkdownParams{ + {Key: "text_start", Values: []string{" "}}, //空着 + {Key: "img_dec", Values: []string{imgDesc}}, + {Key: "img_url", Values: []string{imgURL}}, + {Key: "text_end", Values: []string{messageText}}, + } + // 组合模板 Markdown + md = &dto.Markdown{ + CustomTemplateID: CustomTemplateID, + Params: mdParams, + } + } else { + // 使用原生Markdown格式 + content := fmt.Sprintf(" %s![%s](%s)%s", " ", imgDesc, imgURL, messageText) + // 原生 Markdown + md = &dto.Markdown{ + Content: content, + } } + whiteList := matchedPrefix.WhiteList // 创建 CustomKeyboard customKeyboard := &keyboard.CustomKeyboard{ diff --git a/structs/structs.go b/structs/structs.go index 14e41dc1..7786e831 100644 --- a/structs/structs.go +++ b/structs/structs.go @@ -128,6 +128,8 @@ type Settings struct { //MD相关 CustomTemplateID string `yaml:"custom_template_id"` KeyBoardID string `yaml:"keyboard_id"` + NativeMD bool `yaml:"native_md"` + EntersAsBlock bool `yaml:"enters_as_block"` //发送行为修改 LazyMessageId bool `yaml:"lazy_message_id"` RamDomSeq bool `yaml:"ramdom_seq"` diff --git a/template/config_template.go b/template/config_template.go index c3842272..37c3e312 100644 --- a/template/config_template.go +++ b/template/config_template.go @@ -167,7 +167,9 @@ settings: #MD相关 custom_template_id : "" #自动转换图文信息到md所需要的id *需要应用端支持双方向echo keyboard_id : "" #自动转换图文信息到md所需要的按钮id *需要应用端支持双方向echo - + native_md : false #自动转换图文信息到md,使用原生markdown能力. + enters_as_block : false #自动转换图文信息到md,\r \r\n \n 替换为空格. + #发送行为修改 lazy_message_id : false #false=message_id 条条准确对应 true=message_id 按时间范围随机对应(适合主动推送bot)前提,有足够多的活跃信息刷新id池 ramdom_seq : false #当多开gensokyo时,如果遇到群信息只能发出一条,请开启每个gsk的此项.(建议使用一个gsk连接多个应用) From 887f0989f53b37a1209c2a0fcef9f798a29b8546 Mon Sep 17 00:00:00 2001 From: cosmo Date: Sun, 19 May 2024 20:53:00 +0800 Subject: [PATCH 07/20] beta405 --- httpapi/httpapi.go | 17 +++++++++++++---- main.go | 25 +++++++++++++------------ 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/httpapi/httpapi.go b/httpapi/httpapi.go index cd5fe1d7..8692d760 100644 --- a/httpapi/httpapi.go +++ b/httpapi/httpapi.go @@ -453,10 +453,19 @@ func handleDeleteMsg(c *gin.Context, api openapi.OpenAPI, apiV2 openapi.OpenAPI) MessageID interface{} `json:"message_id" form:"message_id"` } - // 解析请求参数 - if err := c.ShouldBind(&req); err != nil { - c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) - return + // 根据请求方法解析参数 + if c.Request.Method == http.MethodGet { + // 从URL查询参数解析 + if err := c.ShouldBindQuery(&req); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + return + } + } else { + // 从JSON或表单数据解析 + if err := c.ShouldBind(&req); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + return + } } // 构造参数内容,只包括实际有值的字段 diff --git a/main.go b/main.go index 2e6d82c5..dc2218c3 100644 --- a/main.go +++ b/main.go @@ -183,6 +183,19 @@ func main() { log.Printf("自定义ac地址模式...请从日志手动获取bot的真实id并设置,不然at会不正常") } if !nologin { + + //创建idmap服务器 数据库 + idmap.InitializeDB() + //创建botstats数据库 + botstats.InitializeDB() + //创建webui数据库 + webui.InitializeDB() + + //关闭时候释放数据库 + defer idmap.CloseDB() + defer botstats.CloseDB() + defer webui.CloseDB() + if configURL == "" && !fix11300 { //初始化handlers handlers.BotID = me.ID } else { //初始化handlers @@ -309,18 +322,6 @@ func main() { } - //创建idmap服务器 数据库 - idmap.InitializeDB() - //创建botstats数据库 - botstats.InitializeDB() - //创建webui数据库 - webui.InitializeDB() - - //关闭时候释放数据库 - defer idmap.CloseDB() - defer botstats.CloseDB() - defer webui.CloseDB() - //图片上传 调用次数限制 rateLimiter := server.NewRateLimiter() // 根据 lotus 的值选择端口 From 6c8a5addc6f534104f1e56866760a4dd9b15c4ed Mon Sep 17 00:00:00 2001 From: cosmo Date: Fri, 24 May 2024 12:00:59 +0800 Subject: [PATCH 08/20] beta406 --- Processor/ProcessC2CMessage.go | 20 ++++++++++------- Processor/Processor.go | 1 + handlers/send_group_msg.go | 40 +++++++++++++++++++++++++++++++--- httpapi/httpapi.go | 20 ++++++++--------- 4 files changed, 60 insertions(+), 21 deletions(-) diff --git a/Processor/ProcessC2CMessage.go b/Processor/ProcessC2CMessage.go index c9945915..67589d14 100644 --- a/Processor/ProcessC2CMessage.go +++ b/Processor/ProcessC2CMessage.go @@ -120,12 +120,12 @@ func (p *Processors) ProcessC2CMessage(data *dto.WSC2CMessageData) error { SubType: "friend", Time: time.Now().Unix(), } + // 额外字段 if !config.GetNativeOb11() { privateMsg.RealMessageType = "group_private" privateMsg.IsBindedUserId = IsBindedUserId - if IsBindedUserId { - privateMsg.Avatar, _ = GenerateAvatarURL(userid64) - } + privateMsg.RealUserID = data.Author.ID + privateMsg.Avatar, _ = GenerateAvatarURLV2(data.Author.ID) } // 根据条件判断是否添加Echo字段 if config.GetTwoWayEcho() { @@ -238,11 +238,15 @@ func (p *Processors) ProcessC2CMessage(data *dto.WSC2CMessageData) error { Area: "0", Level: "0", }, - SubType: "normal", - Time: time.Now().Unix(), - Avatar: "", - RealMessageType: "group_private", - IsBindedUserId: IsBindedUserId, + 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() diff --git a/Processor/Processor.go b/Processor/Processor.go index e4558ae1..62a8cd6d 100644 --- a/Processor/Processor.go +++ b/Processor/Processor.go @@ -115,6 +115,7 @@ type OnebotPrivateMessage struct { 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 + RealUserID string `json:"real_user_id,omitempty"` //当前真实uid IsBindedUserId bool `json:"is_binded_user_id,omitempty"` //当前用户号号是否是binded后的 } diff --git a/handlers/send_group_msg.go b/handlers/send_group_msg.go index 17a72838..69b95e58 100644 --- a/handlers/send_group_msg.go +++ b/handlers/send_group_msg.go @@ -318,8 +318,9 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap groupMessage.Timestamp = time.Now().Unix() // 设置时间戳 } + var resp *dto.GroupMessageResponse // 发送组合消息 - resp, err := apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) + resp, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) if err != nil { mylog.Printf("发送组合消息失败: %v", err) } @@ -329,6 +330,12 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap pair.Group = message.Params.GroupID.(string) pair.GroupMessage = groupMessage echo.PushGlobalStack(pair) + } else if err != nil && strings.Contains(err.Error(), `"code":40034025`) { + groupMessage.EventID = "" + resp, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) + if err != nil { + mylog.Printf("发送组合消息失败: %v", err) + } } // 发送成功回执 @@ -351,9 +358,10 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap return "", nil // 或其他错误处理 } + var resp *dto.GroupMessageResponse groupMessage.Timestamp = time.Now().Unix() // 设置时间戳 //重新为err赋值 - resp, err := apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) + resp, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) if err != nil { mylog.Printf("发送文本群组信息失败: %v", err) } @@ -363,6 +371,12 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap pair.Group = message.Params.GroupID.(string) pair.GroupMessage = groupMessage echo.PushGlobalStack(pair) + } else if err != nil && strings.Contains(err.Error(), `"code":40034025`) { + groupMessage.EventID = "" + resp, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) + if err != nil { + mylog.Printf("发送文本群组信息失败: %v", err) + } } //发送成功回执 retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2) @@ -401,7 +415,7 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap return "", nil // 或其他错误处理 } //重新为err赋值 - resp, err := apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) + resp, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) if err != nil { mylog.Printf("发送 MessageToCreate 信息失败: %v", err) } @@ -411,6 +425,14 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap pair.Group = message.Params.GroupID.(string) pair.GroupMessage = groupMessage echo.PushGlobalStack(pair) + } else if err != nil && strings.Contains(err.Error(), `"code":40034025`) { + //请求参数event_id无效 重试 + groupMessage.EventID = "" + //重新为err赋值 + resp, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) + if err != nil { + mylog.Printf("发送 MessageToCreate 信息失败 on code 40034025: %v", err) + } } //发送成功回执 retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2) @@ -442,6 +464,12 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap pair.Group = message.Params.GroupID.(string) pair.GroupMessage = groupMessage echo.PushGlobalStack(pair) + } else if err != nil && strings.Contains(err.Error(), `"code":40034025`) { + groupMessage.EventID = "" + resp, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) + if err != nil { + mylog.Printf("发送文本报错信息失败: %v", err) + } } } } @@ -471,6 +499,12 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap pair.Group = message.Params.GroupID.(string) pair.GroupMessage = groupMessage echo.PushGlobalStack(pair) + } else if err != nil && strings.Contains(err.Error(), `"code":40034025`) { + groupMessage.EventID = "" + resp, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) + if err != nil { + mylog.Printf("发送图片失败: %v", err) + } } } //发送成功回执 diff --git a/httpapi/httpapi.go b/httpapi/httpapi.go index 8692d760..51040268 100644 --- a/httpapi/httpapi.go +++ b/httpapi/httpapi.go @@ -446,11 +446,11 @@ func convertToString(value interface{}) string { func handleDeleteMsg(c *gin.Context, api openapi.OpenAPI, apiV2 openapi.OpenAPI) { // 使用interface{}以适应不同类型的输入,接受动态参数类型 var req struct { - UserID interface{} `json:"user_id,omitempty" form:"user_id"` - GroupID interface{} `json:"group_id,omitempty" form:"group_id"` - ChannelID interface{} `json:"channel_id,omitempty" form:"channel_id"` - GuildID interface{} `json:"guild_id,omitempty" form:"guild_id"` - MessageID interface{} `json:"message_id" form:"message_id"` + UserID string `json:"user_id,omitempty" form:"user_id"` + GroupID string `json:"group_id,omitempty" form:"group_id"` + ChannelID string `json:"channel_id,omitempty" form:"channel_id"` + GuildID string `json:"guild_id,omitempty" form:"guild_id"` + MessageID string `json:"message_id" form:"message_id"` } // 根据请求方法解析参数 @@ -471,19 +471,19 @@ func handleDeleteMsg(c *gin.Context, api openapi.OpenAPI, apiV2 openapi.OpenAPI) // 构造参数内容,只包括实际有值的字段 params := callapi.ParamsContent{} - if req.UserID != nil { + if req.UserID != "" { params.UserID = convertToString(req.UserID) } - if req.GroupID != nil { + if req.GroupID != "" { params.GroupID = convertToString(req.GroupID) } - if req.ChannelID != nil { + if req.ChannelID != "" { params.ChannelID = convertToString(req.ChannelID) } - if req.GuildID != nil { + if req.GuildID != "" { params.GuildID = convertToString(req.GuildID) } - if req.MessageID != nil { + if req.MessageID != "" { params.MessageID = convertToString(req.MessageID) } From e307ca16f56670ca9f747500e3b261bcb19e877e Mon Sep 17 00:00:00 2001 From: cosmo Date: Fri, 24 May 2024 12:36:36 +0800 Subject: [PATCH 09/20] beta407 --- handlers/send_private_msg_sse.go | 13 +- httpapi/httpapi.go | 213 +++++++++++++++++++++---------- structs/structs.go | 8 ++ 3 files changed, 154 insertions(+), 80 deletions(-) diff --git a/handlers/send_private_msg_sse.go b/handlers/send_private_msg_sse.go index 4a2350b2..216394ee 100644 --- a/handlers/send_private_msg_sse.go +++ b/handlers/send_private_msg_sse.go @@ -10,6 +10,7 @@ import ( "github.com/hoshinonyaruko/gensokyo/echo" "github.com/hoshinonyaruko/gensokyo/idmap" "github.com/hoshinonyaruko/gensokyo/mylog" + "github.com/hoshinonyaruko/gensokyo/structs" "github.com/tencent-connect/botgo/dto" "github.com/tencent-connect/botgo/openapi" ) @@ -21,14 +22,6 @@ func init() { callapi.RegisterHandler("send_private_msg_sse", HandleSendPrivateMsgSSE) } -type InterfaceBody struct { - Content string `json:"content"` - State int `json:"state"` - PromptKeyboard []string `json:"prompt_keyboard,omitempty"` - ActionButton int `json:"action_button,omitempty"` - CallbackData string `json:"callback_data,omitempty"` -} - func incrementIndex(msgID string) int { if _, exists := msgIDToIndex[msgID]; !exists { msgIDToIndex[msgID] = 0 // 初始化为0 @@ -108,7 +101,7 @@ func HandleSendPrivateMsgSSE(client callapi.Client, api openapi.OpenAPI, apiv2 o } // 然后,将这个JSON字符串反序列化到InterfaceBody类型的对象中 - var messageBody InterfaceBody + var messageBody structs.InterfaceBody err = json.Unmarshal(messageJSON, &messageBody) if err != nil { fmt.Printf("Error unmarshalling to InterfaceBody: %v\n", err) @@ -164,7 +157,7 @@ func HandleSendPrivateMsgSSE(client callapi.Client, api openapi.OpenAPI, apiv2 o return retmsg, nil } -func generateMessageSSE(body InterfaceBody, msgID, ID string) *dto.MessageSSE { +func generateMessageSSE(body structs.InterfaceBody, msgID, ID string) *dto.MessageSSE { index := incrementIndex(msgID) // 获取并递增Index // 将InterfaceBody的PromptKeyboard转换为MessageSSE的结构 diff --git a/httpapi/httpapi.go b/httpapi/httpapi.go index 51040268..ec562303 100644 --- a/httpapi/httpapi.go +++ b/httpapi/httpapi.go @@ -1,6 +1,7 @@ package httpapi import ( + "encoding/json" "fmt" "net/http" "reflect" @@ -9,6 +10,7 @@ import ( "github.com/hoshinonyaruko/gensokyo/config" "github.com/hoshinonyaruko/gensokyo/handlers" + "github.com/hoshinonyaruko/gensokyo/structs" "github.com/gin-gonic/gin" "github.com/hoshinonyaruko/gensokyo/callapi" @@ -226,51 +228,80 @@ func handleSendPrivateMessage(c *gin.Context, api openapi.OpenAPI, apiV2 openapi // handleSendPrivateMessageSSE 处理发送私聊SSE消息的请求 func handleSendPrivateMessageSSE(c *gin.Context, api openapi.OpenAPI, apiV2 openapi.OpenAPI) { - var retmsg string - var req struct { - GroupID int64 `json:"group_id" form:"group_id"` - UserID int64 `json:"user_id" form:"user_id"` - Message interface{} `json:"message" form:"message"` - AutoEscape bool `json:"auto_escape" form:"auto_escape"` - } - // 根据请求方法解析参数 if c.Request.Method == http.MethodGet { + var req struct { + GroupID int64 `json:"group_id" form:"group_id"` + UserID int64 `json:"user_id" form:"user_id"` + Message string `json:"message" form:"message"` + AutoEscape bool `json:"auto_escape" form:"auto_escape"` + } // 从URL查询参数解析 if err := c.ShouldBindQuery(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } + var InterfaceBody structs.InterfaceBody + if err := json.Unmarshal([]byte(req.Message), &InterfaceBody); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid message format"}) + return + } + + client := &HttpAPIClient{} + // 创建 ActionMessage 实例 + message := callapi.ActionMessage{ + Action: "send_private_msg_sse", + Params: callapi.ParamsContent{ + GroupID: strconv.FormatInt(req.GroupID, 10), // 注意这里需要转换类型,因为 GroupID 是 int64 + UserID: strconv.FormatInt(req.UserID, 10), + Message: InterfaceBody, + }, + } + // 调用处理函数 + retmsg, err := handlers.HandleSendPrivateMsgSSE(client, api, apiV2, message) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } + + // 返回处理结果 + c.Header("Content-Type", "application/json") + c.String(http.StatusOK, retmsg) } else { + var req struct { + GroupID int64 `json:"group_id" form:"group_id"` + UserID int64 `json:"user_id" form:"user_id"` + Message interface{} `json:"message" form:"message"` + AutoEscape bool `json:"auto_escape" form:"auto_escape"` + } // 从JSON或表单数据解析 if err := c.ShouldBind(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } - } - // 使用解析后的参数处理请求 - // 例如:api.SendGroupMessage(req.GroupID, req.Message, req.AutoEscape) - client := &HttpAPIClient{} - // 创建 ActionMessage 实例 - message := callapi.ActionMessage{ - Action: "send_private_msg_sse", - Params: callapi.ParamsContent{ - GroupID: strconv.FormatInt(req.GroupID, 10), // 注意这里需要转换类型,因为 GroupID 是 int64 - UserID: strconv.FormatInt(req.UserID, 10), - Message: req.Message, - }, - } - // 调用处理函数 - retmsg, err := handlers.HandleSendPrivateMsgSSE(client, api, apiV2, message) - if err != nil { - c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) - return + client := &HttpAPIClient{} + // 创建 ActionMessage 实例 + message := callapi.ActionMessage{ + Action: "send_private_msg_sse", + Params: callapi.ParamsContent{ + GroupID: strconv.FormatInt(req.GroupID, 10), // 注意这里需要转换类型,因为 GroupID 是 int64 + UserID: strconv.FormatInt(req.UserID, 10), + Message: req.Message, + }, + } + // 调用处理函数 + retmsg, err := handlers.HandleSendPrivateMsgSSE(client, api, apiV2, message) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } + + // 返回处理结果 + c.Header("Content-Type", "application/json") + c.String(http.StatusOK, retmsg) } - // 返回处理结果 - c.Header("Content-Type", "application/json") - c.String(http.StatusOK, retmsg) } // handleSendGuildChannelMessage 处理发送消频道息的请求 @@ -444,63 +475,105 @@ func convertToString(value interface{}) string { } func handleDeleteMsg(c *gin.Context, api openapi.OpenAPI, apiV2 openapi.OpenAPI) { - // 使用interface{}以适应不同类型的输入,接受动态参数类型 - var req struct { - UserID string `json:"user_id,omitempty" form:"user_id"` - GroupID string `json:"group_id,omitempty" form:"group_id"` - ChannelID string `json:"channel_id,omitempty" form:"channel_id"` - GuildID string `json:"guild_id,omitempty" form:"guild_id"` - MessageID string `json:"message_id" form:"message_id"` - } - - // 根据请求方法解析参数 + // 根据请求方法解析参数 GET if c.Request.Method == http.MethodGet { + var req struct { + UserID string `json:"user_id,omitempty" form:"user_id"` + GroupID string `json:"group_id,omitempty" form:"group_id"` + ChannelID string `json:"channel_id,omitempty" form:"channel_id"` + GuildID string `json:"guild_id,omitempty" form:"guild_id"` + MessageID string `json:"message_id" form:"message_id"` + } // 从URL查询参数解析 if err := c.ShouldBindQuery(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } + // 构造参数内容,只包括实际有值的字段 + params := callapi.ParamsContent{} + + if req.UserID != "" { + params.UserID = req.UserID + } + if req.GroupID != "" { + params.GroupID = req.GroupID + } + if req.ChannelID != "" { + params.ChannelID = req.ChannelID + } + if req.GuildID != "" { + params.GuildID = req.GuildID + } + if req.MessageID != "" { + params.MessageID = req.MessageID + } + + // 创建 ActionMessage 实例 + message := callapi.ActionMessage{ + Action: "delete_msg", + Params: params, + } + + // 调用处理函数,假设 handlers.DeleteMsg 已经实现并且适合处理消息删除的操作 + client := &HttpAPIClient{} + retmsg, err := handlers.DeleteMsg(client, api, apiV2, message) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } + + // 返回处理结果 + c.JSON(http.StatusOK, gin.H{"message": retmsg}) } else { + // 根据请求方法解析参数 POST + // 使用interface{}以适应不同类型的输入,接受动态参数类型 + var req struct { + UserID interface{} `json:"user_id,omitempty" form:"user_id"` + GroupID interface{} `json:"group_id,omitempty" form:"group_id"` + ChannelID interface{} `json:"channel_id,omitempty" form:"channel_id"` + GuildID interface{} `json:"guild_id,omitempty" form:"guild_id"` + MessageID interface{} `json:"message_id" form:"message_id"` + } // 从JSON或表单数据解析 if err := c.ShouldBind(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } - } + // 构造参数内容,只包括实际有值的字段 + params := callapi.ParamsContent{} - // 构造参数内容,只包括实际有值的字段 - params := callapi.ParamsContent{} + if req.UserID != nil { + params.UserID = convertToString(req.UserID) + } + if req.GroupID != nil { + params.GroupID = convertToString(req.GroupID) + } + if req.ChannelID != nil { + params.ChannelID = convertToString(req.ChannelID) + } + if req.GuildID != nil { + params.GuildID = convertToString(req.GuildID) + } + if req.MessageID != nil { + params.MessageID = convertToString(req.MessageID) + } - if req.UserID != "" { - params.UserID = convertToString(req.UserID) - } - if req.GroupID != "" { - params.GroupID = convertToString(req.GroupID) - } - if req.ChannelID != "" { - params.ChannelID = convertToString(req.ChannelID) - } - if req.GuildID != "" { - params.GuildID = convertToString(req.GuildID) - } - if req.MessageID != "" { - params.MessageID = convertToString(req.MessageID) - } + // 创建 ActionMessage 实例 + message := callapi.ActionMessage{ + Action: "delete_msg", + Params: params, + } - // 创建 ActionMessage 实例 - message := callapi.ActionMessage{ - Action: "delete_msg", - Params: params, - } + // 调用处理函数,假设 handlers.DeleteMsg 已经实现并且适合处理消息删除的操作 + client := &HttpAPIClient{} + retmsg, err := handlers.DeleteMsg(client, api, apiV2, message) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } - // 调用处理函数,假设 handlers.DeleteMsg 已经实现并且适合处理消息删除的操作 - client := &HttpAPIClient{} - retmsg, err := handlers.DeleteMsg(client, api, apiV2, message) - if err != nil { - c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) - return + // 返回处理结果 + c.JSON(http.StatusOK, gin.H{"message": retmsg}) } - // 返回处理结果 - c.JSON(http.StatusOK, gin.H{"message": retmsg}) } diff --git a/structs/structs.go b/structs/structs.go index 7786e831..5c47d640 100644 --- a/structs/structs.go +++ b/structs/structs.go @@ -182,3 +182,11 @@ type VisualPrefixConfig struct { WhiteList []string `yaml:"whiteList"` NoWhiteResponse string `yaml:"No_White_Response"` } + +type InterfaceBody struct { + Content string `json:"content"` + State int `json:"state"` + PromptKeyboard []string `json:"prompt_keyboard,omitempty"` + ActionButton int `json:"action_button,omitempty"` + CallbackData string `json:"callback_data,omitempty"` +} From 52260917b41d43bde796f50f4b8e62144f225cf9 Mon Sep 17 00:00:00 2001 From: cosmo Date: Sun, 26 May 2024 12:46:33 +0800 Subject: [PATCH 10/20] beta408 --- botgo/go.mod | 124 ++++++++++++++- botgo/go.sum | 162 ++++++++++++++++++++ botgo/interaction/search/simulate_search.go | 2 +- config/config.go | 12 ++ handlers/send_group_msg.go | 63 +++++++- idmap/service.go | 7 +- mylog/errlog.go | 57 +++++++ structs/structs.go | 1 + template/config_template.go | 1 + 9 files changed, 420 insertions(+), 9 deletions(-) create mode 100644 mylog/errlog.go diff --git a/botgo/go.mod b/botgo/go.mod index 34d76325..01816b58 100644 --- a/botgo/go.mod +++ b/botgo/go.mod @@ -1,13 +1,129 @@ module github.com/tencent-connect/botgo -go 1.16 +go 1.21.1 require ( github.com/go-redis/redis/v8 v8.11.5 github.com/go-resty/resty/v2 v2.6.0 - github.com/google/uuid v1.3.1 + github.com/google/uuid v1.6.0 github.com/gorilla/websocket v1.4.2 - github.com/stretchr/testify v1.7.0 + github.com/hoshinonyaruko/gensokyo v0.0.0-20240524044114-62dbc304940b + github.com/stretchr/testify v1.9.0 github.com/tidwall/gjson v1.9.3 - gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c + gopkg.in/yaml.v3 v3.0.1 +) + +require ( + dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9 // indirect + github.com/Baidu-AIP/golang-sdk v1.1.1 // indirect + github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802 // indirect + github.com/HdrHistogram/hdrhistogram-go v1.1.2 // indirect + github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409 // indirect + github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af // indirect + github.com/aliyun/alibaba-cloud-sdk-go v1.62.645 // indirect + github.com/aliyun/aliyun-oss-go-sdk v3.0.1+incompatible // indirect + github.com/baidubce/bce-sdk-go v0.9.161 // indirect + github.com/bytedance/sonic v1.9.1 // indirect + github.com/cespare/xxhash/v2 v2.1.2 // indirect + github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect + github.com/chzyer/logex v1.1.10 // indirect + github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect + github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 // indirect + github.com/clbanning/mxj v1.8.4 // indirect + github.com/creack/pty v1.1.9 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect + github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect + github.com/fatih/color v1.15.0 // indirect + github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90 // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect + github.com/gabriel-vasile/mimetype v1.4.2 // indirect + github.com/gin-contrib/sse v0.1.0 // indirect + github.com/gin-gonic/gin v1.9.1 // indirect + github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1 // indirect + github.com/go-ole/go-ole v1.2.6 // indirect + github.com/go-playground/assert/v2 v2.2.0 // indirect + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect + github.com/go-playground/validator/v10 v10.14.0 // indirect + github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect + github.com/goccy/go-json v0.10.2 // indirect + github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d // indirect + github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect + github.com/golang/protobuf v1.5.2 // indirect + github.com/google/go-cmp v0.5.6 // indirect + github.com/google/go-querystring v1.0.0 // indirect + github.com/google/gofuzz v1.0.0 // indirect + github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect + github.com/hashicorp/errwrap v1.0.0 // indirect + github.com/hashicorp/go-multierror v1.1.1 // indirect + github.com/hpcloud/tail v1.0.0 // indirect + github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639 // indirect + github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5 // indirect + github.com/klauspost/cpuid/v2 v2.2.4 // indirect + github.com/kr/pty v1.1.1 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/leodido/go-urn v1.2.4 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mitchellh/mapstructure v1.4.3 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/mozillazg/go-httpheader v0.2.1 // indirect + github.com/mvdan/xurls v1.1.0 // indirect + github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect + github.com/nxadm/tail v1.4.8 // indirect + github.com/onsi/ginkgo v1.16.5 // indirect + github.com/onsi/ginkgo/v2 v2.0.0 // indirect + github.com/onsi/gomega v1.18.1 // indirect + github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect + github.com/pelletier/go-toml/v2 v2.0.8 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/shirou/gopsutil v3.21.11+incompatible // indirect + github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect + github.com/stretchr/objx v0.5.2 // indirect + github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.563 // indirect + github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.563 // indirect + github.com/tencentyun/cos-go-sdk-v5 v0.7.45 // indirect + github.com/tidwall/match v1.1.1 // indirect + github.com/tidwall/pretty v1.2.0 // indirect + github.com/tklauser/go-sysconf v0.3.12 // indirect + github.com/tklauser/numcpus v0.6.1 // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect + github.com/uber/jaeger-lib v2.4.1+incompatible // indirect + github.com/ugorji/go/codec v1.2.11 // indirect + github.com/yuin/goldmark v1.4.13 // indirect + github.com/yusufpapurcu/wmi v1.2.3 // indirect + go.etcd.io/bbolt v1.3.9 // indirect + go.etcd.io/gofail v0.1.0 // indirect + go.uber.org/atomic v1.9.0 // indirect + golang.org/x/arch v0.3.0 // indirect + golang.org/x/crypto v0.9.0 // indirect + golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136 // indirect + golang.org/x/image v0.0.0-20190802002840-cff245a6509b // indirect + golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028 // indirect + golang.org/x/mod v0.8.0 // indirect + golang.org/x/net v0.10.0 // indirect + golang.org/x/sync v0.5.0 // indirect + golang.org/x/sys v0.13.0 // indirect + golang.org/x/term v0.8.0 // indirect + golang.org/x/text v0.9.0 // indirect + golang.org/x/time v0.5.0 // indirect + golang.org/x/tools v0.6.0 // indirect + golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect + gonum.org/v1/gonum v0.8.2 // indirect + gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0 // indirect + gonum.org/v1/plot v0.0.0-20190515093506-e2840ee46a6b // indirect + google.golang.org/protobuf v1.32.0 // indirect + gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect + gopkg.in/fsnotify.v1 v1.4.7 // indirect + gopkg.in/ini.v1 v1.66.2 // indirect + gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + mvdan.cc/xurls v1.1.0 // indirect + rsc.io/pdf v0.1.1 // indirect ) diff --git a/botgo/go.sum b/botgo/go.sum index 4f951cd4..36a31f95 100644 --- a/botgo/go.sum +++ b/botgo/go.sum @@ -1,21 +1,61 @@ +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +github.com/Baidu-AIP/golang-sdk v1.1.1/go.mod h1:bXnGw7xPeKt8aF7UCELKrV6UZ/46spItONK1RQBQj1Y= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/HdrHistogram/hdrhistogram-go v1.1.2/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo= +github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mod h1:1pk82RBxDY/JZnPQrtqHlUFfCctgdorsd9M06fMynOM= +github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= +github.com/aliyun/alibaba-cloud-sdk-go v1.62.645/go.mod h1:CJJYa1ZMxjlN/NbXEwmejEnBkhi0DV+Yb3B2lxf+74o= +github.com/aliyun/aliyun-oss-go-sdk v3.0.1+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8= +github.com/baidubce/bce-sdk-go v0.9.161/go.mod h1:zbYJMQwE4IZuyrJiFO8tO8NbtYiKTFTbwh4eIsqjVdg= +github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= +github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= +github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= +github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= +github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/clbanning/mxj v1.8.4/go.mod h1:BVjHeAH+rl9rs6f+QIpeRl0tfu10SXn1pUSa5PVGJng= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= +github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= +github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= +github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= +github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= +github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= +github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= +github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= github.com/go-resty/resty/v2 v2.6.0 h1:joIR5PNLM2EFqqESUjCMGXrWmXNHEU9CEiK813oKYS4= github.com/go-resty/resty/v2 v2.6.0/go.mod h1:PwvJS6hvaPkjtjNg9ph+VrSD92bi5Zq73w/BIH7cC3Q= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= +github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= @@ -28,14 +68,53 @@ github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= +github.com/hoshinonyaruko/gensokyo v0.0.0-20240524044114-62dbc304940b h1:M4uhkrXY44kliM2SvJVlM/g/TtBMYlL+zi+NoieLXdc= +github.com/hoshinonyaruko/gensokyo v0.0.0-20240524044114-62dbc304940b/go.mod h1:rY3d8D1vUQ6o0U/r4tuEHcpwvFC1QDR5x1jEm6FuDFQ= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= +github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= +github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= +github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/mozillazg/go-httpheader v0.2.1/go.mod h1:jJ8xECTlalr6ValeXYdOF8fFUISeBAdw6E61aqQma60= +github.com/mvdan/xurls v1.1.0/go.mod h1:tQlNn3BED8bE/15hnSL2HLkDeLWpNPAwtw7wkEq44oU= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= @@ -50,23 +129,73 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE= github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs= +github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b/go.mod h1:AC62GU6hc0BrNm+9RK9VSiwa/EUe1bkIeFORAMcHvJU= +github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= +github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= +github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.563/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.563/go.mod h1:uom4Nvi9W+Qkom0exYiJ9VWJjXwyxtPYTkKkaLMlfE0= +github.com/tencentyun/cos-go-sdk-v5 v0.7.45/go.mod h1:DH9US8nB+AJXqwu/AMOrCFN1COv3dpytXuJWHgdg7kE= github.com/tidwall/gjson v1.9.3 h1:hqzS9wAHMO+KVBBkLxYdkEeeFHuqr95GfClRLKlgK0E= github.com/tidwall/gjson v1.9.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= +github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= +github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= +github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= +github.com/uber/jaeger-client-go v2.30.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk= +github.com/uber/jaeger-lib v2.4.1+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U= +github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= +github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +go.etcd.io/bbolt v1.3.9/go.mod h1:zaO32+Ti0PK1ivdPtgMESzuzL2VPoIG1PCQNvOdo/dE= +go.etcd.io/gofail v0.1.0/go.mod h1:VZBCXYGZhHAinaBiiqYvuDynvahNsAyLFwB3kEHKz1M= +go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= +golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= +golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= +golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -75,13 +204,18 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 h1:DzZ89McO9/gWPsQXS/FVKAlG02ZjaQ6AlZRBimEYOd0= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= +golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -93,18 +227,37 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190206041539-40960b6deb8e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gonum.org/v1/gonum v0.0.0-20180816165407-929014505bf4/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo= +gonum.org/v1/gonum v0.8.2/go.mod h1:oe/vMfY3deqTw+1EZJhuvEW2iwGF1bW9wwu7XCu0+v0= +gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw= +gonum.org/v1/plot v0.0.0-20190515093506-e2840ee46a6b/go.mod h1:Wt8AAjI+ypCyYX3nZBvf6cAIx93T+c/OS2HFAYskSZc= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -113,9 +266,13 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= +google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= @@ -125,3 +282,8 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +mvdan.cc/xurls v1.1.0/go.mod h1:TNWuhvo+IqbUCmtUIb/3LJSQdrzel8loVpgFm0HikbI= +rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/botgo/interaction/search/simulate_search.go b/botgo/interaction/search/simulate_search.go index 9b13f03f..05bd454e 100644 --- a/botgo/interaction/search/simulate_search.go +++ b/botgo/interaction/search/simulate_search.go @@ -30,7 +30,7 @@ func SimulateSearch(config *Config, keyword string) (*dto.SearchRsp, error) { Name: "search", Type: dto.InteractionDataTypeChatSearch, } - interactionData.Resolved, _ = json.Marshal(dto.SearchInputResolved{Keyword: keyword}) + //interactionData.Resolved, _ = json.Marshal(dto.SearchInputResolved{Keyword: keyword}) interaction := &dto.Interaction{ ApplicationID: config.AppID, Type: dto.InteractionTypeCommand, diff --git a/config/config.go b/config/config.go index 5eb2fe50..d6abf063 100644 --- a/config/config.go +++ b/config/config.go @@ -1163,6 +1163,18 @@ func GetSendError() bool { return instance.Settings.SendError } +// 获取GetSaveError的值 +func GetSaveError() bool { + mu.Lock() + defer mu.Unlock() + + if instance == nil { + mylog.Println("Warning: instance is nil when trying to GetSaveError value.") + return true + } + return instance.Settings.SaveError +} + // 获取GetAddAtGroup的值 func GetAddAtGroup() bool { mu.Lock() diff --git a/handlers/send_group_msg.go b/handlers/send_group_msg.go index 69b95e58..ed826a72 100644 --- a/handlers/send_group_msg.go +++ b/handlers/send_group_msg.go @@ -323,6 +323,12 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap resp, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) if err != nil { mylog.Printf("发送组合消息失败: %v", err) + // 错误保存到本地 + if config.GetSaveError() { + mylog.ErrLogToFile("type", "PostGroupMessage") + mylog.ErrInterfaceToFile("request", groupMessage) + mylog.ErrLogToFile("error", err.Error()) + } } if err != nil && strings.Contains(err.Error(), `"code":22009`) { mylog.Printf("信息发送失败,加入到队列中,下次被动信息进行发送") @@ -335,6 +341,12 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap resp, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) if err != nil { mylog.Printf("发送组合消息失败: %v", err) + // 错误保存到本地 + if config.GetSaveError() { + mylog.ErrLogToFile("type", "PostGroupMessage") + mylog.ErrInterfaceToFile("request", groupMessage) + mylog.ErrLogToFile("error", err.Error()) + } } } @@ -364,6 +376,12 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap resp, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) if err != nil { mylog.Printf("发送文本群组信息失败: %v", err) + // 错误保存到本地 + if config.GetSaveError() { + mylog.ErrLogToFile("type", "PostGroupMessage") + mylog.ErrInterfaceToFile("request", groupMessage) + mylog.ErrLogToFile("error", err.Error()) + } } if err != nil && strings.Contains(err.Error(), `"code":22009`) { mylog.Printf("信息发送失败,加入到队列中,下次被动信息进行发送") @@ -376,6 +394,12 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap resp, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) if err != nil { mylog.Printf("发送文本群组信息失败: %v", err) + // 错误保存到本地 + if config.GetSaveError() { + mylog.ErrLogToFile("type", "PostGroupMessage") + mylog.ErrInterfaceToFile("request", groupMessage) + mylog.ErrLogToFile("error", err.Error()) + } } } //发送成功回执 @@ -418,6 +442,12 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap resp, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) if err != nil { mylog.Printf("发送 MessageToCreate 信息失败: %v", err) + // 错误保存到本地 + if config.GetSaveError() { + mylog.ErrLogToFile("type", "PostGroupMessage") + mylog.ErrInterfaceToFile("request", groupMessage) + mylog.ErrLogToFile("error", err.Error()) + } } if err != nil && strings.Contains(err.Error(), `"code":22009`) { mylog.Printf("信息发送失败,加入到队列中,下次被动信息进行发送") @@ -432,6 +462,12 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap resp, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) if err != nil { mylog.Printf("发送 MessageToCreate 信息失败 on code 40034025: %v", err) + // 错误保存到本地 + if config.GetSaveError() { + mylog.ErrLogToFile("type", "PostGroupMessage") + mylog.ErrInterfaceToFile("request", groupMessage) + mylog.ErrLogToFile("error", err.Error()) + } } } //发送成功回执 @@ -442,7 +478,8 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap message_return, err := apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), richMediaMessage) if err != nil { mylog.Printf("发送 %s 信息失败_send_group_msg: %v", key, err) - if config.GetSendError() { //把报错当作文本发出去 + //把报错当作文本发出去 + if config.GetSendError() { msgseq := echo.GetMappingSeq(messageID) echo.AddMappingSeq(messageID, msgseq+1) groupReply := generateGroupMessage(messageID, eventID, nil, err.Error(), msgseq+1, apiv2, message.Params.GroupID.(string)) @@ -472,6 +509,12 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap } } } + // 错误保存到本地 + if config.GetSaveError() { + mylog.ErrLogToFile("type", "PostGroupMessage") + mylog.ErrInterfaceToFile("request", richMediaMessage) + mylog.ErrLogToFile("error", err.Error()) + } } if message_return != nil && message_return.MediaResponse != nil && message_return.MediaResponse.FileInfo != "" { msgseq := echo.GetMappingSeq(messageID) @@ -492,6 +535,12 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap resp, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) if err != nil { mylog.Printf("发送图片失败: %v", err) + // 错误保存到本地 + if config.GetSaveError() { + mylog.ErrLogToFile("type", "PostGroupMessage") + mylog.ErrInterfaceToFile("request", groupMessage) + mylog.ErrLogToFile("error", err.Error()) + } } if err != nil && strings.Contains(err.Error(), `"code":22009`) { mylog.Printf("信息发送失败,加入到队列中,下次被动信息进行发送") @@ -1290,6 +1339,12 @@ func uploadMedia(ctx context.Context, groupID string, richMediaMessage *dto.Rich // 调用API来上传媒体 messageReturn, err := apiv2.PostGroupMessage(ctx, groupID, richMediaMessage) if err != nil { + // 错误保存到本地 + if config.GetSaveError() { + mylog.ErrLogToFile("type", "PostGroupMessage") + mylog.ErrInterfaceToFile("request", richMediaMessage) + mylog.ErrLogToFile("error", err.Error()) + } return "", err } // 返回上传后的FileInfo @@ -1313,6 +1368,12 @@ func SendStackMessages(apiv2 openapi.OpenAPI, messageid string, GroupID string) _, err := apiv2.PostGroupMessage(context.TODO(), pair.Group, pair.GroupMessage) if err != nil { mylog.Printf("发送组合消息失败: %v", err) + // 错误保存到本地 + if config.GetSaveError() { + mylog.ErrLogToFile("type", "PostGroupMessage") + mylog.ErrInterfaceToFile("request", pair.GroupMessage) + mylog.ErrLogToFile("error", err.Error()) + } } else { echo.RemoveFromGlobalStack(i) } diff --git a/idmap/service.go b/idmap/service.go index c080f83f..8bba4d9a 100644 --- a/idmap/service.go +++ b/idmap/service.go @@ -74,6 +74,7 @@ func InitializeDB() { func CloseDB() { db.Close() } + func GenerateRowID(id string, length int) (int64, error) { // 计算MD5哈希值 hasher := md5.New() @@ -89,13 +90,13 @@ func GenerateRowID(id string, length int) (int64, error) { } digits := digitsBuilder.String() - // 取出需要长度的数字 + // 取出需要长度的数字或补足0 var rowIDStr string if len(digits) >= length { rowIDStr = digits[:length] } else { - // 如果数字不足指定长度,返回错误 - return 0, fmt.Errorf("not enough digits in MD5 hash") + // 补足0到右侧 + rowIDStr = digits + strings.Repeat("0", length-len(digits)) } // 将数字字符串转换为int64 diff --git a/mylog/errlog.go b/mylog/errlog.go new file mode 100644 index 00000000..64991653 --- /dev/null +++ b/mylog/errlog.go @@ -0,0 +1,57 @@ +package mylog + +import ( + "encoding/json" + "fmt" + "log" + "os" + "time" +) + +// 独立的错误日志记录函数 +func ErrLogToFile(level, message string) { + if !enableFileLogGlobal { + return + } + filename := time.Now().Format("2006-01-02") + "-error.log" + filepath := logPath + "/" + filename + + file, err := os.OpenFile(filepath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + fmt.Println("Error opening log file:", err) + return + } + defer file.Close() + + logEntry := fmt.Sprintf("[%s] %s: %s\n", time.Now().Format("2006-01-02T15:04:05"), level, message) + if _, err := file.WriteString(logEntry); err != nil { + fmt.Println("Error writing to log file:", err) + } +} + +// 独立的错误日志记录函数 +func ErrInterfaceToFile(level, message interface{}) { + if !enableFileLogGlobal { + return + } + filename := time.Now().Format("2006-01-02") + "-error.log" + filepath := logPath + "/" + filename + + file, err := os.OpenFile(filepath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + fmt.Println("Error opening log file:", err) + return + } + defer file.Close() + + jsonData, err := json.Marshal(message) + if err != nil { + log.Printf("Error marshaling data for log: %s", err) + return + } + + logEntry := fmt.Sprintf("[%s] %s: %s\n", time.Now().Format("2006-01-02T15:04:05"), level, string(jsonData)) + if _, err := file.WriteString(logEntry); err != nil { + fmt.Println("Error writing to log file:", err) + } +} diff --git a/structs/structs.go b/structs/structs.go index 5c47d640..6d231da7 100644 --- a/structs/structs.go +++ b/structs/structs.go @@ -100,6 +100,7 @@ type Settings struct { SandBoxMode bool `yaml:"sandbox_mode"` DevMessgeID bool `yaml:"dev_message_id"` SendError bool `yaml:"send_error"` + SaveError bool `yaml:"save_error"` //增长营销类 SelfIntroduce []string `yaml:"self_introduce"` //api修改 diff --git a/template/config_template.go b/template/config_template.go index 37c3e312..8cefb04b 100644 --- a/template/config_template.go +++ b/template/config_template.go @@ -132,6 +132,7 @@ settings: sandbox_mode : false #默认false 如果你只希望沙箱频道使用,请改为true dev_message_id : false #在沙盒和测试环境使用无限制msg_id 仅沙盒有效,正式环境请关闭,内测结束后,tx侧未来会移除 send_error : true #将报错用文本发出,避免机器人被审核报无响应 + save_error : false #将保存保存在log文件夹,方便开发者定位发送错误. #增长营销类(推荐gensokyo-broadcast项目) self_introduce : ["",""] #自我介绍,可设置多个随机发送,当不为空时,机器人被邀入群会发送自定义自我介绍 需手动添加新textintent - "GroupAddRobotEventHandler" - "GroupDelRobotEventHandler" From 124c4784a56d0ff16f57bc0447d8d46d0704f469 Mon Sep 17 00:00:00 2001 From: cosmo Date: Sun, 26 May 2024 12:50:47 +0800 Subject: [PATCH 11/20] beta409 --- go.mod | 3 +- go.sum | 86 ++++------------------------------------------------------ 2 files changed, 7 insertions(+), 82 deletions(-) diff --git a/go.mod b/go.mod index df8ad2a7..f50fa170 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/fatih/color v1.15.0 github.com/fsnotify/fsnotify v1.7.0 github.com/gin-gonic/gin v1.9.1 - github.com/google/uuid v1.4.0 + github.com/google/uuid v1.6.0 github.com/gorilla/websocket v1.4.2 github.com/shirou/gopsutil v3.21.11+incompatible github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e @@ -28,7 +28,6 @@ require ( github.com/mattn/go-colorable v0.1.13 // indirect github.com/mitchellh/mapstructure v1.4.3 // indirect github.com/mozillazg/go-httpheader v0.2.1 // indirect - github.com/mvdan/xurls v1.1.0 // indirect github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect diff --git a/go.sum b/go.sum index 7ba6f44c..364603e8 100644 --- a/go.sum +++ b/go.sum @@ -14,13 +14,9 @@ github.com/baidubce/bce-sdk-go v0.9.161/go.mod h1:zbYJMQwE4IZuyrJiFO8tO8NbtYiKTF github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= -github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= -github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= -github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= -github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/clbanning/mxj v1.8.4 h1:HuhwZtbyvyOw+3Z1AowPkU87JkJUSv751ELWaiTpj8I= github.com/clbanning/mxj v1.8.4/go.mod h1:BVjHeAH+rl9rs6f+QIpeRl0tfu10SXn1pUSa5PVGJng= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= @@ -28,12 +24,9 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= -github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= @@ -53,45 +46,27 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= -github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= github.com/go-resty/resty/v2 v2.6.0 h1:joIR5PNLM2EFqqESUjCMGXrWmXNHEU9CEiK813oKYS4= github.com/go-resty/resty/v2 v2.6.0/go.mod h1:PwvJS6hvaPkjtjNg9ph+VrSD92bi5Zq73w/BIH7cC3Q= -github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= -github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= -github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= @@ -126,17 +101,6 @@ github.com/mvdan/xurls v1.1.0 h1:OpuDelGQ1R1ueQ6sSryzi6P+1RtBpfQHM8fJwlE45ww= github.com/mvdan/xurls v1.1.0/go.mod h1:tQlNn3BED8bE/15hnSL2HLkDeLWpNPAwtw7wkEq44oU= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= -github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= -github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= -github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= -github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= -github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= -github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= -github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= -github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs= github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b h1:FfH+VrHHk6Lxt9HdVS0PXzSXFyS2NbZKXv33FYPol0A= github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b/go.mod h1:AC62GU6hc0BrNm+9RK9VSiwa/EUe1bkIeFORAMcHvJU= github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= @@ -153,14 +117,14 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.563/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.563/go.mod h1:uom4Nvi9W+Qkom0exYiJ9VWJjXwyxtPYTkKkaLMlfE0= github.com/tencentyun/cos-go-sdk-v5 v0.7.45 h1:5/ZGOv846tP6+2X7w//8QjLgH2KcUK+HciFbfjWquFU= @@ -183,7 +147,6 @@ github.com/uber/jaeger-lib v2.4.1+incompatible h1:td4jdvLcExb4cBISKIpHuGoVXh+dVK github.com/uber/jaeger-lib v2.4.1+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U= github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= -github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= go.etcd.io/bbolt v1.3.9 h1:8x7aARPEXiXbHmtUwAIv7eV2fQFHrLLavdiJ3uzJXoI= @@ -195,8 +158,6 @@ golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -209,37 +170,20 @@ golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMx golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= -golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -250,7 +194,6 @@ golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= @@ -259,10 +202,7 @@ golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190206041539-40960b6deb8e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -270,27 +210,13 @@ gonum.org/v1/gonum v0.0.0-20180816165407-929014505bf4/go.mod h1:Y+Yx5eoAFn32cQvJ gonum.org/v1/gonum v0.8.2/go.mod h1:oe/vMfY3deqTw+1EZJhuvEW2iwGF1bW9wwu7XCu0+v0= gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw= gonum.org/v1/plot v0.0.0-20190515093506-e2840ee46a6b/go.mod h1:Wt8AAjI+ypCyYX3nZBvf6cAIx93T+c/OS2HFAYskSZc= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/ini.v1 v1.66.2 h1:XfR1dOYubytKy4Shzc2LHrrGhU0lDCfDGG1yLPmpgsI= gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= From d51e128ac2e705726a473e9c030170299183eb9b Mon Sep 17 00:00:00 2001 From: cosmo Date: Sun, 26 May 2024 17:41:16 +0800 Subject: [PATCH 12/20] beta410 --- handlers/send_group_msg.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlers/send_group_msg.go b/handlers/send_group_msg.go index ed826a72..f23084da 100644 --- a/handlers/send_group_msg.go +++ b/handlers/send_group_msg.go @@ -510,7 +510,7 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap } } // 错误保存到本地 - if config.GetSaveError() { + if err != nil && config.GetSaveError() { mylog.ErrLogToFile("type", "PostGroupMessage") mylog.ErrInterfaceToFile("request", richMediaMessage) mylog.ErrLogToFile("error", err.Error()) From 14846932ad0d9f868c423a5115f6d8a304862940 Mon Sep 17 00:00:00 2001 From: cosmo Date: Tue, 28 May 2024 19:13:10 +0800 Subject: [PATCH 13/20] beta411 --- main.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index dc2218c3..1f3674c7 100644 --- a/main.go +++ b/main.go @@ -182,19 +182,21 @@ func main() { } else { log.Printf("自定义ac地址模式...请从日志手动获取bot的真实id并设置,不然at会不正常") } + + // 创建webui数据库 + webui.InitializeDB() + defer webui.CloseDB() + if !nologin { //创建idmap服务器 数据库 idmap.InitializeDB() //创建botstats数据库 botstats.InitializeDB() - //创建webui数据库 - webui.InitializeDB() //关闭时候释放数据库 defer idmap.CloseDB() defer botstats.CloseDB() - defer webui.CloseDB() if configURL == "" && !fix11300 { //初始化handlers handlers.BotID = me.ID From 0733b4ff2fe3a111e33a102fcd28657241ed2ecc Mon Sep 17 00:00:00 2001 From: cosmo Date: Tue, 28 May 2024 20:31:07 +0800 Subject: [PATCH 14/20] beta412 --- main.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 1f3674c7..1fbe134b 100644 --- a/main.go +++ b/main.go @@ -116,6 +116,10 @@ func main() { loggerAdapter := mylog.NewMyLogAdapter(logLevel, config.GetSaveLogs()) botgo.SetLogger(loggerAdapter) + // 创建webui数据库 + webui.InitializeDB() + defer webui.CloseDB() + if conf.Settings.AppID == 12345 { // 输出天蓝色文本 cyan := color.New(color.FgCyan) @@ -183,12 +187,7 @@ func main() { log.Printf("自定义ac地址模式...请从日志手动获取bot的真实id并设置,不然at会不正常") } - // 创建webui数据库 - webui.InitializeDB() - defer webui.CloseDB() - if !nologin { - //创建idmap服务器 数据库 idmap.InitializeDB() //创建botstats数据库 From ee4af967e5936e76bc2fbfd6da9bc15e8fbd4cd8 Mon Sep 17 00:00:00 2001 From: cosmo Date: Wed, 29 May 2024 13:20:32 +0800 Subject: [PATCH 15/20] beta413 --- handlers/send_private_msg.go | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/handlers/send_private_msg.go b/handlers/send_private_msg.go index 8ec6fcc0..7c0923cc 100644 --- a/handlers/send_private_msg.go +++ b/handlers/send_private_msg.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "strconv" + "strings" "time" "github.com/hoshinonyaruko/gensokyo/callapi" @@ -265,6 +266,60 @@ func HandleSendPrivateMsg(client callapi.Client, api openapi.OpenAPI, apiv2 open richMediaMessage, ok := groupReply.(*dto.RichMediaMessage) if !ok { mylog.Printf("Error: Expected RichMediaMessage type for key %s.", key) + // 定义一个map来存储关键字 + keyMap := map[string]bool{ + "markdown": true, + "qqmusic": true, + "local_image": true, + "local_record": true, + "url_image": true, + "url_images": true, + "base64_record": true, + "base64_image": true, + } + // key是 for key, urls := range foundItems { 这里的key + if _, exists := keyMap[key]; exists { + // 进行类型断言 + groupMessage, ok := groupReply.(*dto.MessageToCreate) + if !ok { + mylog.Println("Error: Expected MessageToCreate type.") + return "", nil // 或其他错误处理 + } + //重新为err赋值 + resp, err = apiv2.PostC2CMessage(context.TODO(), UserID, groupMessage) + if err != nil { + mylog.Printf("发送 MessageToCreate 私聊信息失败: %v", err) + // 错误保存到本地 + if config.GetSaveError() { + mylog.ErrLogToFile("type", "PostGroupMessage") + mylog.ErrInterfaceToFile("request", groupMessage) + mylog.ErrLogToFile("error", err.Error()) + } + } + if err != nil && strings.Contains(err.Error(), `"code":22009`) { + mylog.Printf("私信主动转被动待实现") + // var pair echo.MessageGroupPair + // pair.Group = message.Params.GroupID.(string) + // pair.GroupMessage = groupMessage + // echo.PushGlobalStack(pair) + } else if err != nil && strings.Contains(err.Error(), `"code":40034025`) { + //请求参数event_id无效 重试 + groupMessage.EventID = "" + //重新为err赋值 + resp, err = apiv2.PostC2CMessage(context.TODO(), UserID, groupMessage) + if err != nil { + mylog.Printf("发送 MessageToCreate 私聊信息失败 on code 40034025: %v", err) + // 错误保存到本地 + if config.GetSaveError() { + mylog.ErrLogToFile("type", "PostGroupMessage") + mylog.ErrInterfaceToFile("request", groupMessage) + mylog.ErrLogToFile("error", err.Error()) + } + } + } + //发送成功回执 + retmsg, _ = SendC2CResponse(client, err, &message, resp) + } continue // 跳过这个项,继续下一个 } message_return, err := apiv2.PostC2CMessage(context.TODO(), UserID, richMediaMessage) From 5bdffb83995dc87ce9224064c2c506c421c27d33 Mon Sep 17 00:00:00 2001 From: cosmo Date: Wed, 29 May 2024 16:03:26 +0800 Subject: [PATCH 16/20] beta414 --- handlers/send_private_msg_sse.go | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/handlers/send_private_msg_sse.go b/handlers/send_private_msg_sse.go index 216394ee..44cbe02c 100644 --- a/handlers/send_private_msg_sse.go +++ b/handlers/send_private_msg_sse.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "sync" "github.com/hoshinonyaruko/gensokyo/callapi" "github.com/hoshinonyaruko/gensokyo/config" @@ -15,36 +16,34 @@ import ( "github.com/tencent-connect/botgo/openapi" ) -var msgIDToIndex = make(map[string]int) -var msgIDToRelatedID = make(map[string]string) +var msgIDToIndex sync.Map +var msgIDToRelatedID sync.Map func init() { callapi.RegisterHandler("send_private_msg_sse", HandleSendPrivateMsgSSE) } func incrementIndex(msgID string) int { - if _, exists := msgIDToIndex[msgID]; !exists { - msgIDToIndex[msgID] = 0 // 初始化为0 + actual, loaded := msgIDToIndex.LoadOrStore(msgID, 0) + if !loaded { return 0 } - msgIDToIndex[msgID]++ // 递增Index - return msgIDToIndex[msgID] + newVal := actual.(int) + 1 + msgIDToIndex.Store(msgID, newVal) + return newVal +} + +func UpdateRelatedID(MessageID, ID string) { + msgIDToRelatedID.Store(MessageID, ID) } -// GetRelatedID 根据MessageID获取相关的ID func GetRelatedID(MessageID string) string { - if relatedID, exists := msgIDToRelatedID[MessageID]; exists { - return relatedID + if relatedID, ok := msgIDToRelatedID.Load(MessageID); ok { + return relatedID.(string) } - // 如果没有找到转换关系,返回空字符串 return "" } -// UpdateRelatedID 更新MessageID到respID的映射关系 -func UpdateRelatedID(MessageID, ID string) { - msgIDToRelatedID[MessageID] = ID -} - func HandleSendPrivateMsgSSE(client callapi.Client, api openapi.OpenAPI, apiv2 openapi.OpenAPI, message callapi.ActionMessage) (string, error) { // 使用 message.Echo 作为key来获取消息类型 var retmsg string From cbd25bdcc3aad9c0cbc682b56cace8ddd4d77ae6 Mon Sep 17 00:00:00 2001 From: cosmo Date: Sat, 1 Jun 2024 17:13:07 +0800 Subject: [PATCH 17/20] beta415 --- handlers/send_group_msg.go | 57 +++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/handlers/send_group_msg.go b/handlers/send_group_msg.go index f23084da..3fb7752e 100644 --- a/handlers/send_group_msg.go +++ b/handlers/send_group_msg.go @@ -337,6 +337,7 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap pair.GroupMessage = groupMessage echo.PushGlobalStack(pair) } else if err != nil && strings.Contains(err.Error(), `"code":40034025`) { + // event_id无效的时候 groupMessage.EventID = "" resp, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) if err != nil { @@ -348,6 +349,8 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap mylog.ErrLogToFile("error", err.Error()) } } + } else if err != nil && strings.Contains(err.Error(), "context deadline exceeded") { + postGroupMessageWithRetry(apiv2, message.Params.GroupID.(string), groupMessage) } // 发送成功回执 @@ -401,6 +404,8 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap mylog.ErrLogToFile("error", err.Error()) } } + } else if err != nil && strings.Contains(err.Error(), "context deadline exceeded") { + postGroupMessageWithRetry(apiv2, message.Params.GroupID.(string), groupMessage) } //发送成功回执 retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2) @@ -469,6 +474,8 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap mylog.ErrLogToFile("error", err.Error()) } } + } else if err != nil && strings.Contains(err.Error(), "context deadline exceeded") { + postGroupMessageWithRetry(apiv2, message.Params.GroupID.(string), groupMessage) } //发送成功回执 retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2) @@ -507,6 +514,8 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap if err != nil { mylog.Printf("发送文本报错信息失败: %v", err) } + } else if err != nil && strings.Contains(err.Error(), "context deadline exceeded") { + postGroupMessageWithRetry(apiv2, message.Params.GroupID.(string), groupMessage) } } // 错误保存到本地 @@ -554,6 +563,8 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap if err != nil { mylog.Printf("发送图片失败: %v", err) } + } else if err != nil && strings.Contains(err.Error(), "context deadline exceeded") { + postGroupMessageWithRetry(apiv2, message.Params.GroupID.(string), groupMessage) } } //发送成功回执 @@ -1425,9 +1436,13 @@ func auto_md(message callapi.ActionMessage, messageText string, richMediaMessage // 处理 Markdown CustomTemplateID := config.GetCustomTemplateID() imgURL := richMediaMessage.URL + // 处理来自nt图床的链接 + imgURL = processImgUrl(imgURL) height, width, err := images.GetImageDimensions(imgURL) if err != nil { - mylog.Printf("获取图片宽高出错") + height = 480 + width = 480 + mylog.Printf("获取图片宽高出错,默认宽高480x480") } imgDesc := fmt.Sprintf("图片 #%dpx #%dpx", width, height) @@ -1682,3 +1697,43 @@ func checkDataLabelPrefixExcept(whiteLabel string) bool { } return false } + +func processImgUrl(input string) string { + // 将指定的URL前缀替换 + processed := strings.ReplaceAll(input, "https://multimedia.nt.qq.com.cn", "http://multimedia.nt.qq.com") + + // 仅当输入字符串包含 "multimedia.nt.qq" 时,才替换下划线为 "%5f" + if strings.Contains(processed, "multimedia.nt.qq") { + processed = strings.ReplaceAll(processed, "_", "%5f") + } + + return processed +} + +func postGroupMessageWithRetry(apiv2 openapi.OpenAPI, groupID string, groupMessage *dto.MessageToCreate) (resp *dto.GroupMessageResponse, err error) { + retryCount := 3 // 设置最大重试次数为3 + for i := 0; i < retryCount; i++ { + resp, err = apiv2.PostGroupMessage(context.TODO(), groupID, groupMessage) + if err != nil && strings.Contains(err.Error(), "context deadline exceeded") { + mylog.Printf("超时重试第 %d 次: %v", i+1, err) + if config.GetSaveError() { + mylog.ErrLogToFile("type", "PostGroupMessage-context-deadline-exceeded-retry-"+strconv.Itoa(i+1)) + mylog.ErrInterfaceToFile("request", groupMessage) + mylog.ErrLogToFile("error", err.Error()) + } + time.Sleep(1 * time.Second) // 重试间隔1秒 + continue + } else { + mylog.Printf("超时重试第 %d 次成功: %v", i+1, err) + if config.GetSaveError() { + mylog.ErrLogToFile("type", "PostGroupMessage-context-deadline-exceeded-retry-"+strconv.Itoa(i+1)+"-successed") + mylog.ErrInterfaceToFile("request", groupMessage) + mylog.ErrLogToFile("msgid", resp.Message.ID) + retAsString := strconv.Itoa(resp.Message.Ret) + mylog.ErrLogToFile("ret", retAsString) + } + } + break + } + return resp, err +} From d9381b31d3054557c6c60d6e9bab6e27c671279c Mon Sep 17 00:00:00 2001 From: cosmo Date: Sat, 1 Jun 2024 18:50:04 +0800 Subject: [PATCH 18/20] beta416 --- handlers/send_group_msg.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/handlers/send_group_msg.go b/handlers/send_group_msg.go index 3fb7752e..dad01f2d 100644 --- a/handlers/send_group_msg.go +++ b/handlers/send_group_msg.go @@ -1713,6 +1713,11 @@ func processImgUrl(input string) string { func postGroupMessageWithRetry(apiv2 openapi.OpenAPI, groupID string, groupMessage *dto.MessageToCreate) (resp *dto.GroupMessageResponse, err error) { retryCount := 3 // 设置最大重试次数为3 for i := 0; i < retryCount; i++ { + // 递增msgid + msgseq := echo.GetMappingSeq(groupMessage.MsgID) + echo.AddMappingSeq(groupMessage.MsgID, msgseq+1) + groupMessage.MsgSeq = msgseq + 1 + resp, err = apiv2.PostGroupMessage(context.TODO(), groupID, groupMessage) if err != nil && strings.Contains(err.Error(), "context deadline exceeded") { mylog.Printf("超时重试第 %d 次: %v", i+1, err) @@ -1728,9 +1733,9 @@ func postGroupMessageWithRetry(apiv2 openapi.OpenAPI, groupID string, groupMessa if config.GetSaveError() { mylog.ErrLogToFile("type", "PostGroupMessage-context-deadline-exceeded-retry-"+strconv.Itoa(i+1)+"-successed") mylog.ErrInterfaceToFile("request", groupMessage) - mylog.ErrLogToFile("msgid", resp.Message.ID) - retAsString := strconv.Itoa(resp.Message.Ret) - mylog.ErrLogToFile("ret", retAsString) + if resp != nil { + mylog.ErrLogToFile("msgid", resp.Message.ID) + } } } break From 7b66be857f60a882889b5b138f1c0a88ff65b58f Mon Sep 17 00:00:00 2001 From: cosmo Date: Sun, 9 Jun 2024 00:17:10 +0800 Subject: [PATCH 19/20] beta417 --- Processor/ProcessC2CMessage.go | 4 +- Processor/ProcessChannelDirectMessage.go | 6 +- Processor/ProcessGroupAddBot.go | 4 +- Processor/ProcessGroupDelBot.go | 2 +- Processor/ProcessGroupMessage.go | 2 +- Processor/ProcessGroupMsgReceive.go | 4 +- Processor/ProcessGroupMsgReject.go | 4 +- Processor/ProcessGuildATMessage.go | 4 +- Processor/ProcessGuildNormalMessage.go | 4 +- Processor/ProcessInlineSearch.go | 8 +- Processor/ProcessThreadMessage.go | 6 +- Processor/Processor.go | 194 ++++++++++++++++------- config/config.go | 10 ++ main.go | 7 + server/wsserver.go | 2 +- structs/structs.go | 13 +- template/config_template.go | 1 + wsclient/ws.go | 2 +- 18 files changed, 187 insertions(+), 90 deletions(-) diff --git a/Processor/ProcessC2CMessage.go b/Processor/ProcessC2CMessage.go index 67589d14..a8aeccea 100644 --- a/Processor/ProcessC2CMessage.go +++ b/Processor/ProcessC2CMessage.go @@ -154,7 +154,7 @@ func (p *Processors) ProcessC2CMessage(data *dto.WSC2CMessageData) error { // Convert OnebotGroupMessage to map and send privateMsgMap := structToMap(privateMsg) //上报信息到onebotv11应用端(正反ws) - p.BroadcastMessageToAll(privateMsgMap) + go p.BroadcastMessageToAll(privateMsgMap, p.Apiv2, data) //组合FriendData struserid := strconv.FormatInt(userid64, 10) userdata := structs.FriendData{ @@ -296,7 +296,7 @@ func (p *Processors) ProcessC2CMessage(data *dto.WSC2CMessageData) error { // Convert OnebotGroupMessage to map and send groupMsgMap := structToMap(groupMsg) //上报信息到onebotv11应用端(正反ws) - p.BroadcastMessageToAll(groupMsgMap) + go p.BroadcastMessageToAll(groupMsgMap, p.Apiv2, data) //组合FriendData struserid := strconv.FormatInt(userid64, 10) diff --git a/Processor/ProcessChannelDirectMessage.go b/Processor/ProcessChannelDirectMessage.go index 94d73567..50a099e3 100644 --- a/Processor/ProcessChannelDirectMessage.go +++ b/Processor/ProcessChannelDirectMessage.go @@ -171,7 +171,7 @@ func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData) // Convert OnebotGroupMessage to map and send privateMsgMap := structToMap(privateMsg) //上报信息到onebotv11应用端(正反ws) - p.BroadcastMessageToAll(privateMsgMap) + go p.BroadcastMessageToAll(privateMsgMap, p.Apiv2, data) } else { if !p.Settings.GlobalChannelToGroup { //将频道私信作为普通频道信息 @@ -280,7 +280,7 @@ func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData) // 将 onebotMsg 结构体转换为 map[string]interface{} msgMap := structToMap(onebotMsg) //上报信息到onebotv11应用端(正反ws) - p.BroadcastMessageToAll(msgMap) + go p.BroadcastMessageToAll(msgMap, p.Apiv2, data) } else { //将频道信息转化为群信息(特殊需求情况下) //将channelid写入bolt,可取出guild_id @@ -444,7 +444,7 @@ func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData) // Convert OnebotGroupMessage to map and send groupMsgMap := structToMap(groupMsg) //上报信息到onebotv11应用端(正反ws) - p.BroadcastMessageToAll(groupMsgMap) + go p.BroadcastMessageToAll(groupMsgMap, p.Apiv2, data) } } diff --git a/Processor/ProcessGroupAddBot.go b/Processor/ProcessGroupAddBot.go index 973af06e..4bf65c5a 100644 --- a/Processor/ProcessGroupAddBot.go +++ b/Processor/ProcessGroupAddBot.go @@ -125,11 +125,11 @@ func (p *Processors) ProcessGroupAddBot(data *dto.GroupAddBotEvent) error { } groupMsgMap := structToMap(Request) //上报信息到onebotv11应用端(正反ws) - p.BroadcastMessageToAll(groupMsgMap) + go p.BroadcastMessageToAll(groupMsgMap, p.Apiv2, data) groupMsgMap = structToMap(Notice) //上报信息到onebotv11应用端(正反ws) - p.BroadcastMessageToAll(groupMsgMap) + go p.BroadcastMessageToAll(groupMsgMap, p.Apiv2, data) // 转换appid AppIDString := strconv.FormatUint(p.Settings.AppID, 10) diff --git a/Processor/ProcessGroupDelBot.go b/Processor/ProcessGroupDelBot.go index 44d1287e..59e8fc39 100644 --- a/Processor/ProcessGroupDelBot.go +++ b/Processor/ProcessGroupDelBot.go @@ -72,6 +72,6 @@ func (p *Processors) ProcessGroupDelBot(data *dto.GroupAddBotEvent) error { } groupMsgMap := structToMap(Notice) //上报信息到onebotv11应用端(正反ws) - p.BroadcastMessageToAll(groupMsgMap) + go p.BroadcastMessageToAll(groupMsgMap, p.Apiv2, data) return nil } diff --git a/Processor/ProcessGroupMessage.go b/Processor/ProcessGroupMessage.go index 15622618..c5c16ea3 100644 --- a/Processor/ProcessGroupMessage.go +++ b/Processor/ProcessGroupMessage.go @@ -188,6 +188,6 @@ func (p *Processors) ProcessGroupMessage(data *dto.WSGroupATMessageData) error { // Convert OnebotGroupMessage to map and send groupMsgMap := structToMap(groupMsg) //上报信息到onebotv11应用端(正反ws) - p.BroadcastMessageToAll(groupMsgMap) + go p.BroadcastMessageToAll(groupMsgMap, p.Apiv2, data) return nil } diff --git a/Processor/ProcessGroupMsgReceive.go b/Processor/ProcessGroupMsgReceive.go index 3df37683..a0d27b40 100644 --- a/Processor/ProcessGroupMsgReceive.go +++ b/Processor/ProcessGroupMsgReceive.go @@ -93,7 +93,7 @@ func (p *Processors) ProcessGroupMsgRecive(data *dto.GroupMsgReceiveEvent) error noticeMap := structToMap(notice) //上报信息到onebotv11应用端(正反ws) - p.BroadcastMessageToAll(noticeMap) + go p.BroadcastMessageToAll(noticeMap, p.Apiv2, data) // 转换appid AppIDString := strconv.FormatUint(p.Settings.AppID, 10) @@ -205,7 +205,7 @@ func (p *Processors) ProcessGroupMsgRecive(data *dto.GroupMsgReceiveEvent) error // Convert OnebotGroupMessage to map and send groupMsgMap := structToMap(groupMsg) //上报信息到onebotv11应用端(正反ws) - p.BroadcastMessageToAll(groupMsgMap) + go p.BroadcastMessageToAll(groupMsgMap, p.Apiv2, data) // 转换appid AppIDString := strconv.FormatUint(p.Settings.AppID, 10) diff --git a/Processor/ProcessGroupMsgReject.go b/Processor/ProcessGroupMsgReject.go index ae53d668..c3f72d96 100644 --- a/Processor/ProcessGroupMsgReject.go +++ b/Processor/ProcessGroupMsgReject.go @@ -94,7 +94,7 @@ func (p *Processors) ProcessGroupMsgReject(data *dto.GroupMsgRejectEvent) error noticeMap := structToMap(notice) //上报信息到onebotv11应用端(正反ws) - p.BroadcastMessageToAll(noticeMap) + go p.BroadcastMessageToAll(noticeMap, p.Apiv2, data) // 转换appid AppIDString := strconv.FormatUint(p.Settings.AppID, 10) @@ -206,7 +206,7 @@ func (p *Processors) ProcessGroupMsgReject(data *dto.GroupMsgRejectEvent) error // Convert OnebotGroupMessage to map and send groupMsgMap := structToMap(groupMsg) //上报信息到onebotv11应用端(正反ws) - p.BroadcastMessageToAll(groupMsgMap) + go p.BroadcastMessageToAll(groupMsgMap, p.Apiv2, data) // 转换appid AppIDString := strconv.FormatUint(p.Settings.AppID, 10) diff --git a/Processor/ProcessGuildATMessage.go b/Processor/ProcessGuildATMessage.go index aef11d04..bb2cf227 100644 --- a/Processor/ProcessGuildATMessage.go +++ b/Processor/ProcessGuildATMessage.go @@ -132,7 +132,7 @@ func (p *Processors) ProcessGuildATMessage(data *dto.WSATMessageData) error { msgMap := structToMap(onebotMsg) //上报信息到onebotv11应用端(正反ws) - p.BroadcastMessageToAll(msgMap) + go p.BroadcastMessageToAll(msgMap, p.Apiv2, data) } else { // GlobalChannelToGroup为true时的处理逻辑 //将频道转化为一个群 @@ -298,7 +298,7 @@ func (p *Processors) ProcessGuildATMessage(data *dto.WSATMessageData) error { // Convert OnebotGroupMessage to map and send groupMsgMap := structToMap(groupMsg) //上报信息到onebotv11应用端(正反ws) - p.BroadcastMessageToAll(groupMsgMap) + go p.BroadcastMessageToAll(groupMsgMap, p.Apiv2, data) } diff --git a/Processor/ProcessGuildNormalMessage.go b/Processor/ProcessGuildNormalMessage.go index 36b9a32a..d7d39589 100644 --- a/Processor/ProcessGuildNormalMessage.go +++ b/Processor/ProcessGuildNormalMessage.go @@ -131,7 +131,7 @@ func (p *Processors) ProcessGuildNormalMessage(data *dto.WSMessageData) error { msgMap := structToMap(onebotMsg) //上报信息到onebotv11应用端(正反ws) - p.BroadcastMessageToAll(msgMap) + go p.BroadcastMessageToAll(msgMap, p.Apiv2, data) } else { // GlobalChannelToGroup为true时的处理逻辑 //将频道转化为一个群 @@ -305,7 +305,7 @@ func (p *Processors) ProcessGuildNormalMessage(data *dto.WSMessageData) error { groupMsgMap := structToMap(groupMsg) //上报信息到onebotv11应用端(正反ws) - p.BroadcastMessageToAll(groupMsgMap) + go p.BroadcastMessageToAll(groupMsgMap, p.Apiv2, data) } return nil diff --git a/Processor/ProcessInlineSearch.go b/Processor/ProcessInlineSearch.go index c7a4d867..6e339119 100644 --- a/Processor/ProcessInlineSearch.go +++ b/Processor/ProcessInlineSearch.go @@ -107,7 +107,7 @@ func (p *Processors) ProcessInlineSearch(data *dto.WSInteractionData) error { noticeMap := structToMap(notice) //上报信息到onebotv11应用端(正反ws) - p.BroadcastMessageToAll(noticeMap) + go p.BroadcastMessageToAll(noticeMap, p.Apiv2, data) // 转换appid AppIDString := strconv.FormatUint(p.Settings.AppID, 10) @@ -221,7 +221,7 @@ func (p *Processors) ProcessInlineSearch(data *dto.WSInteractionData) error { // Convert OnebotGroupMessage to map and send groupMsgMap := structToMap(groupMsg) //上报信息到onebotv11应用端(正反ws) - p.BroadcastMessageToAll(groupMsgMap) + go p.BroadcastMessageToAll(groupMsgMap, p.Apiv2, data) // 转换appid AppIDString := strconv.FormatUint(p.Settings.AppID, 10) @@ -300,7 +300,7 @@ func (p *Processors) ProcessInlineSearch(data *dto.WSInteractionData) error { // Convert OnebotGroupMessage to map and send privateMsgMap := structToMap(privateMsg) //上报信息到onebotv11应用端(正反ws) - p.BroadcastMessageToAll(privateMsgMap) + go p.BroadcastMessageToAll(privateMsgMap, p.Apiv2, data) // 转换appid AppIDString := strconv.FormatUint(p.Settings.AppID, 10) @@ -361,7 +361,7 @@ func (p *Processors) ProcessInlineSearch(data *dto.WSInteractionData) error { msgMap := structToMap(onebotMsg) //上报信息到onebotv11应用端(正反ws) - p.BroadcastMessageToAll(msgMap) + go p.BroadcastMessageToAll(msgMap, p.Apiv2, data) // TODO: 实现eventid } diff --git a/Processor/ProcessThreadMessage.go b/Processor/ProcessThreadMessage.go index 833ec72d..1d9d596f 100644 --- a/Processor/ProcessThreadMessage.go +++ b/Processor/ProcessThreadMessage.go @@ -137,7 +137,7 @@ func (p *Processors) ProcessThreadMessage(data *dto.WSThreadData) error { msgMap := structToMap(onebotMsg) //上报信息到onebotv11应用端(正反ws) - p.BroadcastMessageToAll(msgMap) + go p.BroadcastMessageToAll(msgMap, p.Apiv2, data) return nil } else { @@ -256,7 +256,7 @@ func (p *Processors) ProcessThreadMessage(data *dto.WSThreadData) error { msgMap := structToMap(onebotMsg) //上报信息到onebotv11应用端(正反ws) - p.BroadcastMessageToAll(msgMap) + go p.BroadcastMessageToAll(msgMap, p.Apiv2, data) } else { //转化为群信息 //将频道转化为一个群 @@ -394,7 +394,7 @@ func (p *Processors) ProcessThreadMessage(data *dto.WSThreadData) error { groupMsgMap := structToMap(groupMsg) //上报信息到onebotv11应用端(正反ws) - p.BroadcastMessageToAll(groupMsgMap) + go p.BroadcastMessageToAll(groupMsgMap, p.Apiv2, data) } } diff --git a/Processor/Processor.go b/Processor/Processor.go index 62a8cd6d..85b95f6b 100644 --- a/Processor/Processor.go +++ b/Processor/Processor.go @@ -15,6 +15,7 @@ import ( "regexp" "strconv" "strings" + "sync" "time" "github.com/hashicorp/go-multierror" @@ -230,35 +231,101 @@ func (p *Processors) SendMessageToAllClients(message map[string]interface{}) err } // 方便快捷的发信息函数 -func (p *Processors) BroadcastMessageToAll(message map[string]interface{}) error { - var errors []string +func (p *Processors) BroadcastMessageToAll(message map[string]interface{}, api openapi.MessageAPI, data interface{}) error { + var wg sync.WaitGroup + errorCh := make(chan string, len(p.Wsclient)+len(p.WsServerClients)) + defer close(errorCh) - // 发送到我们作为客户端的Wsclient + // 并发发送到我们作为客户端的Wsclient for _, client := range p.Wsclient { - //mylog.Printf("第%v个Wsclient", test) - err := client.SendMessage(message) - if err != nil { - errors = append(errors, fmt.Sprintf("error sending private message via wsclient: %v", err)) - } + wg.Add(1) + go func(c callapi.WebSocketServerClienter) { + defer wg.Done() + if err := c.SendMessage(message); err != nil { + errorCh <- fmt.Sprintf("error sending message via wsclient: %v", err) + } + }(client) } - // 发送到我们作为服务器连接到我们的WsServerClients + // 并发发送到我们作为服务器连接到我们的WsServerClients for _, serverClient := range p.WsServerClients { - err := serverClient.SendMessage(message) - if err != nil { - errors = append(errors, fmt.Sprintf("error sending private message via WsServerClient: %v", err)) + wg.Add(1) + go func(sc callapi.WebSocketServerClienter) { + defer wg.Done() + if err := sc.SendMessage(message); err != nil { + errorCh <- fmt.Sprintf("error sending message via WsServerClient: %v", err) + } + }(serverClient) + } + + wg.Wait() // 等待所有goroutine完成 + + var errors []string + failed := 0 + for len(errorCh) > 0 { + err := <-errorCh + errors = append(errors, err) + failed++ + } + + // 检查是否所有尝试都失败了 + if failed == len(p.Wsclient)+len(p.WsServerClients) { + // 处理全部失败的情况 + fmt.Println("All message sending attempts failed.") + downtimemessgae := config.GetDowntimeMessage() + switch v := data.(type) { + case *dto.WSGroupATMessageData: + msgtocreate := &dto.MessageToCreate{ + Content: downtimemessgae, + MsgID: v.ID, + MsgSeq: 1, + MsgType: 0, // 默认文本类型 + } + api.PostGroupMessage(context.Background(), v.GroupID, msgtocreate) + case *dto.WSATMessageData: + msgtocreate := &dto.MessageToCreate{ + Content: downtimemessgae, + MsgID: v.ID, + MsgSeq: 1, + MsgType: 0, // 默认文本类型 + } + api.PostMessage(context.Background(), v.ChannelID, msgtocreate) + case *dto.WSMessageData: + msgtocreate := &dto.MessageToCreate{ + Content: downtimemessgae, + MsgID: v.ID, + MsgSeq: 1, + MsgType: 0, // 默认文本类型 + } + api.PostMessage(context.Background(), v.ChannelID, msgtocreate) + case *dto.WSDirectMessageData: + msgtocreate := &dto.MessageToCreate{ + Content: downtimemessgae, + MsgID: v.ID, + MsgSeq: 1, + MsgType: 0, // 默认文本类型 + } + api.PostMessage(context.Background(), v.GuildID, msgtocreate) + case *dto.WSC2CMessageData: + msgtocreate := &dto.MessageToCreate{ + Content: downtimemessgae, + MsgID: v.ID, + MsgSeq: 1, + MsgType: 0, // 默认文本类型 + } + api.PostC2CMessage(context.Background(), v.Author.ID, msgtocreate) } } - // 在循环结束后处理记录的错误 + // 判断是否填写了反向post地址 + if !allEmpty(config.GetPostUrl()) { + go PostMessageToUrls(message) + } + if len(errors) > 0 { return fmt.Errorf(strings.Join(errors, "; ")) } - //判断是否填写了反向post地址 - if !allEmpty(config.GetPostUrl()) { - PostMessageToUrls(message) - } return nil } @@ -272,59 +339,70 @@ func allEmpty(addresses []string) bool { return true } -// 上报信息给反向Http +// PostMessageToUrls 使用并发 goroutines 上报信息给多个反向 HTTP URL func PostMessageToUrls(message map[string]interface{}) { // 获取上报 URL 列表 postUrls := config.GetPostUrl() // 检查 postUrls 是否为空 - if len(postUrls) > 0 { - - // 转换 message 为 JSON 字符串 - jsonString, err := handlers.ConvertMapToJSONString(message) - if err != nil { - mylog.Printf("Error converting message to JSON: %v", err) - return - } - - for _, url := range postUrls { - // 创建请求体 - reqBody := bytes.NewBufferString(jsonString) + if len(postUrls) == 0 { + return + } - // 创建 POST 请求 - req, err := http.NewRequest("POST", url, reqBody) - if err != nil { - mylog.Printf("Error creating POST request to %s: %v", url, err) - continue - } + // 转换 message 为 JSON 字符串 + jsonString, err := handlers.ConvertMapToJSONString(message) + if err != nil { + mylog.Printf("Error converting message to JSON: %v", err) + return + } - // 设置请求头 - req.Header.Set("Content-Type", "application/json") - // 设置 X-Self-ID - var selfid string - if config.GetUseUin() { - selfid = config.GetUinStr() - } else { - selfid = config.GetAppIDStr() - } + // 使用 WaitGroup 等待所有 goroutines 完成 + var wg sync.WaitGroup + for _, url := range postUrls { + wg.Add(1) + // 启动一个 goroutine + go func(url string) { + defer wg.Done() // 确保减少 WaitGroup 的计数器 + sendPostRequest(jsonString, url) + }(url) + } + wg.Wait() // 等待所有 goroutine 完成 +} - req.Header.Set("X-Self-ID", selfid) +// sendPostRequest 发送单个 POST 请求 +func sendPostRequest(jsonString, url string) { + // 创建请求体 + reqBody := bytes.NewBufferString(jsonString) - // 发送请求 - client := &http.Client{} - resp, err := client.Do(req) - if err != nil { - mylog.Printf("Error sending POST request to %s: %v", url, err) - continue - } + // 创建 POST 请求 + req, err := http.NewRequest("POST", url, reqBody) + if err != nil { + mylog.Printf("Error creating POST request to %s: %v", url, err) + return + } - // 处理响应 - defer resp.Body.Close() - // 可以添加更多的响应处理逻辑,如检查状态码等 + // 设置请求头 + req.Header.Set("Content-Type", "application/json") + // 设置 X-Self-ID + var selfid string + if config.GetUseUin() { + selfid = config.GetUinStr() + } else { + selfid = config.GetAppIDStr() + } + req.Header.Set("X-Self-ID", selfid) - mylog.Printf("Posted to %s successfully", url) - } + // 发送请求 + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + mylog.Printf("Error sending POST request to %s: %v", url, err) + return } + defer resp.Body.Close() // 确保释放网络资源 + + // 可以在此处添加更多的响应处理逻辑 + mylog.Printf("Posted to %s successfully", url) } func (p *Processors) HandleFrameworkCommand(messageText string, data interface{}, Type string) error { diff --git a/config/config.go b/config/config.go index d6abf063..79f57b77 100644 --- a/config/config.go +++ b/config/config.go @@ -2292,3 +2292,13 @@ func GetNativeMD() bool { } return instance.Settings.NativeMD } + +// 获取DowntimeMessage +func GetDowntimeMessage() string { + mu.Lock() + defer mu.Unlock() + if instance != nil { + return instance.Settings.DowntimeMessage + } + return "" +} diff --git a/main.go b/main.go index 1fbe134b..2318f1ce 100644 --- a/main.go +++ b/main.go @@ -48,6 +48,7 @@ func main() { // 定义faststart命令行标志。默认为false。 fastStart := flag.Bool("faststart", false, "start without initialization if set") tidy := flag.Bool("tidy", false, "backup and tidy your config.yml") + m := flag.Bool("m", false, "Maintenance mode") // 解析命令行参数到定义的标志。 flag.Parse() @@ -116,6 +117,12 @@ func main() { loggerAdapter := mylog.NewMyLogAdapter(logLevel, config.GetSaveLogs()) botgo.SetLogger(loggerAdapter) + if *m { + // 维护模式 + conf.Settings.WsAddress = []string{"ws://127.0.0.1:50000"} + conf.Settings.EnableWsServer = false + } + // 创建webui数据库 webui.InitializeDB() defer webui.CloseDB() diff --git a/server/wsserver.go b/server/wsserver.go index 5bd2b366..ae5aed28 100644 --- a/server/wsserver.go +++ b/server/wsserver.go @@ -150,7 +150,7 @@ func processWSMessage(client *WebSocketServerClient, msg []byte) { mylog.Println("Received from WebSocket onebotv11 client:", wsclient.TruncateMessage(message, 500)) // 调用callapi - callapi.CallAPIFromDict(client, client.API, client.APIv2, message) + go callapi.CallAPIFromDict(client, client.API, client.APIv2, message) } // 发信息给client diff --git a/structs/structs.go b/structs/structs.go index 6d231da7..6940c952 100644 --- a/structs/structs.go +++ b/structs/structs.go @@ -95,12 +95,13 @@ type Settings struct { AutoWithdrawTime int `yaml:"auto_withdraw_time"` VisualPrefixsBypass []string `yaml:"visual_prefixs_bypass"` //开发增强类 - DevlopAcDir string `yaml:"develop_access_token_dir"` - DevBotid string `yaml:"develop_bot_id"` - SandBoxMode bool `yaml:"sandbox_mode"` - DevMessgeID bool `yaml:"dev_message_id"` - SendError bool `yaml:"send_error"` - SaveError bool `yaml:"save_error"` + DevlopAcDir string `yaml:"develop_access_token_dir"` + DevBotid string `yaml:"develop_bot_id"` + SandBoxMode bool `yaml:"sandbox_mode"` + DevMessgeID bool `yaml:"dev_message_id"` + SendError bool `yaml:"send_error"` + SaveError bool `yaml:"save_error"` + DowntimeMessage string `yaml:"downtime_message"` //增长营销类 SelfIntroduce []string `yaml:"self_introduce"` //api修改 diff --git a/template/config_template.go b/template/config_template.go index 8cefb04b..3006a586 100644 --- a/template/config_template.go +++ b/template/config_template.go @@ -133,6 +133,7 @@ settings: dev_message_id : false #在沙盒和测试环境使用无限制msg_id 仅沙盒有效,正式环境请关闭,内测结束后,tx侧未来会移除 send_error : true #将报错用文本发出,避免机器人被审核报无响应 save_error : false #将保存保存在log文件夹,方便开发者定位发送错误. + downtime_message : "我正在维护中~请不要担心,维护结束就回来~维护时间:(1小时)" #增长营销类(推荐gensokyo-broadcast项目) self_introduce : ["",""] #自我介绍,可设置多个随机发送,当不为空时,机器人被邀入群会发送自定义自我介绍 需手动添加新textintent - "GroupAddRobotEventHandler" - "GroupDelRobotEventHandler" diff --git a/wsclient/ws.go b/wsclient/ws.go index 3435e87c..f635fd33 100644 --- a/wsclient/ws.go +++ b/wsclient/ws.go @@ -189,7 +189,7 @@ func (client *WebSocketClient) recvMessage(msg []byte) { } mylog.Println("Received from onebotv11 server:", TruncateMessage(message, 800)) // 调用callapi - callapi.CallAPIFromDict(client, client.api, client.apiv2, message) + go callapi.CallAPIFromDict(client, client.api, client.apiv2, message) } // 截断信息 From 4b2a9a9691fca94990496f56d470624a9d4817a8 Mon Sep 17 00:00:00 2001 From: cosmo Date: Mon, 10 Jun 2024 11:54:06 +0800 Subject: [PATCH 20/20] btea418 --- Processor/Processor.go | 93 +++++++++++++++++++------------------ main.go | 19 +++++++- server/wsserver.go | 5 ++ structs/structs.go | 3 +- template/config_template.go | 2 +- 5 files changed, 73 insertions(+), 49 deletions(-) diff --git a/Processor/Processor.go b/Processor/Processor.go index 85b95f6b..c10db3fb 100644 --- a/Processor/Processor.go +++ b/Processor/Processor.go @@ -268,52 +268,55 @@ func (p *Processors) BroadcastMessageToAll(message map[string]interface{}, api o failed++ } - // 检查是否所有尝试都失败了 - if failed == len(p.Wsclient)+len(p.WsServerClients) { - // 处理全部失败的情况 - fmt.Println("All message sending attempts failed.") - downtimemessgae := config.GetDowntimeMessage() - switch v := data.(type) { - case *dto.WSGroupATMessageData: - msgtocreate := &dto.MessageToCreate{ - Content: downtimemessgae, - MsgID: v.ID, - MsgSeq: 1, - MsgType: 0, // 默认文本类型 + // 仅对连接正反ws的bot应用这个判断 + if !p.Settings.HttpOnlyBot { + // 检查是否所有尝试都失败了 + if failed == len(p.Wsclient)+len(p.WsServerClients) { + // 处理全部失败的情况 + fmt.Println("All ws event sending attempts failed.") + downtimemessgae := config.GetDowntimeMessage() + switch v := data.(type) { + case *dto.WSGroupATMessageData: + msgtocreate := &dto.MessageToCreate{ + Content: downtimemessgae, + MsgID: v.ID, + MsgSeq: 1, + MsgType: 0, // 默认文本类型 + } + api.PostGroupMessage(context.Background(), v.GroupID, msgtocreate) + case *dto.WSATMessageData: + msgtocreate := &dto.MessageToCreate{ + Content: downtimemessgae, + MsgID: v.ID, + MsgSeq: 1, + MsgType: 0, // 默认文本类型 + } + api.PostMessage(context.Background(), v.ChannelID, msgtocreate) + case *dto.WSMessageData: + msgtocreate := &dto.MessageToCreate{ + Content: downtimemessgae, + MsgID: v.ID, + MsgSeq: 1, + MsgType: 0, // 默认文本类型 + } + api.PostMessage(context.Background(), v.ChannelID, msgtocreate) + case *dto.WSDirectMessageData: + msgtocreate := &dto.MessageToCreate{ + Content: downtimemessgae, + MsgID: v.ID, + MsgSeq: 1, + MsgType: 0, // 默认文本类型 + } + api.PostMessage(context.Background(), v.GuildID, msgtocreate) + case *dto.WSC2CMessageData: + msgtocreate := &dto.MessageToCreate{ + Content: downtimemessgae, + MsgID: v.ID, + MsgSeq: 1, + MsgType: 0, // 默认文本类型 + } + api.PostC2CMessage(context.Background(), v.Author.ID, msgtocreate) } - api.PostGroupMessage(context.Background(), v.GroupID, msgtocreate) - case *dto.WSATMessageData: - msgtocreate := &dto.MessageToCreate{ - Content: downtimemessgae, - MsgID: v.ID, - MsgSeq: 1, - MsgType: 0, // 默认文本类型 - } - api.PostMessage(context.Background(), v.ChannelID, msgtocreate) - case *dto.WSMessageData: - msgtocreate := &dto.MessageToCreate{ - Content: downtimemessgae, - MsgID: v.ID, - MsgSeq: 1, - MsgType: 0, // 默认文本类型 - } - api.PostMessage(context.Background(), v.ChannelID, msgtocreate) - case *dto.WSDirectMessageData: - msgtocreate := &dto.MessageToCreate{ - Content: downtimemessgae, - MsgID: v.ID, - MsgSeq: 1, - MsgType: 0, // 默认文本类型 - } - api.PostMessage(context.Background(), v.GuildID, msgtocreate) - case *dto.WSC2CMessageData: - msgtocreate := &dto.MessageToCreate{ - Content: downtimemessgae, - MsgID: v.ID, - MsgSeq: 1, - MsgType: 0, // 默认文本类型 - } - api.PostC2CMessage(context.Background(), v.Author.ID, msgtocreate) } } diff --git a/main.go b/main.go index 2318f1ce..48433c61 100644 --- a/main.go +++ b/main.go @@ -318,8 +318,24 @@ func main() { p = Processor.NewProcessor(api, apiV2, &conf.Settings, wsClients) } } else { - log.Println("提示,目前只启动了正向ws或httpapi") + // p一定需要初始化 p = Processor.NewProcessorV2(api, apiV2, &conf.Settings) + // 如果只启动了http api + if !conf.Settings.EnableWsServer { + if conf.Settings.HttpAddress != "" { + // 对全局生效 + conf.Settings.HttpOnlyBot = true + log.Println("提示,目前只启动了httpapi,正反向ws均未配置.") + } else { + log.Println("提示,目前你配置了个寂寞,httpapi没设置,正反ws都没配置.") + } + } else { + if conf.Settings.HttpAddress != "" { + log.Println("提示,目前启动了正向ws和httpapi,未连接反向ws") + } else { + log.Println("提示,目前启动了正向ws,未连接反向ws,httpapi未开启") + } + } } } else { // 设置颜色为红色 @@ -327,7 +343,6 @@ func main() { // 输出红色文本 red.Println("请设置正确的appid、token、clientsecret再试") } - } //图片上传 调用次数限制 diff --git a/server/wsserver.go b/server/wsserver.go index ae5aed28..d14f5a8e 100644 --- a/server/wsserver.go +++ b/server/wsserver.go @@ -4,6 +4,7 @@ import ( "encoding/json" "net/http" "strings" + "sync" "time" "github.com/gin-gonic/gin" @@ -20,6 +21,7 @@ type WebSocketServerClient struct { Conn *websocket.Conn API openapi.OpenAPI APIv2 openapi.OpenAPI + mu sync.Mutex // 互斥锁保护 conn } var upgrader = websocket.Upgrader{ @@ -155,6 +157,9 @@ func processWSMessage(client *WebSocketServerClient, msg []byte) { // 发信息给client func (c *WebSocketServerClient) SendMessage(message map[string]interface{}) error { + c.mu.Lock() + defer c.mu.Unlock() + msgBytes, err := json.Marshal(message) if err != nil { mylog.Println("Error marshalling message:", err) diff --git a/structs/structs.go b/structs/structs.go index 6940c952..29c7c725 100644 --- a/structs/structs.go +++ b/structs/structs.go @@ -141,7 +141,8 @@ type Settings struct { EnableChangeWord bool `yaml:"enableChangeWord"` DefaultChangeWord string `yaml:"defaultChangeWord"` //错误临时修复类 - Fix11300 bool `yaml:"fix_11300"` + Fix11300 bool `yaml:"fix_11300"` + HttpOnlyBot bool `yaml:"http_only_bot"` //内置指令 BindPrefix string `yaml:"bind_prefix"` MePrefix string `yaml:"me_prefix"` diff --git a/template/config_template.go b/template/config_template.go index 3006a586..48863c48 100644 --- a/template/config_template.go +++ b/template/config_template.go @@ -183,7 +183,7 @@ settings: #错误临时修复类 fix_11300: false #修复11300报错,需要在develop_bot_id填入自己机器人的appid. 11300原因暂时未知,临时修复方案. - + http_only_bot : false #这个配置项会自动配置,请不要修改,保持false. #内置指令类 bind_prefix : "/bind" #需设置 #增强配置项 master_id 可触发