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

Beta495 #501

Merged
merged 51 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
a6ebe57
beta447
Hoshinonyaruko Jun 29, 2024
1d63fae
beta448
Hoshinonyaruko Jul 1, 2024
cd34627
beta449
Hoshinonyaruko Jul 4, 2024
b790b29
beta450
Hoshinonyaruko Jul 4, 2024
7a9b56a
beta451
Hoshinonyaruko Jul 4, 2024
e17d0d4
beta452
Hoshinonyaruko Jul 4, 2024
1318175
beta453
Hoshinonyaruko Jul 4, 2024
b7f291c
beta454
Hoshinonyaruko Jul 4, 2024
f921895
beta455
Hoshinonyaruko Jul 9, 2024
24108c6
btea455
Hoshinonyaruko Jul 9, 2024
7cdc968
beta456
Hoshinonyaruko Jul 9, 2024
b5d784e
beta457
Hoshinonyaruko Jul 9, 2024
61e4001
beta458
Hoshinonyaruko Jul 9, 2024
6d4116a
beta460
Hoshinonyaruko Jul 9, 2024
2c1f1b7
beta460
Hoshinonyaruko Jul 11, 2024
5c312cd
beta461
Hoshinonyaruko Jul 12, 2024
58304eb
beta462
Hoshinonyaruko Jul 13, 2024
7e7c9f3
beta463
Hoshinonyaruko Jul 15, 2024
188f250
beta464
Hoshinonyaruko Jul 15, 2024
af0296d
beta465
Hoshinonyaruko Jul 18, 2024
500135c
beta467
Hoshinonyaruko Jul 21, 2024
c1a588c
beta468
Hoshinonyaruko Jul 21, 2024
1df8e15
beta469
Hoshinonyaruko Jul 21, 2024
f57ab7b
beta470
Hoshinonyaruko Jul 26, 2024
cd21ad9
beta471
Hoshinonyaruko Aug 1, 2024
6039272
beta472
Hoshinonyaruko Aug 1, 2024
c45b450
beta473
Hoshinonyaruko Aug 1, 2024
f89d6c5
beta473
Hoshinonyaruko Aug 3, 2024
b54fdee
beta475
Hoshinonyaruko Aug 5, 2024
a30a697
beta476
Hoshinonyaruko Aug 8, 2024
ab805cc
beta478
Hoshinonyaruko Aug 8, 2024
6debefd
beta479
Hoshinonyaruko Aug 17, 2024
9cc7e5d
beta479
Hoshinonyaruko Aug 17, 2024
c0fe93c
beta480
Hoshinonyaruko Aug 18, 2024
91cf223
beta481
Hoshinonyaruko Aug 18, 2024
a3aa6c1
beta482
Hoshinonyaruko Aug 18, 2024
0917e56
beta483
Hoshinonyaruko Aug 19, 2024
dd1f774
beta484
Hoshinonyaruko Aug 19, 2024
1c87d61
beta485
Hoshinonyaruko Aug 20, 2024
aac474a
beta486
Hoshinonyaruko Aug 20, 2024
2604eb7
beta486
Hoshinonyaruko Aug 20, 2024
76377be
beta487
Hoshinonyaruko Aug 20, 2024
cb095ec
beta487
Hoshinonyaruko Aug 20, 2024
34c92ae
beta489
Hoshinonyaruko Aug 21, 2024
288cf7a
beta490
Hoshinonyaruko Aug 22, 2024
d3a6eb8
beta491
Hoshinonyaruko Aug 22, 2024
b2de7c5
beta492
Hoshinonyaruko Oct 13, 2024
ec68fb1
beta492-1
Hoshinonyaruko Oct 13, 2024
f4d9229
beta494
Hoshinonyaruko Oct 13, 2024
def45ca
beta495
Hoshinonyaruko Oct 13, 2024
86ff924
Merge branch 'main' into beta495
Hoshinonyaruko Oct 13, 2024
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
8 changes: 4 additions & 4 deletions .github/workflows/cross_compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
go build -ldflags="-s -w" -o output/gensokyo-${{ matrix.os }}-${{ matrix.goarch }}
fi

- name: Compress executable files with UPX (except for gensokyo-android-arm64)
- name: Compress executable files with UPX (except for gensokyo-android-arm64 and macOS)
run: |
sudo apt-get update
sudo apt-get install -y upx
Expand All @@ -109,14 +109,14 @@ jobs:
else
FILENAME="output/gensokyo-${{ matrix.os }}-${{ matrix.goarch }}"
fi
if [[ "${{ matrix.os }}" == "android" && "${{ matrix.goarch }}" == "arm64" ]]; then
if [[ "${{ matrix.os }}" == "android" && "${{ matrix.goarch }}" == "arm64" ]] || [[ "${{ matrix.os }}" == "macos" ]]; then
echo "Skipping UPX compression for $FILENAME"
else
upx --best --lzma "$FILENAME"
fi
fi

