From 04d046d4611fe74ce125ed2ca718e18140e4de20 Mon Sep 17 00:00:00 2001 From: SanaeFox <36219542+Hoshinonyaruko@users.noreply.github.com> Date: Sun, 14 Jul 2024 01:39:12 +0800 Subject: [PATCH] Beta462 (#464) * beta447 * beta448 * beta449 * beta450 * beta451 * beta452 * beta453 * beta454 * beta455 * btea455 * beta456 * beta457 * beta458 * beta460 * beta460 * beta461 * beta462 --- Processor/ProcessInlineSearch.go | 22 ++++++++++- acnode/acnode.go | 12 +++--- config/config.go | 12 ++++++ handlers/message_parser.go | 63 +++++++++++++++++--------------- handlers/send_group_msg.go | 36 +++++++++++++++++- structs/structs.go | 21 ++++++----- template/config_template.go | 1 + 7 files changed, 118 insertions(+), 49 deletions(-) diff --git a/Processor/ProcessInlineSearch.go b/Processor/ProcessInlineSearch.go index 3cdb23db..254c6d89 100644 --- a/Processor/ProcessInlineSearch.go +++ b/Processor/ProcessInlineSearch.go @@ -6,6 +6,7 @@ import ( "fmt" "log" "strconv" + "strings" "sync" "time" @@ -53,10 +54,27 @@ func (p *Processors) ProcessInlineSearch(data *dto.WSInteractionData) error { // 构造echostr,包括AppID,原始的s变量和当前时间戳 echostr := fmt.Sprintf("%s_%d_%d", AppIDString, s, currentTimeMillis) - //这里处理自动handle回调回应 + // 这里处理自动handle回调回应 if config.GetAutoPutInteraction() { - DelayedPutInteraction(p.Api, data.ID, fromuid, fromgid) + exceptions := config.GetPutInteractionExcept() // 会返回一个string[],即例外列表 + + shouldCall := true // 默认应该调用DelayedPutInteraction,除非下面的条件匹配 + + // 判断,data.Data.Resolved.ButtonData 是否以返回的string[]中的任意成员开头 + for _, prefix := range exceptions { + if strings.HasPrefix(data.Data.Resolved.ButtonData, prefix) { + shouldCall = false // 如果匹配到任何一个前缀,设置shouldCall为false + break // 找到匹配项,无需继续检查 + } + } + + // 如果data.Data.Resolved.ButtonData不以返回的string[]中的任意成员开头, + // 则调用DelayedPutInteraction,否则不调用 + if shouldCall { + DelayedPutInteraction(p.Api, data.ID, fromuid, fromgid) + } } + if config.GetIdmapPro() { //将真实id转为int userid64 GroupID64, userid64, err = idmap.StoreIDv2Pro(fromgid, fromuid) diff --git a/acnode/acnode.go b/acnode/acnode.go index ba4f917f..4efab6f6 100644 --- a/acnode/acnode.go +++ b/acnode/acnode.go @@ -354,12 +354,14 @@ func CheckWordOUT(word string) string { return "错误:缺少 'word' 参数" } + //不替换base64 + if strings.Contains(word, "base64://") { + // 当word包含特定字符串时原样返回 + //fmt.Printf("原样返回的文本:%s", word) + return word + } + if len([]rune(word)) > 5000 { - if strings.Contains(word, "[CQ:image,file=base64://") { - // 当word包含特定字符串时原样返回 - fmt.Printf("原样返回的文本:%s", word) - return word - } log.Printf("错误请求:字符数超过最大限制(5000字符)。内容:%s", word) return "错误:字符数超过最大限制(5000字符)" } diff --git a/config/config.go b/config/config.go index e2da9a17..61ad5fbf 100644 --- a/config/config.go +++ b/config/config.go @@ -2400,3 +2400,15 @@ func GetDisableErrorChan() bool { } return instance.Settings.DisableErrorChan } + +// 获取 PutInteractionExcept 数组 +func GetPutInteractionExcept() []string { + mu.RLock() + defer mu.RUnlock() + + if instance == nil { + mylog.Println("Warning: instance is nil when trying to get PutInteractionExcept.") + return nil + } + return instance.Settings.PutInteractionExcept +} diff --git a/handlers/message_parser.go b/handlers/message_parser.go index 6c7f9f32..d193dcc6 100644 --- a/handlers/message_parser.go +++ b/handlers/message_parser.go @@ -1089,43 +1089,46 @@ func RevertTransformedText(data interface{}, msgtype string, api openapi.OpenAPI } } - //如果二级指令白名单全部是*(忽略自身,那么不判断二级白名单是否匹配) - if allStarPrefixed { - if len(messageText) == len(matchedPrefix.Prefix) { + // 调用 GetVisualPrefixsBypass 获取前缀数组 + visualPrefixes := config.GetVisualPrefixsBypass() + // 判断 messageText 是否以数组中的任一前缀开头 + for _, prefix := range visualPrefixes { + if strings.HasPrefix(originmessageText, prefix) { matched = true + break + } + } + + if !matched { + //如果二级指令白名单全部是*(忽略自身,那么不判断二级白名单是否匹配) + if allStarPrefixed { + if len(messageText) == len(matchedPrefix.Prefix) { + matched = true + } else { + matched = false + } } else { - matched = false - // 调用 GetVisualPrefixsBypass 获取前缀数组 - visualPrefixes := config.GetVisualPrefixsBypass() - // 判断 messageText 是否以数组中的任一前缀开头 - for _, prefix := range visualPrefixes { - if strings.HasPrefix(originmessageText, prefix) { + // 遍历白名单数组,检查是否有匹配项 + for _, prefix := range allPrefixes { + trimmedPrefix := prefix + if strings.HasPrefix(prefix, "*") { + // 如果前缀以 * 开头,则移除 * + trimmedPrefix = strings.TrimPrefix(prefix, "*") + } else if strings.HasPrefix(prefix, "&") { + // 如果前缀以 & 开头,则移除 & 并从 trimmedPrefix 前端去除 matchedPrefix.Prefix + trimmedPrefix = strings.TrimPrefix(prefix, "&") + trimmedPrefix = strings.TrimPrefix(trimmedPrefix, matchedPrefix.Prefix) + } + + // 从trimmedPrefix中去除前后空格 + trimmedPrefix = strings.TrimSpace(trimmedPrefix) + // trimmedPrefix如果是""就会导致任意内容都是true,所以不能是"" + if strings.HasPrefix(messageText, trimmedPrefix) && trimmedPrefix != "" { matched = true break } } } - } else { - // 遍历白名单数组,检查是否有匹配项 - for _, prefix := range allPrefixes { - trimmedPrefix := prefix - if strings.HasPrefix(prefix, "*") { - // 如果前缀以 * 开头,则移除 * - trimmedPrefix = strings.TrimPrefix(prefix, "*") - } else if strings.HasPrefix(prefix, "&") { - // 如果前缀以 & 开头,则移除 & 并从 trimmedPrefix 前端去除 matchedPrefix.Prefix - trimmedPrefix = strings.TrimPrefix(prefix, "&") - trimmedPrefix = strings.TrimPrefix(trimmedPrefix, matchedPrefix.Prefix) - } - - // 从trimmedPrefix中去除前后空格(可能会有bug) - trimmedPrefix = strings.TrimSpace(trimmedPrefix) - // trimmedPrefix如果是""就会导致任意内容都是true,所以不能是"" - if strings.HasPrefix(messageText, trimmedPrefix) && trimmedPrefix != "" { - matched = true - break - } - } } // 如果没有匹配项,则将 messageText 置为对应的兜底回复 diff --git a/handlers/send_group_msg.go b/handlers/send_group_msg.go index e66d1351..450be103 100644 --- a/handlers/send_group_msg.go +++ b/handlers/send_group_msg.go @@ -990,8 +990,24 @@ func generateGroupMessage(id string, eventid string, foundItems map[string][]str fileRecordData = silk.EncoderSilk(fileRecordData) mylog.Printf("音频转码ing") } + base64Encoded := base64.StdEncoding.EncodeToString(fileRecordData) + if config.GetUploadPicV2Base64() { + // 直接上传语音返回 MessageToCreate type=7 + messageToCreate, err := images.CreateAndUploadMediaMessage(context.TODO(), base64Encoded, eventid, 1, false, "", groupid, id, msgseq, apiv2) + if err != nil { + mylog.Printf("Error messageToCreate: %v", err) + return &dto.MessageToCreate{ + Content: "错误: 上传语音失败", + MsgID: id, + EventID: eventid, + MsgSeq: msgseq, + MsgType: 0, // 默认文本类型 + } + } + return messageToCreate + } // 将解码的语音数据转换回base64格式并上传 - imageURL, err := images.UploadBase64RecordToServer(base64.StdEncoding.EncodeToString(fileRecordData)) + imageURL, err := images.UploadBase64RecordToServer(base64Encoded) if err != nil { mylog.Printf("failed to upload base64 record: %v", err) return nil @@ -1578,8 +1594,24 @@ func generatePrivateMessage(id string, eventid string, foundItems map[string][]s fileRecordData = silk.EncoderSilk(fileRecordData) mylog.Printf("音频转码ing") } + base64Encoded := base64.StdEncoding.EncodeToString(fileRecordData) + if config.GetUploadPicV2Base64() { + // 直接上传语音返回 MessageToCreate type=7 + messageToCreate, err := images.CreateAndUploadMediaMessagePrivate(context.TODO(), base64Encoded, eventid, 1, false, "", userid, id, msgseq, apiv2) + if err != nil { + mylog.Printf("Error messageToCreate: %v", err) + return &dto.MessageToCreate{ + Content: "错误: 上传语音失败", + MsgID: id, + EventID: eventid, + MsgSeq: msgseq, + MsgType: 0, // 默认文本类型 + } + } + return messageToCreate + } // 将解码的语音数据转换回base64格式并上传 - imageURL, err := images.UploadBase64RecordToServer(base64.StdEncoding.EncodeToString(fileRecordData)) + imageURL, err := images.UploadBase64RecordToServer(base64Encoded) if err != nil { mylog.Printf("failed to upload base64 record: %v", err) return nil diff --git a/structs/structs.go b/structs/structs.go index b8b61106..e23552de 100644 --- a/structs/structs.go +++ b/structs/structs.go @@ -109,16 +109,17 @@ type Settings struct { //增长营销类 SelfIntroduce []string `yaml:"self_introduce"` //api修改 - GetGroupListAllGuilds bool `yaml:"get_g_list_all_guilds"` - GetGroupListGuilds string `yaml:"get_g_list_guilds"` - GetGroupListReturnGuilds bool `yaml:"get_g_list_return_guilds"` - GetGroupListGuidsType int `yaml:"get_g_list_guilds_type"` - GetGroupListDelay int `yaml:"get_g_list_delay"` - ForwardMsgLimit int `yaml:"forward_msg_limit"` - CustomBotName string `yaml:"custom_bot_name"` - TransFormApiIds bool `yaml:"transform_api_ids"` - AutoPutInteraction bool `yaml:"auto_put_interaction"` - PutInteractionDelay int `yaml:"put_interaction_delay"` + GetGroupListAllGuilds bool `yaml:"get_g_list_all_guilds"` + GetGroupListGuilds string `yaml:"get_g_list_guilds"` + GetGroupListReturnGuilds bool `yaml:"get_g_list_return_guilds"` + GetGroupListGuidsType int `yaml:"get_g_list_guilds_type"` + GetGroupListDelay int `yaml:"get_g_list_delay"` + ForwardMsgLimit int `yaml:"forward_msg_limit"` + CustomBotName string `yaml:"custom_bot_name"` + TransFormApiIds bool `yaml:"transform_api_ids"` + AutoPutInteraction bool `yaml:"auto_put_interaction"` + PutInteractionDelay int `yaml:"put_interaction_delay"` + PutInteractionExcept []string `yaml:"put_interaction_except"` //onebot修改 TwoWayEcho bool `yaml:"twoway_echo"` Array bool `yaml:"array"` diff --git a/template/config_template.go b/template/config_template.go index f952046d..8639f1d7 100644 --- a/template/config_template.go +++ b/template/config_template.go @@ -154,6 +154,7 @@ settings: transform_api_ids : true #对get_group_menmber_list\get_group_member_info\get_group_list生效,是否在其中返回转换后的值(默认转换,不转换请自行处理插件逻辑,比如调用gsk的http api转换) auto_put_interaction : false #自动回应按钮回调的/interactions/{interaction_id} 注本api需要邮件申请,详细方法参考群公告:196173384 put_interaction_delay : 0 #单位毫秒 表示回应已收到回调类型的按钮的毫秒数 会按用户进行区分 非全局delay + put_interaction_except : [] #自动回复按钮的例外,当你想要自己用api回复,回复特殊状态时,将指令前缀填入进去(根据按钮的data字段判断的) #Onebot修改 twoway_echo : false #是否采用双向echo,根据机器人选择,獭獭\早苗 true 红色问答\椛椛 或者其他 请使用 false