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 #27

Merged
merged 37 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 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
1f8c174
add url service
Hoshinonyaruko Oct 31, 2023
240f569
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
19 changes: 10 additions & 9 deletions Processor/ProcessChannelDirectMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData)
if err != nil {
log.Fatalf("Error storing ID: %v", err)
}

//将真实id写入数据库,可取出ChannelID
idmap.WriteConfigv2(data.Author.ID, "channel_id", data.ChannelID)
//将channelid写入数据库,可取出guild_id
Expand Down Expand Up @@ -177,20 +178,20 @@ func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData)
p.BroadcastMessageToAll(msgMap)
} else {
//将频道信息转化为群信息(特殊需求情况下)
//将channelid写入ini,可取出guild_id
idmap.WriteConfigv2(data.ChannelID, "guild_id", data.GuildID)
//将channelid写入bolt,可取出guild_id
ChannelID64, err := idmap.StoreIDv2(data.ChannelID)
if err != nil {
log.Printf("Error storing ID: %v", err)
return nil
}
//转成int再互转
idmap.WriteConfigv2(fmt.Sprint(ChannelID64), "guild_id", data.GuildID)
//转换at
messageText := handlers.RevertTransformedText(data)
//转换appid
AppIDString := strconv.FormatUint(p.Settings.AppID, 10)
//构造echo
echostr := AppIDString + "_" + strconv.FormatInt(s, 10)
//把频道号作为群号
channelIDInt, err := strconv.Atoi(data.ChannelID)
if err != nil {
// handle error, perhaps return it
return fmt.Errorf("failed to convert ChannelID to int: %v", err)
}
//映射str的userid到int
userid64, err := idmap.StoreIDv2(data.Author.ID)
if err != nil {
Expand All @@ -214,7 +215,7 @@ func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData)
RawMessage: messageText,
Message: segmentedMessages,
MessageID: messageID,
GroupID: int64(channelIDInt),
GroupID: ChannelID64,
MessageType: "group",
PostType: "message",
SelfID: int64(p.Settings.AppID),
Expand Down
2 changes: 0 additions & 2 deletions Processor/ProcessGroupMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ func (p *Processors) ProcessGroupMessage(data *dto.WSGroupATMessageData) error {
// 获取s
s := client.GetGlobalS()

idmap.WriteConfigv2(data.ChannelID, "guild_id", data.GuildID)

// 转换at
messageText := handlers.RevertTransformedText(data)

Expand Down
22 changes: 11 additions & 11 deletions Processor/ProcessGuildATMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,20 @@ func (p *Processors) ProcessGuildATMessage(data *dto.WSATMessageData) error {
//将频道转化为一个群
//获取s
s := client.GetGlobalS()
//将channelid写入ini,可取出guild_id todo 比ini更好的储存方式
idmap.WriteConfigv2(data.ChannelID, "guild_id", data.GuildID)
//将channelid写入ini,可取出guild_id
ChannelID64, err := idmap.StoreIDv2(data.ChannelID)
if err != nil {
log.Printf("Error storing ID: %v", err)
return nil
}
//转成int再互转
idmap.WriteConfigv2(fmt.Sprint(ChannelID64), "guild_id", data.GuildID)
//转换at和图片
messageText := handlers.RevertTransformedText(data)
//转换appid
AppIDString := strconv.FormatUint(p.Settings.AppID, 10)
//构造echo
echostr := AppIDString + "_" + strconv.FormatInt(s, 10)
//把频道号作为群号
channelIDInt, err := strconv.Atoi(data.ChannelID)
if err != nil {
// handle error, perhaps return it
return fmt.Errorf("failed to convert ChannelID to int: %v", err)
}
//映射str的userid到int
userid64, err := idmap.StoreIDv2(data.Author.ID)
if err != nil {
Expand All @@ -142,7 +142,7 @@ func (p *Processors) ProcessGuildATMessage(data *dto.WSATMessageData) error {
RawMessage: messageText,
Message: segmentedMessages,
MessageID: messageID,
GroupID: int64(channelIDInt),
GroupID: ChannelID64,
MessageType: "group",
PostType: "message",
SelfID: int64(p.Settings.AppID),
Expand Down Expand Up @@ -178,8 +178,8 @@ func (p *Processors) ProcessGuildATMessage(data *dto.WSATMessageData) error {
echo.AddMsgID(AppIDString, s, data.ID)
echo.AddMsgType(AppIDString, s, "guild")
//为不支持双向echo的ob服务端映射
echo.AddMsgID(AppIDString, int64(channelIDInt), data.ID)
echo.AddMsgType(AppIDString, int64(channelIDInt), "guild")
echo.AddMsgID(AppIDString, ChannelID64, data.ID)
echo.AddMsgType(AppIDString, ChannelID64, "guild")
//储存当前群或频道号的类型
idmap.WriteConfigv2(data.ChannelID, "type", "guild")

Expand Down
22 changes: 11 additions & 11 deletions Processor/ProcessGuildNormalMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,20 @@ func (p *Processors) ProcessGuildNormalMessage(data *dto.WSMessageData) error {
//将频道转化为一个群
//获取s
s := client.GetGlobalS()
//将channelid写入ini,可取出guild_id todo 比ini更好的储存方式
idmap.WriteConfigv2(data.ChannelID, "guild_id", data.GuildID)
//将channelid写入ini,可取出guild_id
ChannelID64, err := idmap.StoreIDv2(data.ChannelID)
if err != nil {
log.Printf("Error storing ID: %v", err)
return nil
}
//转成int再互转
idmap.WriteConfigv2(fmt.Sprint(ChannelID64), "guild_id", data.GuildID)
//转换at
messageText := handlers.RevertTransformedText(data)
//转换appid
AppIDString := strconv.FormatUint(p.Settings.AppID, 10)
//构造echo
echostr := AppIDString + "_" + strconv.FormatInt(s, 10)
//把频道号作为群号
channelIDInt, err := strconv.Atoi(data.ChannelID)
if err != nil {
// handle error, perhaps return it
return fmt.Errorf("failed to convert ChannelID to int: %v", err)
}
//映射str的userid到int
userid64, err := idmap.StoreIDv2(data.Author.ID)
if err != nil {
Expand All @@ -141,7 +141,7 @@ func (p *Processors) ProcessGuildNormalMessage(data *dto.WSMessageData) error {
RawMessage: messageText,
Message: segmentedMessages,
MessageID: messageID,
GroupID: int64(channelIDInt),
GroupID: ChannelID64,
MessageType: "group",
PostType: "message",
SelfID: int64(p.Settings.AppID),
Expand Down Expand Up @@ -177,8 +177,8 @@ func (p *Processors) ProcessGuildNormalMessage(data *dto.WSMessageData) error {
echo.AddMsgID(AppIDString, s, data.ID)
echo.AddMsgType(AppIDString, s, "guild")
//为不支持双向echo的ob服务端映射
echo.AddMsgID(AppIDString, int64(channelIDInt), data.ID)
echo.AddMsgType(AppIDString, int64(channelIDInt), "guild")
echo.AddMsgID(AppIDString, ChannelID64, data.ID)
echo.AddMsgType(AppIDString, ChannelID64, "guild")
//储存当前群或频道号的类型
idmap.WriteConfigv2(data.ChannelID, "type", "guild")

Expand Down
18 changes: 8 additions & 10 deletions handlers/get_group_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handlers
import (
"context"
"encoding/json"
"fmt"
"log"

"github.com/hoshinonyaruko/gensokyo/callapi"
Expand Down Expand Up @@ -57,8 +58,13 @@ func handleGetGroupInfo(client callapi.Client, api openapi.OpenAPI, apiv2 openap

//用GroupID给ChannelID赋值,因为我们是把频道虚拟成了群
ChannelID := params.GroupID
// 使用RetrieveRowByIDv2还原真实的ChannelID
RChannelID, err := idmap.RetrieveRowByIDv2(ChannelID.(string))
if err != nil {
fmt.Printf("error retrieving real ChannelID: %v", err)
}
//读取ini 通过ChannelID取回之前储存的guild_id
value, err := idmap.ReadConfigv2(ChannelID.(string), "guild_id")
value, err := idmap.ReadConfigv2(RChannelID, "guild_id")
if err != nil {
log.Printf("handleGetGroupInfo:Error reading config: %v\n", err)
return
Expand All @@ -71,16 +77,8 @@ func handleGetGroupInfo(client callapi.Client, api openapi.OpenAPI, apiv2 openap
log.Printf("获取频道信息失败: %v", err)
return
}
//用group_id还原出channelid 这是虚拟成群的私聊信息
message.Params.ChannelID = message.Params.GroupID.(string)
//读取ini 通过ChannelID取回之前储存的guild_id
GroupId, err := idmap.ReadConfigv2(message.Params.ChannelID, "guild_id")
if err != nil {
log.Printf("Error reading config: %v", err)
return
}
groupInfo := ConvertGuildToGroupInfo(guild, GroupId)

groupInfo := ConvertGuildToGroupInfo(guild, guildID)
groupInfoMap := structToMap(groupInfo)

// 打印groupInfoMap的内容
Expand Down
7 changes: 6 additions & 1 deletion handlers/get_group_member_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ func getGroupMemberList(client callapi.Client, api openapi.OpenAPI, apiv2 openap
//要把group_id还原成guild_id
//用group_id还原出channelid 这是虚拟成群的私聊信息
message.Params.ChannelID = message.Params.GroupID.(string)
// 使用RetrieveRowByIDv2还原真实的ChannelID
RChannelID, err := idmap.RetrieveRowByIDv2(message.Params.ChannelID)
if err != nil {
log.Printf("error retrieving real ChannelID: %v", err)
}
//读取ini 通过ChannelID取回之前储存的guild_id
value, err := idmap.ReadConfigv2(message.Params.ChannelID, "guild_id")
value, err := idmap.ReadConfigv2(RChannelID, "guild_id")
if err != nil {
log.Printf("Error reading config: %v", err)
return
Expand Down
15 changes: 7 additions & 8 deletions handlers/send_group_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,19 @@ func handleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
case "guild":
//用GroupID给ChannelID赋值,因为我们是把频道虚拟成了群
message.Params.ChannelID = message.Params.GroupID.(string)
//读取ini 通过ChannelID取回之前储存的guild_id
// value, err := idmap.ReadConfigv2(message.Params.ChannelID, "guild_id")
// if err != nil {
// log.Printf("Error reading config: %v", err)
// return
// }
//这一句是group_private的逻辑,发频道信息用的是channelid,只有频道private需要guildid才需要这些逻辑
//这一句是group_private的逻辑,发频道信息用的是channelid
//message.Params.GroupID = value
handleSendGuildChannelMsg(client, api, apiv2, message)
case "guild_private":
//用group_id还原出channelid 这是虚拟成群的私聊信息
message.Params.ChannelID = message.Params.GroupID.(string)
// 使用RetrieveRowByIDv2还原真实的ChannelID
RChannelID, err := idmap.RetrieveRowByIDv2(message.Params.ChannelID)
if err != nil {
log.Printf("error retrieving real ChannelID: %v", err)
}
//读取ini 通过ChannelID取回之前储存的guild_id
value, err := idmap.ReadConfigv2(message.Params.ChannelID, "guild_id")
value, err := idmap.ReadConfigv2(RChannelID, "guild_id")
if err != nil {
log.Printf("Error reading config: %v", err)
return
Expand Down
15 changes: 7 additions & 8 deletions handlers/send_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,6 @@ func handleSendMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openapi.Ope
case "guild":
//用GroupID给ChannelID赋值,因为我们是把频道虚拟成了群
message.Params.ChannelID = message.Params.GroupID.(string)
//读取ini 通过ChannelID取回之前储存的guild_id
// value, err := idmap.ReadConfigv2(message.Params.ChannelID, "guild_id")
// if err != nil {
// log.Printf("Error reading config: %v", err)
// return
// }
// message.Params.GroupID = value
handleSendGuildChannelMsg(client, api, apiv2, message)
case "guild_private":
//send_msg比具体的send_xxx少一层,其包含的字段类型在虚拟化场景已经失去作用
Expand All @@ -137,8 +130,14 @@ func handleSendMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openapi.Ope
// 先尝试将GroupID断言为字符串
if channelID, ok := message.Params.GroupID.(string); ok && channelID != "" {
channelIDPtr = &channelID
// 使用RetrieveRowByIDv2还原真实的UserID
RChannelID, err := idmap.RetrieveRowByIDv2(*channelIDPtr)
if err != nil {
log.Printf("error retrieving real ChannelID: %v", err)
return
}
// 读取bolt数据库 通过ChannelID取回之前储存的guild_id
if value, err := idmap.ReadConfigv2(channelID, "guild_id"); err == nil && value != "" {
if value, err := idmap.ReadConfigv2(RChannelID, "guild_id"); err == nil && value != "" {
GuildidPtr = &value
} else {
log.Printf("Error reading config: %v", err)
Expand Down
8 changes: 6 additions & 2 deletions handlers/send_private_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,13 @@ func getGuildIDFromMessage(message callapi.ActionMessage) (string, string, error
if err != nil {
return "", "", fmt.Errorf("error reading channel_id: %v", err)
}

// 使用RetrieveRowByIDv2还原真实的ChannelID
RChannelID, err := idmap.RetrieveRowByIDv2(channelID)
if err != nil {
log.Printf("error retrieving real UserID: %v", err)
}
// 使用channelID作为sectionName从数据库中获取guild_id
guildID, err := idmap.ReadConfigv2(channelID, "guild_id")
guildID, err := idmap.ReadConfigv2(RChannelID, "guild_id")
if err != nil {
return "", "", fmt.Errorf("error reading guild_id: %v", err)
}
Expand Down
10 changes: 7 additions & 3 deletions handlers/set_group_ban.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ func setGroupBan(client callapi.Client, api openapi.OpenAPI, apiv2 openapi.OpenA
// 从message中获取group_id和UserID
groupID := message.Params.GroupID.(string)
receivedUserID := message.Params.UserID.(string)

// 根据group_id读取guild_id
guildID, err := idmap.ReadConfigv2(groupID, "guild_id")
// 使用RetrieveRowByIDv2还原真实的ChannelID
RChannelID, err := idmap.RetrieveRowByIDv2(groupID)
if err != nil {
log.Printf("error retrieving real UserID: %v", err)
}
// 根据RChannelID读取guild_id
guildID, err := idmap.ReadConfigv2(RChannelID, "guild_id")
if err != nil {
log.Printf("Error reading config for guild_id: %v", err)
return
Expand Down
8 changes: 6 additions & 2 deletions handlers/set_group_whole_ban.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ func init() {
func setGroupWholeBan(client callapi.Client, api openapi.OpenAPI, apiv2 openapi.OpenAPI, message callapi.ActionMessage) {
// 从message中获取group_id
groupID := message.Params.GroupID.(string)

// 使用RetrieveRowByIDv2还原真实的ChannelID
RChannelID, err := idmap.RetrieveRowByIDv2(groupID)
if err != nil {
log.Printf("error retrieving real UserID: %v", err)
}
// 根据group_id读取guild_id
guildID, err := idmap.ReadConfigv2(groupID, "guild_id")
guildID, err := idmap.ReadConfigv2(RChannelID, "guild_id")
if err != nil {
log.Printf("Error reading config for guild_id: %v", err)
return
Expand Down
11 changes: 9 additions & 2 deletions idmap/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,18 @@ func WriteConfig(sectionName, keyName, value string) error {
return db.Update(func(tx *bolt.Tx) error {
b, err := tx.CreateBucketIfNotExists([]byte(ConfigBucket))
if err != nil {
return err
log.Printf("Error creating or accessing bucket: %v", err)
return fmt.Errorf("failed to access or create bucket %s: %w", ConfigBucket, err)
}

key := joinSectionAndKey(sectionName, keyName)
return b.Put(key, []byte(value))
err = b.Put(key, []byte(value))
if err != nil {
log.Printf("Error putting data into bucket with key %s: %v", key, err)
return fmt.Errorf("failed to put data into bucket with key %s: %w", key, err)
}
//log.Printf("Data saved successfully with key %s,value %s", key, value)
return nil
})
}

Expand Down
21 changes: 2 additions & 19 deletions url/shorturl.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,32 +296,15 @@ func CreateShortURLHandler(c *gin.Context) {

// Construct baseUrl
serverDir := config.GetServer_dir()
portValue := config.GetPortValue()
protocol := "http"
if portValue == "443" {
protocol = "https"
}
baseUrl := protocol + "://" + serverDir
if portValue != "80" && portValue != "443" && portValue != "" {
baseUrl += ":" + portValue
}
baseUrl := "https://" + serverDir

c.JSON(http.StatusOK, gin.H{"shortURL": baseUrl + "/url/" + shortURL})
}

// 短链接baseurl
func GetBaseURL() string {
serverDir := config.GetServer_dir()
portValue := config.GetPortValue()
protocol := "http"
if portValue == "443" {
protocol = "https"
}
baseUrl := protocol + "://" + serverDir
if portValue != "80" && portValue != "443" && portValue != "" {
baseUrl += ":" + portValue
}
return baseUrl
return "https://" + serverDir
}

// RedirectFromShortURLHandler
Expand Down
Loading