- name: Upload artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: gensokyo-${{ matrix.os }}-${{ matrix.goarch }}
path: output/gensokyo-${{ matrix.os }}-${{ matrix.goarch }}${{ endsWith(matrix.os, 'windows') && '.exe' || '' }}
Expand Down
2 changes: 1 addition & 1 deletion Processor/ProcessGroupMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func (p *Processors) ProcessGroupMessage(data *dto.WSGroupATMessageData) error {
echo.AddMsgID(AppIDString, s, data.ID)
echo.AddMsgType(AppIDString, s, "group")
//储存当前群或频道号的类型
//idmap.WriteConfigv2(data.GroupID, "type", "group")
go idmap.WriteConfigv2(data.GroupID, "type", "group")
//懒message_id池
echo.AddLazyMessageId(data.GroupID, data.ID, time.Now())
//懒message_id池
Expand Down
16 changes: 15 additions & 1 deletion handlers/get_friend_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package handlers

import (
"encoding/json"
"regexp"

"github.com/hoshinonyaruko/gensokyo/callapi"
"github.com/hoshinonyaruko/gensokyo/idmap"
Expand All @@ -25,14 +26,27 @@ type APIOutput struct {
func HandleGetFriendList(client callapi.Client, api openapi.OpenAPI, apiv2 openapi.OpenAPI, message callapi.ActionMessage) (string, error) {
var output APIOutput

// 检查字符串是否是数字
isNumeric := func(s string) bool {
return regexp.MustCompile(`^\d+$`).MatchString(s)
}

// 从数据库获取所有用户信息
users, err := idmap.ListAllUsers()
if err != nil {
mylog.Errorf("Failed to list users: %v", err)
}

// 过滤用户ID是数字的用户
filteredUsers := []structs.FriendData{} // 假设 User 是你用户结构体的类型
for _, user := range users {
if !isNumeric(user.UserID) {
filteredUsers = append(filteredUsers, user)
}
}

// 添加数据库中读取的用户数据到output.Data
output.Data = append(output.Data, users...)
output.Data = append(output.Data, filteredUsers...)

output.Message = ""
output.RetCode = 0
Expand Down
23 changes: 17 additions & 6 deletions handlers/get_group_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handlers
import (
"context"
"encoding/json"
"fmt"
"regexp"
"strconv"
"time"
Expand Down Expand Up @@ -189,7 +190,7 @@ func GetGroupList(client callapi.Client, api openapi.OpenAPI, apiv2 openapi.Open
for _, idStr := range groupIDs {
var originalGroupID string
if isNumeric(idStr) {
originalGroupID, _ = idmap.RetrieveRowByIDv2(idStr)
continue
} else {
originalGroupID = idStr
}
Expand All @@ -216,17 +217,27 @@ func GetGroupList(client callapi.Client, api openapi.OpenAPI, apiv2 openapi.Open
outputMap = structToMap(groupListString)
}

//mylog.Printf("getGroupList(频道): %+v\n", outputMap)
//fmt.Printf("getGroupList(频道): %+v\n", outputMap)
fmt.Printf("getGroupList(数量): %+v\n", len(outputMap["data"].([]interface{})))

err = client.SendMessage(outputMap)
if err != nil {
mylog.Printf("error sending group info via wsclient: %v", err)
}

result, err := json.Marshal(groupList)
if err != nil {
mylog.Printf("Error marshaling data: %v", err)
return "", nil
var result []byte
if !config.GetStringOb11() {
result, err = json.Marshal(groupList)
if err != nil {
mylog.Printf("Error marshaling data: %v", err)
return "", nil
}
} else {
result, err = json.Marshal(groupListString)
if err != nil {
mylog.Printf("Error marshaling data: %v", err)
return "", nil
}
}

//mylog.Printf("get_group_list: %s", result)
Expand Down
121 changes: 117 additions & 4 deletions handlers/message_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ type ServerResponse struct {
Echo interface{} `json:"echo"`
}

// 定义响应结构体
type ServerResponseSB struct {
Data struct {
MessageID string `json:"message_id"`
} `json:"data"`
Message string `json:"message"`
GroupID string `json:"group_id,omitempty"`
UserID string `json:"user_id,omitempty"`
ChannelID string `json:"channel_id,omitempty"`
GuildID string `json:"guild_id,omitempty"`
RetCode int `json:"retcode"`
Status string `json:"status"`
Echo interface{} `json:"echo"`
}

// 定义了一个符合 Client 接口的 HttpAPIClient 结构体
type HttpAPIClient struct {
// 可添加所需字段
Expand Down Expand Up @@ -248,6 +263,52 @@ func SendResponse(client callapi.Client, err error, message *callapi.ActionMessa
return string(jsonResponse), nil
}

// 发送成功回执 todo 返回可互转的messageid 实现群撤回api
func SendResponseSB(client callapi.Client, err error, message *callapi.ActionMessage, resp *dto.GroupMessageResponse, api openapi.OpenAPI, apiv2 openapi.OpenAPI) (string, error) {
// 设置响应值
response := ServerResponseSB{}
if resp != nil {

response.Data.MessageID = resp.Message.ID

} else {
// Default ID handling
response.Data.MessageID = ""
}

response.GroupID = message.Params.GroupID.(string)
response.Echo = message.Echo
if err != nil {
response.Message = err.Error() // 可选:在响应中添加错误消息
//response.RetCode = -1 // 可以是任何非零值,表示出错
//response.Status = "failed"
response.RetCode = 0 //官方api审核异步的 审核中默认返回失败,但其实信息发送成功了
response.Status = "ok"
} else {
response.Message = ""
response.RetCode = 0
response.Status = "ok"
}

// 转化为map并发送
outputMap := structToMap(response)
// 将map转换为JSON字符串
jsonResponse, jsonErr := json.Marshal(outputMap)
if jsonErr != nil {
log.Printf("Error marshaling response to JSON: %v", jsonErr)
return "", jsonErr
}
//发送给ws 客户端
sendErr := client.SendMessage(outputMap)
if sendErr != nil {
mylog.Printf("Error sending message via client: %v", sendErr)
return "", sendErr
}

mylog.Printf("发送成功回执: %+v", string(jsonResponse))
return string(jsonResponse), nil
}

// 发送成功回执 todo 返回可互转的messageid 实现频道撤回api
func SendGuildResponse(client callapi.Client, err error, message *callapi.ActionMessage, resp *dto.Message) (string, error) {
var messageID64 int64
Expand Down Expand Up @@ -480,7 +541,33 @@ func parseMessageContent(paramsMessage callapi.ParamsContent, message callapi.Ac
}
case "image":
fileContent, _ := segmentMap["data"].(map[string]interface{})["file"].(string)
foundItems["image"] = append(foundItems["image"], fileContent)

// 检查是否为 Base64 图片
if strings.HasPrefix(fileContent, "base64://") {
// 去掉 "base64://" 头部
cleanContent := strings.TrimPrefix(fileContent, "base64://")
foundItems["base64_image"] = append(foundItems["base64_image"], cleanContent)
} else if strings.HasPrefix(fileContent, "http://") {
// HTTP 图片,去掉 "http://" 头部
cleanContent := strings.TrimPrefix(fileContent, "http://")
foundItems["url_image"] = append(foundItems["url_image"], cleanContent)
} else if strings.HasPrefix(fileContent, "https://") {
// HTTPS 图片,去掉 "https://" 头部
cleanContent := strings.TrimPrefix(fileContent, "https://")
foundItems["url_images"] = append(foundItems["url_images"], cleanContent)
} else if strings.HasPrefix(fileContent, "file://") {
// 本地文件,根据系统区分前缀
var cleanContent string
if runtime.GOOS == "windows" {
cleanContent = strings.TrimPrefix(fileContent, "file:///")
} else {
cleanContent = strings.TrimPrefix(fileContent, "file://")
}
foundItems["local_image"] = append(foundItems["local_image"], cleanContent)
} else {
// 默认情况,直接将内容存储到 foundItems 中
foundItems["unknown_image"] = append(foundItems["unknown_image"], fileContent)
}

case "voice", "record":
fileContent, _ := segmentMap["data"].(map[string]interface{})["file"].(string)
Expand Down Expand Up @@ -513,7 +600,7 @@ func parseMessageContent(paramsMessage callapi.ParamsContent, message callapi.Ac
mdContentEncoded = base64.StdEncoding.EncodeToString(mdContentBytes)
} else if mdContentStr, isString := mdContent.(string); isString {
if strings.HasPrefix(mdContentStr, "base64://") {
mdContentEncoded = mdContentStr
mdContentEncoded = strings.TrimPrefix(mdContentStr, "base64://")
} else {
mdContentStr = strings.ReplaceAll(mdContentStr, "&", "&")
mdContentStr = strings.ReplaceAll(mdContentStr, "[", "[")
Expand Down Expand Up @@ -561,7 +648,33 @@ func parseMessageContent(paramsMessage callapi.ParamsContent, message callapi.Ac

case "image":
fileContent, _ := message["data"].(map[string]interface{})["file"].(string)
foundItems["image"] = append(foundItems["image"], fileContent)

// 检查是否为 Base64 图片
if strings.HasPrefix(fileContent, "base64://") {
// 去掉 "base64://" 头部
cleanContent := strings.TrimPrefix(fileContent, "base64://")
foundItems["base64_image"] = append(foundItems["base64_image"], cleanContent)
} else if strings.HasPrefix(fileContent, "http://") {
// HTTP 图片,去掉 "http://" 头部
cleanContent := strings.TrimPrefix(fileContent, "http://")
foundItems["url_image"] = append(foundItems["url_image"], cleanContent)
} else if strings.HasPrefix(fileContent, "https://") {
// HTTPS 图片,去掉 "https://" 头部
cleanContent := strings.TrimPrefix(fileContent, "https://")
foundItems["url_images"] = append(foundItems["url_images"], cleanContent)
} else if strings.HasPrefix(fileContent, "file://") {
// 本地文件,根据系统区分前缀
var cleanContent string
if runtime.GOOS == "windows" {
cleanContent = strings.TrimPrefix(fileContent, "file:///")
} else {
cleanContent = strings.TrimPrefix(fileContent, "file://")
}
foundItems["local_image"] = append(foundItems["local_image"], cleanContent)
} else {
// 默认情况,直接将内容存储到 foundItems 中
foundItems["unknown_image"] = append(foundItems["unknown_image"], fileContent)
}

case "voice", "record":
fileContent, _ := message["data"].(map[string]interface{})["file"].(string)
Expand Down Expand Up @@ -593,7 +706,7 @@ func parseMessageContent(paramsMessage callapi.ParamsContent, message callapi.Ac
mdContentEncoded = base64.StdEncoding.EncodeToString(mdContentBytes)
} else if mdContentStr, isString := mdContent.(string); isString {
if strings.HasPrefix(mdContentStr, "base64://") {
mdContentEncoded = mdContentStr
mdContentEncoded = strings.TrimPrefix(mdContentStr, "base64://")
} else {
mdContentStr = strings.ReplaceAll(mdContentStr, "&", "&")
mdContentStr = strings.ReplaceAll(mdContentStr, "[", "[")
Expand Down
58 changes: 49 additions & 9 deletions handlers/send_group_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,20 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap

if !config.GetNoRetMsg() {
if config.GetThreadsRetMsg() {
go SendResponse(client, err, &message, resp, api, apiv2)
if !config.GetStringOb11() {
go SendResponse(client, err, &message, resp, api, apiv2)
} else {
go SendResponseSB(client, err, &message, resp, api, apiv2)
}
} else {
// 发送成功回执
retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2)
if !config.GetStringOb11() {
// 发送成功回执
retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2)
} else {
// 发送成功回执
retmsg, _ = SendResponseSB(client, err, &message, resp, api, apiv2)
}

}
}

Expand Down Expand Up @@ -442,9 +452,19 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
if !config.GetNoRetMsg() {
//发送成功回执
if config.GetThreadsRetMsg() {
go SendResponse(client, err, &message, resp, api, apiv2)
if !config.GetStringOb11() {
go SendResponse(client, err, &message, resp, api, apiv2)
} else {
go SendResponseSB(client, err, &message, resp, api, apiv2)
}

} else {
retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2)
if !config.GetStringOb11() {
retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2)
} else {
retmsg, _ = SendResponseSB(client, err, &message, resp, api, apiv2)
}

}
}

Expand Down Expand Up @@ -520,9 +540,19 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
if !config.GetNoRetMsg() {
//发送成功回执
if config.GetThreadsRetMsg() {
go SendResponse(client, err, &message, resp, api, apiv2)
if !config.GetStringOb11() {
go SendResponse(client, err, &message, resp, api, apiv2)
} else {
go SendResponseSB(client, err, &message, resp, api, apiv2)
}

} else {
retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2)
if !config.GetStringOb11() {
retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2)
} else {
retmsg, _ = SendResponseSB(client, err, &message, resp, api, apiv2)
}

}
}
}
Expand Down Expand Up @@ -617,9 +647,19 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
if !config.GetNoRetMsg() {
//发送成功回执
if config.GetThreadsRetMsg() {
go SendResponse(client, err, &message, resp, api, apiv2)
if !config.GetStringOb11() {
go SendResponse(client, err, &message, resp, api, apiv2)
} else {
go SendResponseSB(client, err, &message, resp, api, apiv2)
}

} else {
retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2)
if !config.GetStringOb11() {
retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2)
} else {
retmsg, _ = SendResponseSB(client, err, &message, resp, api, apiv2)
}

}
}

Expand Down
Loading
Loading