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

Beta456 #456

Merged
merged 11 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
31 changes: 23 additions & 8 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 @@ -205,10 +213,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
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
16 changes: 12 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
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
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 时需要) |

## 响应数据

54 changes: 54 additions & 0 deletions docs/文档-markdown message segment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
```markdown
# Gensokyo Markdown Segment

Gensokyo的Markdown Segment是对现有OneBot v11的扩展。

## Markdown卡片(文本形式)

```json
{
"type": "markdown",
"data": {
"data": "文本内容"
}
}
```

| 参数名 | 收 | 发 | 可能的值 | 说明 |
|----------|----|----|----------|-------------|
| data | ✓ | ✓ | - | md文本 |

**文本内容为**:
- [链接](https://www.yuque.com/km57bt/hlhnxg/ddkv4a2lgcswitei) 中markdown的json字符串的base64(以base64://开头,文字处理为/u形式的unicode)或按以下规则处理后的,json实体化文本。

**转义**:
CQ 码由字符 [ 起始, 以 ] 结束, 并且以 , 分割各个参数。如果你的 CQ 码中, 参数值包括了这些字符, 那么它们应该被使用 HTML 特殊字符的编码方式进行转义。

字符 | 对应实体转义序列
-----|------------------
& | &
[ | [
] | ]
, | ,

## Markdown卡片(object形式)

```json
{
"type": "markdown",
"data": {
"data": md object
}
}
```

| 参数名 | 收 | 发 | 可能的值 | 说明 |
|----------|----|----|----------|-------------|
| data | ✓ | ✓ | - | md object |

**结构请参考**:
支持MessageSegment [链接](https://www.yuque.com/km57bt/hlhnxg/ddkv4a2lgcswitei) 与文本形式实际包含内容相同,但传参类型不同,不是string,而是你所组合的md卡片object(map)。

data下层应包含data(2层data),data.markdown,data.keyboard。
同时与type同级的data字段是OneBot v11标准固定的,所以json结构会呈现data.data.markdown,data.data.keyboard双层结构。
```
Loading
Loading