Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta463 #465

Merged
merged 18 commits into from
Jul 15, 2024
42 changes: 32 additions & 10 deletions Processor/ProcessC2CMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,19 @@ func (p *Processors) ProcessC2CMessage(data *dto.WSC2CMessageData) error {
//收到私聊信息调用的具体还原步骤
//1,idmap还原真实userid,
//发信息使用的是userid

messageID64, err := idmap.StoreCachev2(data.ID)
if err != nil {
log.Fatalf("Error storing ID: %v", err)
var messageID64 int64
if config.GetMemoryMsgid() {
messageID64, err = echo.StoreCacheInMemory(data.ID)
if err != nil {
log.Fatalf("Error storing ID: %v", err)
}
} else {
messageID64, err = idmap.StoreCachev2(data.ID)
if err != nil {
log.Fatalf("Error storing ID: %v", err)
}
}

messageID := int(messageID64)
if config.GetAutoBind() {
if len(data.Attachments) > 0 && data.Attachments[0].URL != "" {
Expand Down Expand Up @@ -139,14 +147,17 @@ func (p *Processors) ProcessC2CMessage(data *dto.WSC2CMessageData) error {
//其实不需要用AppIDString,因为gensokyo是单机器人框架
//可以试着开发一个,会很棒的
echo.AddMsgID(AppIDString, userid64, data.ID)

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

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

//储存类型
echo.AddMsgType(AppIDString, userid64, "group_private")
//储存当前群或频道号的类型
idmap.WriteConfigv2(fmt.Sprint(userid64), "type", "group_private")
//储存当前群或频道号的类型 私信不需要
//idmap.WriteConfigv2(data.ChannelID, "type", "group_private")

// 调试
PrintStructWithFieldNames(privateMsg)
Expand Down Expand Up @@ -205,10 +216,17 @@ func (p *Processors) ProcessC2CMessage(data *dto.WSC2CMessageData) error {
//框架内指令
p.HandleFrameworkCommand(messageText, data, "group_private")
//映射str的messageID到int
messageID64, err := idmap.StoreCachev2(data.ID)
if err != nil {
mylog.Printf("Error storing ID: %v", err)
return nil
var messageID64 int64
if config.GetMemoryMsgid() {
messageID64, err = echo.StoreCacheInMemory(data.ID)
if err != nil {
log.Fatalf("Error storing ID: %v", err)
}
} else {
messageID64, err = idmap.StoreCachev2(data.ID)
if err != nil {
log.Fatalf("Error storing ID: %v", err)
}
}
messageID := int(messageID64)
//todo 判断array模式 然后对Message处理成array格式
Expand Down Expand Up @@ -287,9 +305,13 @@ func (p *Processors) ProcessC2CMessage(data *dto.WSC2CMessageData) error {
echo.AddMsgType(AppIDString, userid64, "group_private")
//储存当前群或频道号的类型
idmap.WriteConfigv2(fmt.Sprint(userid64), "type", "group_private")

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

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

//调试
PrintStructWithFieldNames(groupMsg)

Expand Down
29 changes: 22 additions & 7 deletions Processor/ProcessChannelDirectMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,17 @@ func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData)
//3,通过idmap用channelid获取guildid,
//发信息使用的是guildid
//todo 优化数据库读写次数
messageID64, err := idmap.StoreCachev2(data.ID)
if err != nil {
log.Fatalf("Error storing ID: %v", err)
var messageID64 int64
if config.GetMemoryMsgid() {
messageID64, err = echo.StoreCacheInMemory(data.ID)
if err != nil {
log.Fatalf("Error storing ID: %v", err)
}
} else {
messageID64, err = idmap.StoreCachev2(data.ID)
if err != nil {
log.Fatalf("Error storing ID: %v", err)
}
}
messageID := int(messageID64)
//转换at
Expand Down Expand Up @@ -344,10 +352,17 @@ func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData)

//userid := int(userid64)
//映射str的messageID到int
messageID64, err := idmap.StoreCachev2(data.ID)
if err != nil {
mylog.Printf("Error storing ID: %v", err)
return nil
var messageID64 int64
if config.GetMemoryMsgid() {
messageID64, err = echo.StoreCacheInMemory(data.ID)
if err != nil {
log.Fatalf("Error storing ID: %v", err)
}
} else {
messageID64, err = idmap.StoreCachev2(data.ID)
if err != nil {
log.Fatalf("Error storing ID: %v", err)
}
}
messageID := int(messageID64)
// 如果在Array模式下, 则处理Message为Segment格式
Expand Down
16 changes: 12 additions & 4 deletions Processor/ProcessGroupMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package Processor

import (
"fmt"
"log"
"strconv"
"time"

Expand Down Expand Up @@ -78,10 +79,17 @@ func (p *Processors) ProcessGroupMessage(data *dto.WSGroupATMessageData) error {
//框架内指令
p.HandleFrameworkCommand(messageText, data, "group")
//映射str的messageID到int
messageID64, err := idmap.StoreCachev2(data.ID)
if err != nil {
mylog.Printf("Error storing ID: %v", err)
return nil
var messageID64 int64
if config.GetMemoryMsgid() {
messageID64, err = echo.StoreCacheInMemory(data.ID)
if err != nil {
log.Fatalf("Error storing ID: %v", err)
}
} else {
messageID64, err = idmap.StoreCachev2(data.ID)
if err != nil {
log.Fatalf("Error storing ID: %v", err)
}
}
messageID := int(messageID64)
if config.GetAutoBind() {
Expand Down
18 changes: 14 additions & 4 deletions Processor/ProcessGuildATMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package Processor

import (
"fmt"
"log"
"strconv"
"time"

Expand Down Expand Up @@ -195,10 +196,17 @@ func (p *Processors) ProcessGuildATMessage(data *dto.WSATMessageData) error {
echostr := fmt.Sprintf("%s_%d_%d", AppIDString, s, currentTimeMillis)

//映射str的messageID到int
messageID64, err := idmap.StoreCachev2(data.ID)
if err != nil {
mylog.Printf("Error storing ID: %v", err)
return nil
var messageID64 int64
if config.GetMemoryMsgid() {
messageID64, err = echo.StoreCacheInMemory(data.ID)
if err != nil {
log.Fatalf("Error storing ID: %v", err)
}
} else {
messageID64, err = idmap.StoreCachev2(data.ID)
if err != nil {
log.Fatalf("Error storing ID: %v", err)
}
}
messageID := int(messageID64)
// 如果在Array模式下, 则处理Message为Segment格式
Expand Down Expand Up @@ -288,6 +296,8 @@ func (p *Processors) ProcessGuildATMessage(data *dto.WSATMessageData) error {
echo.AddMsgType(AppIDString, ChannelID64, "guild")
//懒message_id池
echo.AddLazyMessageId(strconv.FormatInt(ChannelID64, 10), data.ID, time.Now())
//测试
echo.AddLazyMessageId(data.ChannelID, data.ID, time.Now())
//懒message_id池
//echo.AddLazyMessageId(strconv.FormatInt(userid64, 10), data.ID, time.Now())
//echo.AddLazyMessageIdv2(strconv.FormatInt(ChannelID64, 10), strconv.FormatInt(userid64, 10), data.ID, time.Now())
Expand Down
18 changes: 14 additions & 4 deletions Processor/ProcessGuildNormalMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package Processor

import (
"fmt"
"log"
"strconv"
"time"

Expand Down Expand Up @@ -191,10 +192,17 @@ func (p *Processors) ProcessGuildNormalMessage(data *dto.WSMessageData) error {
// 构造echostr,包括AppID,原始的s变量和当前时间戳
echostr := fmt.Sprintf("%s_%d_%d", AppIDString, s, currentTimeMillis)
//映射str的messageID到int
messageID64, err := idmap.StoreCachev2(data.ID)
if err != nil {
mylog.Printf("Error storing ID: %v", err)
return nil
var messageID64 int64
if config.GetMemoryMsgid() {
messageID64, err = echo.StoreCacheInMemory(data.ID)
if err != nil {
log.Fatalf("Error storing ID: %v", err)
}
} else {
messageID64, err = idmap.StoreCachev2(data.ID)
if err != nil {
log.Fatalf("Error storing ID: %v", err)
}
}
messageID := int(messageID64)
// 如果在Array模式下, 则处理Message为Segment格式
Expand Down Expand Up @@ -294,6 +302,8 @@ func (p *Processors) ProcessGuildNormalMessage(data *dto.WSMessageData) error {
echo.AddMsgType(AppIDString, ChannelID64, "guild")
//懒message_id池
echo.AddLazyMessageId(strconv.FormatInt(ChannelID64, 10), data.ID, time.Now())
//测试
echo.AddLazyMessageId(data.ChannelID, data.ID, time.Now())
//懒message_id池
//echo.AddLazyMessageId(strconv.FormatInt(userid64, 10), data.ID, time.Now())
//echo.AddLazyMessageIdv2(strconv.FormatInt(ChannelID64, 10), strconv.FormatInt(userid64, 10), data.ID, time.Now())
Expand Down
39 changes: 35 additions & 4 deletions Processor/ProcessInlineSearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ package Processor
import (
"context"
"fmt"
"log"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -52,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 Expand Up @@ -136,10 +155,22 @@ func (p *Processors) ProcessInlineSearch(data *dto.WSInteractionData) error {
IsBindedGroupId = idmap.CheckValuev2(GroupID64)
}

//平台事件,不是真实信息,无需messageID
messageID64 := 123
//映射str的messageID到int
var messageID64 int64
if config.GetMemoryMsgid() {
messageID64, err = echo.StoreCacheInMemory(data.ID)
if err != nil {
log.Fatalf("Error storing ID: %v", err)
}
} else {
messageID64, err = idmap.StoreCachev2(data.ID)
if err != nil {
log.Fatalf("Error storing ID: %v", err)
}
}

messageID := int(messageID64)

var selfid64 int64
if config.GetUseUin() {
selfid64 = config.GetUinint64()
Expand Down
16 changes: 12 additions & 4 deletions Processor/ProcessThreadMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package Processor
import (
"encoding/json"
"fmt"
"log"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -312,10 +313,17 @@ func (p *Processors) ProcessThreadMessage(data *dto.WSThreadData) error {
// 构造echostr,包括AppID,原始的s变量和当前时间戳
echostr := fmt.Sprintf("%s_%d_%d", AppIDString, s, currentTimeMillis)
//映射str的messageID到int
messageID64, err := idmap.StoreCachev2(data.ID)
if err != nil {
mylog.Printf("Error storing ID: %v", err)
return nil
var messageID64 int64
if config.GetMemoryMsgid() {
messageID64, err = echo.StoreCacheInMemory(data.ID)
if err != nil {
log.Fatalf("Error storing ID: %v", err)
}
} else {
messageID64, err = idmap.StoreCachev2(data.ID)
if err != nil {
log.Fatalf("Error storing ID: %v", err)
}
}
messageID := int(messageID64)
// 如果在Array模式下, 则处理Message为Segment格式
Expand Down
4 changes: 1 addition & 3 deletions Processor/Processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ func (p *Processors) HandleFrameworkCommand(messageText string, data interface{}
}

//link指令
if Type == "group" && strings.HasPrefix(cleanedMessage, config.GetLinkPrefix()) {
if strings.HasPrefix(cleanedMessage, config.GetLinkPrefix()) {
md, kb := generateMdByConfig()
SendMessageMd(md, kb, data, Type, p.Api, p.Apiv2)
}
Expand Down Expand Up @@ -845,7 +845,6 @@ func SendMessageMd(md *dto.Markdown, kb *keyboard.MessageKeyboard, data interfac
msgseq := echo.GetMappingSeq(msg.ID)
echo.AddMappingSeq(msg.ID, msgseq+1)
Message := &dto.MessageToCreate{
Content: "markdown",
MsgID: msg.ID,
MsgSeq: msgseq,
Markdown: md,
Expand Down Expand Up @@ -889,7 +888,6 @@ func SendMessageMd(md *dto.Markdown, kb *keyboard.MessageKeyboard, data interfac
msgseq := echo.GetMappingSeq(msg.ID)
echo.AddMappingSeq(msg.ID, msgseq+1)
Message := &dto.MessageToCreate{
Content: "markdown",
MsgID: msg.ID,
MsgSeq: msgseq,
Markdown: md,
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
11 changes: 8 additions & 3 deletions botgo/sessions/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ func (l *ChanManager) StartSingle(apInfo *dto.WebsocketAPSingle, token *token.To
apInfo.ShardCount, startInterval)

// 只启动一个分片

// 按照1数量初始化,用于启动连接的管理
l.sessionChan = make(chan dto.Session, 1)
session := dto.Session{
URL: apInfo.URL,
Token: *token,
Expand All @@ -80,9 +81,13 @@ func (l *ChanManager) StartSingle(apInfo *dto.WebsocketAPSingle, token *token.To
ShardCount: apInfo.ShardCount,
},
}
l.sessionChan <- session

time.Sleep(startInterval)
go l.newConnect(session)
for session := range l.sessionChan {
// MaxConcurrency 代表的是每 5s 可以连多少个请求
time.Sleep(startInterval)
go l.newConnect(session)
}

return nil
}
Expand Down
Loading
Loading