Skip to content

Commit

Permalink
Beta462 (#464)
Browse files Browse the repository at this point in the history
* beta447

* beta448

* beta449

* beta450

* beta451

* beta452

* beta453

* beta454

* beta455

* btea455

* beta456

* beta457

* beta458

* beta460

* beta460

* beta461

* beta462
  • Loading branch information
Hoshinonyaruko authored Jul 13, 2024
1 parent f4698f4 commit 04d046d
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 49 deletions.
22 changes: 20 additions & 2 deletions Processor/ProcessInlineSearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"log"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions acnode/acnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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字符)"
}
Expand Down
12 changes: 12 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
63 changes: 33 additions & 30 deletions handlers/message_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 置为对应的兜底回复
Expand Down
36 changes: 34 additions & 2 deletions handlers/send_group_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 11 additions & 10 deletions structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
1 change: 1 addition & 0 deletions template/config_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 04d046d

Please sign in to comment.