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

Test4 #26

Merged
merged 35 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
fad0d50
Compiled main.go and pushed changes
Hoshinonyaruko Oct 23, 2023
fda2572
test
Hoshinonyaruko Oct 23, 2023
34cfac1
适配了频道私聊,用bolt数据库取代ini
Hoshinonyaruko Oct 23, 2023
7fc1f10
适配了nonebot2
Hoshinonyaruko Oct 24, 2023
28f9a73
Merge branch 'main' of https://github.com/Hoshinonyaruko/Gensokyo
Hoshinonyaruko Oct 24, 2023
9fadda4
适配私域
Hoshinonyaruko Oct 24, 2023
1336c6a
add license
Hoshinonyaruko Oct 24, 2023
b094949
add a lot
Hoshinonyaruko Oct 25, 2023
f4787f5
Resolved merge conflicts
Hoshinonyaruko Oct 25, 2023
86698c6
trss support
Hoshinonyaruko Oct 26, 2023
045f3e9
fix
Hoshinonyaruko Oct 26, 2023
618561c
add action
Hoshinonyaruko Oct 26, 2023
7e803aa
add action
Hoshinonyaruko Oct 26, 2023
ece4cef
add action
Hoshinonyaruko Oct 26, 2023
f864a50
fixbug
Hoshinonyaruko Oct 26, 2023
4564731
add wss
Hoshinonyaruko Oct 26, 2023
070e4df
merge
Hoshinonyaruko Oct 26, 2023
84e8fe9
bugfix
Hoshinonyaruko Oct 26, 2023
0e4fd50
fix action
Hoshinonyaruko Oct 26, 2023
fe2234a
fix action again
Hoshinonyaruko Oct 26, 2023
cf67a11
fix action againnn
Hoshinonyaruko Oct 26, 2023
0875837
fa
Hoshinonyaruko Oct 26, 2023
3a3c33f
fix
Hoshinonyaruko Oct 26, 2023
8789fa8
add a lot
Hoshinonyaruko Oct 27, 2023
7943466
add ws server token
Hoshinonyaruko Oct 28, 2023
4660983
merge
Hoshinonyaruko Oct 28, 2023
2a1026a
bugifx
Hoshinonyaruko Oct 28, 2023
4186970
fix
Hoshinonyaruko Oct 28, 2023
2f26828
fixat
Hoshinonyaruko Oct 28, 2023
007e1af
bugfix
Hoshinonyaruko Oct 28, 2023
c41fd77
bugfix
Hoshinonyaruko Oct 28, 2023
d8354b7
test
Hoshinonyaruko Oct 28, 2023
6e3c63c
test
Hoshinonyaruko Oct 28, 2023
f08d9d7
test2
Hoshinonyaruko Oct 28, 2023
4dd6e15
add url service
Hoshinonyaruko Oct 31, 2023
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
6 changes: 3 additions & 3 deletions echo/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ var globalEchoMapping = &EchoMapping{
msgIDMapping: make(map[string]string),
}

