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

Beta459 #459

Merged
merged 14 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
24 changes: 24 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2340,3 +2340,27 @@ func GetLinkNum() int {

return instance.Settings.LinkNum
}

// 获取GetDoNotReplaceAppid的值
func GetDoNotReplaceAppid() bool {
mu.Lock()
defer mu.Unlock()

if instance == nil {
mylog.Println("Warning: instance is nil when trying to DoNotReplaceAppid value.")
return false
}
return instance.Settings.DoNotReplaceAppid
}

// 获取GetMemoryMsgid的值
func GetMemoryMsgid() bool {
mu.Lock()
defer mu.Unlock()

if instance == nil {
mylog.Println("Warning: instance is nil when trying to MemoryMsgid value.")
return false
}
return instance.Settings.MemoryMsgid
}
40 changes: 40 additions & 0 deletions docs/api介绍.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
目前支持的API列表

具体api的定义请参考[onebot-11](https://github.com/botuniverse/onebot-11)

### 支持的API列表

1. `/avatar` - avatar.go
2. `/delete_msg` - delete_msg.go
3. `/get_avatar` - get_avatar.go
4. `/get_friend_list` - get_friend_list.go
5. `/get_group_info` - get_group_info.go
6. `/get_group_list` - get_group_list.go
7. `/get_group_member_info` - get_group_member_info.go
8. `/get_group_member_list` - get_group_member_list.go
9. `/get_guild_channel_list` - get_guild_channel_list.go
10. `/get_guild_list` - get_guild_list.go
11. `/get_guild_service_profile` - get_guild_service_profile.go
12. `/get_login_info` - get_login_info.go
13. `/get_online_clients` - get_online_clients.go
14. `/get_status` - get_status.go
15. `/get_version_info` - get_version_info.go
16. `/handle_quick_operation` - handle_quick_operation.go
17. `/handle_quick_operation_async` - handle_quick_operation_async.go
18. `/mark_msg_as_read` - mark_msg_as_read.go
19. `/message_parser` - message_parser.go
20. `/put_interaction` - put_interaction.go
21. `/send_group_forward_msg` - send_group_forward_msg.go
22. `/send_group_msg` - send_group_msg.go
23. `/send_group_msg_async` - send_group_msg_async.go
24. `/send_group_msg_raw` - send_group_msg_raw.go
25. `/send_guild_channel_forum` - send_guild_channel_forum.go
26. `/send_guild_channel_msg` - send_guild_channel_msg.go
27. `/send_guild_private_msg` - send_guild_private_msg.go
28. `/send_msg` - send_msg.go
29. `/send_msg_async` - send_msg_async.go
30. `/send_private_msg` - send_private_msg.go
31. `/send_private_msg_async` - send_private_msg_async.go
32. `/send_private_msg_sse` - send_private_msg_sse.go
33. `/set_group_ban` - set_group_ban.go
34. `/set_group_whole_ban` - set_group_whole_ban.go
17 changes: 17 additions & 0 deletions docs/api差异-delete_msg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# API: delete_msg

撤回消息。

## 参数

| 字段名 | 数据类型 | 默认值 | 说明 |
|-------------|----------------|--------|-----------------------------------|
| message_id | number (int32) | - | 消息 ID |
| user_id | number | - | 对方 QQ 号(消息类型为 private 时需要) |
| group_id | number | - | 群号(消息类型为 group 时需要) |
| channel_id | number | - | 频道号(消息类型是 guild 时需要) |
| guild_id | number | - | 子频道号(消息类型是 guild_Private 时需要) |

## 响应数据

Loading
Loading