Skip to content

Commit

Permalink
Beta495 (#501)
Browse files Browse the repository at this point in the history
* beta447

* beta448

* beta449

* beta450

* beta451

* beta452

* beta453

* beta454

* beta455

* btea455

* beta456

* beta457

* beta458

* beta460

* beta460

* beta461

* beta462

* beta463

* beta464

* beta465

* beta467

* beta468

* beta469

* beta470

* beta471

* beta472

* beta473

* beta473

* beta475

* beta476

* beta478

* beta479

* beta479

* beta480

* beta481

* beta482

* beta483

* beta484

* beta485

* beta486

* beta486

* beta487

* beta487

* beta489

* beta490

* beta491

* beta492

* beta492-1

* beta494

* beta495
  • Loading branch information
Hoshinonyaruko authored Oct 13, 2024
1 parent 107b096 commit 7888ca3
Show file tree
Hide file tree
Showing 7 changed files with 323 additions and 91 deletions.
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

0 comments on commit 7888ca3

Please sign in to comment.