func (e *EchoMapping) generateKey(appid string, s int64) string {
func (e *EchoMapping) GenerateKey(appid string, s int64) string {
return appid + "_" + strconv.FormatInt(s, 10)
}

// 添加echo对应的类型
func AddMsgType(appid string, s int64, msgType string) {
key := globalEchoMapping.generateKey(appid, s)
key := globalEchoMapping.GenerateKey(appid, s)
globalEchoMapping.mu.Lock()
defer globalEchoMapping.mu.Unlock()
globalEchoMapping.msgTypeMapping[key] = msgType
}

// 添加echo对应的messageid
func AddMsgID(appid string, s int64, msgID string) {
key := globalEchoMapping.generateKey(appid, s)
key := globalEchoMapping.GenerateKey(appid, s)
globalEchoMapping.mu.Lock()
defer globalEchoMapping.mu.Unlock()
globalEchoMapping.msgIDMapping[key] = msgID
Expand Down
9 changes: 5 additions & 4 deletions handlers/get_group_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"log"
"strconv"

"github.com/hoshinonyaruko/gensokyo/callapi"
"github.com/hoshinonyaruko/gensokyo/idmap"
Expand All @@ -28,11 +27,13 @@ type OnebotGroupInfo struct {
}

func ConvertGuildToGroupInfo(guild *dto.Guild, GroupId string) *OnebotGroupInfo {
groupidstr, err := strconv.ParseInt(GroupId, 10, 64)
// 使用idmap.StoreIDv2映射GroupId到一个int64的值
groupid64, err := idmap.StoreIDv2(GroupId)
if err != nil {
log.Printf("groupidstr: %v", err)
log.Printf("Error storing GroupID: %v", err)
return nil
}

ts, err := guild.JoinedAt.Time()
if err != nil {
log.Printf("转换JoinedAt失败: %v", err)
Expand All @@ -41,7 +42,7 @@ func ConvertGuildToGroupInfo(guild *dto.Guild, GroupId string) *OnebotGroupInfo
groupCreateTime := uint32(ts.Unix())

return &OnebotGroupInfo{
GroupID: groupidstr,
GroupID: groupid64,
GroupName: guild.Name,
GroupMemo: guild.Desc,
GroupCreateTime: groupCreateTime,
Expand Down
5 changes: 5 additions & 0 deletions handlers/send_guild_channel_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func handleSendGuildChannelMsg(client callapi.Client, api openapi.OpenAPI, apiv2
messageID = echo.GetMsgIDByKey(echoStr)
log.Println("echo取频道发信息对应的message_id:", messageID)
}
// 如果messageID为空,通过函数获取
if messageID == "" {
messageID = GetMessageIDByUseridOrGroupid(config.GetAppIDStr(), channelID)
log.Println("通过GetMessageIDByUserid函数获取的message_id:", messageID)
}
log.Println("频道发信息messageText:", messageText)
log.Println("foundItems:", foundItems)
var err error
Expand Down
5 changes: 5 additions & 0 deletions handlers/send_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ func handleSendMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openapi.Ope
messageID = echo.GetMsgIDByKey(echoStr)
log.Println("echo取私聊发信息对应的message_id:", messageID)
}
// 如果messageID为空,通过函数获取
if messageID == "" {
messageID = GetMessageIDByUseridOrGroupid(config.GetAppIDStr(), UserID)
log.Println("通过GetMessageIDByUserid函数获取的message_id:", messageID)
}
log.Println("私聊发信息messageText:", messageText)
log.Println("foundItems:", foundItems)

Expand Down
10 changes: 10 additions & 0 deletions handlers/send_private_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ func handleSendPrivateMsg(client callapi.Client, api openapi.OpenAPI, apiv2 open
messageID = echo.GetMsgIDByKey(echoStr)
log.Println("echo取私聊发信息对应的message_id:", messageID)
}
// 如果messageID仍然为空,尝试使用config.GetAppID和UserID的组合来获取messageID
// 如果messageID为空,通过函数获取
if messageID == "" {
messageID = GetMessageIDByUseridOrGroupid(config.GetAppIDStr(), UserID)
log.Println("通过GetMessageIDByUserid函数获取的message_id:", messageID)
}
log.Println("私聊发信息messageText:", messageText)
log.Println("foundItems:", foundItems)

Expand All @@ -66,6 +72,8 @@ func handleSendPrivateMsg(client callapi.Client, api openapi.OpenAPI, apiv2 open
if err != nil {
log.Printf("发送文本私聊信息失败: %v", err)
}
//发送成功回执
SendResponse(client, err, &message)
}

// 遍历 foundItems 并发送每种信息
Expand All @@ -85,6 +93,8 @@ func handleSendPrivateMsg(client callapi.Client, api openapi.OpenAPI, apiv2 open
if err != nil {
log.Printf("发送 %s 私聊信息失败: %v", key, err)
}
//发送成功回执
SendResponse(client, err, &message)
}
case "guild_private":
//当收到发私信调用 并且来源是频道
Expand Down
Loading