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

Merged
merged 24 commits into from
Oct 27, 2023
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
4 changes: 1 addition & 3 deletions .github/workflows/cross_compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ jobs:
goarch: amd64
- os: windows
goarch: 386
- os: android
goarch: arm
- os: android
goarch: arm64
# ... Add other combinations as needed
Expand Down Expand Up @@ -58,7 +56,7 @@ jobs:
env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: ${{ matrix.os == 'android' || matrix.goarch == 'arm' || matrix.goarch == 'arm64' ? '0' : '1' }}
CGO_ENABLED: 0
run: |
go build -o output/gensokyo-${{ matrix.os }}-${{ matrix.goarch }}

Expand Down
40 changes: 31 additions & 9 deletions Processor/ProcessC2CMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"strconv"
"strings"
"time"

"github.com/hoshinonyaruko/gensokyo/config"
Expand All @@ -16,7 +17,7 @@ import (
)

// ProcessC2CMessage 处理C2C消息 群私聊
func (p *Processor) ProcessC2CMessage(data *dto.WSC2CMessageData) error {
func (p *Processors) ProcessC2CMessage(data *dto.WSC2CMessageData) error {
// 打印data结构体
PrintStructWithFieldNames(data)

Expand Down Expand Up @@ -89,15 +90,26 @@ func (p *Processor) ProcessC2CMessage(data *dto.WSC2CMessageData) error {

// Convert OnebotGroupMessage to map and send
privateMsgMap := structToMap(privateMsg)
err = p.Wsclient.SendMessage(privateMsgMap)
if err != nil {
return fmt.Errorf("error sending group message via wsclient: %v", err)
var errors []string

for _, client := range p.Wsclient {
err = client.SendMessage(privateMsgMap)
if err != nil {
// 记录错误信息,但不立即返回
errors = append(errors, fmt.Sprintf("error sending private message via wsclient: %v", err))
}
}

// 在循环结束后处理记录的错误
if len(errors) > 0 {
// 使用strings.Join合并所有的错误信息
return fmt.Errorf(strings.Join(errors, "; "))
}
} else {
//将私聊信息转化为群信息(特殊需求情况下)

//转换at
messageText := handlers.RevertTransformedText(data.Content)
messageText := handlers.RevertTransformedText(data)
//转换appid
AppIDString := strconv.FormatUint(p.Settings.AppID, 10)
//构造echo
Expand Down Expand Up @@ -165,11 +177,21 @@ func (p *Processor) ProcessC2CMessage(data *dto.WSC2CMessageData) error {

// Convert OnebotGroupMessage to map and send
groupMsgMap := structToMap(groupMsg)
err = p.Wsclient.SendMessage(groupMsgMap)
if err != nil {
return fmt.Errorf("error sending group message via wsclient: %v", err)
var errors []string

for _, client := range p.Wsclient {
err = client.SendMessage(groupMsgMap)
if err != nil {
// 记录错误信息,但不立即返回
errors = append(errors, fmt.Sprintf("error sending group message via wsclient: %v", err))
}
}
}

// 在循环结束后处理记录的错误
if len(errors) > 0 {
// 使用strings.Join合并所有的错误信息
log.Println("Encountered errors while sending to wsclients:", strings.Join(errors, "; "))
}
}
return nil
}
58 changes: 45 additions & 13 deletions Processor/ProcessChannelDirectMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"strconv"
"strings"
"time"

"github.com/hoshinonyaruko/gensokyo/config"
Expand All @@ -17,7 +18,7 @@ import (
)

// ProcessChannelDirectMessage 处理频道私信消息 这里我们是被动收到
func (p *Processor) ProcessChannelDirectMessage(data *dto.WSDirectMessageData) error {
func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData) error {
// 打印data结构体
//PrintStructWithFieldNames(data)

Expand Down Expand Up @@ -93,9 +94,20 @@ func (p *Processor) ProcessChannelDirectMessage(data *dto.WSDirectMessageData) e

// Convert OnebotGroupMessage to map and send
privateMsgMap := structToMap(privateMsg)
err = p.Wsclient.SendMessage(privateMsgMap)
if err != nil {
return fmt.Errorf("error sending group message via wsclient: %v", err)
var errors []string

for _, client := range p.Wsclient {
err = client.SendMessage(privateMsgMap)
if err != nil {
// 记录错误信息,但不立即返回
errors = append(errors, fmt.Sprintf("error sending private message via wsclient: %v", err))
}
}

// 在循环结束后处理记录的错误
if len(errors) > 0 {
// 使用strings.Join合并所有的错误信息
return fmt.Errorf(strings.Join(errors, "; "))
}
} else {
if !p.Settings.GlobalChannelToGroup {
Expand All @@ -109,7 +121,7 @@ func (p *Processor) ProcessChannelDirectMessage(data *dto.WSDirectMessageData) e
//获取s
s := client.GetGlobalS()
//转换at
messageText := handlers.RevertTransformedText(data.Content)
messageText := handlers.RevertTransformedText(data)
//转换appid
AppIDString := strconv.FormatUint(p.Settings.AppID, 10)
//构造echo
Expand Down Expand Up @@ -175,18 +187,27 @@ func (p *Processor) ProcessChannelDirectMessage(data *dto.WSDirectMessageData) e

// 将 onebotMsg 结构体转换为 map[string]interface{}
msgMap := structToMap(onebotMsg)
var errors []string

// 使用 wsclient 发送消息
err = p.Wsclient.SendMessage(msgMap)
if err != nil {
return fmt.Errorf("error sending message via wsclient: %v", err)
for _, client := range p.Wsclient {
err = client.SendMessage(msgMap)
if err != nil {
// 记录错误信息,但不立即返回
errors = append(errors, fmt.Sprintf("error sending message via wsclient: %v", err))
}
}

// 在循环结束后处理记录的错误
if len(errors) > 0 {
// 使用strings.Join合并所有的错误信息
return fmt.Errorf(strings.Join(errors, "; "))
}
} else {
//将频道信息转化为群信息(特殊需求情况下)
//将channelid写入ini,可取出guild_id
idmap.WriteConfigv2(data.ChannelID, "guild_id", data.GuildID)
//转换at
messageText := handlers.RevertTransformedText(data.Content)
messageText := handlers.RevertTransformedText(data)
//转换appid
AppIDString := strconv.FormatUint(p.Settings.AppID, 10)
//构造echo
Expand Down Expand Up @@ -266,9 +287,20 @@ func (p *Processor) ProcessChannelDirectMessage(data *dto.WSDirectMessageData) e

// Convert OnebotGroupMessage to map and send
groupMsgMap := structToMap(groupMsg)
err = p.Wsclient.SendMessage(groupMsgMap)
if err != nil {
return fmt.Errorf("error sending group message via wsclient: %v", err)
var errors []string

for _, client := range p.Wsclient {
err = client.SendMessage(groupMsgMap)
if err != nil {
// 记录错误信息,但不立即返回
errors = append(errors, fmt.Sprintf("error sending group message via wsclient: %v", err))
}
}

// 在循环结束后处理记录的错误
if len(errors) > 0 {
// 使用strings.Join合并所有的错误信息
return fmt.Errorf(strings.Join(errors, "; "))
}
}

Expand Down
21 changes: 16 additions & 5 deletions Processor/ProcessGroupMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"strconv"
"strings"
"time"

"github.com/hoshinonyaruko/gensokyo/config"
Expand All @@ -17,14 +18,14 @@ import (
)

// ProcessGroupMessage 处理群组消息
func (p *Processor) ProcessGroupMessage(data *dto.WSGroupATMessageData) error {
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.Content)
messageText := handlers.RevertTransformedText(data)

// 转换appid
AppIDString := strconv.FormatUint(p.Settings.AppID, 10)
Expand Down Expand Up @@ -107,10 +108,20 @@ func (p *Processor) ProcessGroupMessage(data *dto.WSGroupATMessageData) error {

// Convert OnebotGroupMessage to map and send
groupMsgMap := structToMap(groupMsg)
err = p.Wsclient.SendMessage(groupMsgMap)
if err != nil {
return fmt.Errorf("error sending group message via wsclient: %v", err)
var errors []string

for _, client := range p.Wsclient {
err = client.SendMessage(groupMsgMap)
if err != nil {
// 记录错误信息,但不立即返回
errors = append(errors, fmt.Sprintf("error sending group message via wsclient: %v", err))
}
}

// 在循环结束后处理记录的错误
if len(errors) > 0 {
// 使用strings.Join合并所有的错误信息
return fmt.Errorf(strings.Join(errors, "; "))
}
return nil
}
43 changes: 32 additions & 11 deletions Processor/ProcessGuildATMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"strconv"
"strings"
"time"

"github.com/hoshinonyaruko/gensokyo/config"
Expand All @@ -17,7 +18,7 @@ import (
)

// ProcessGuildATMessage 处理消息,执行逻辑并可能使用 api 发送响应
func (p *Processor) ProcessGuildATMessage(data *dto.WSATMessageData) error {
func (p *Processors) ProcessGuildATMessage(data *dto.WSATMessageData) error {
if !p.Settings.GlobalChannelToGroup {
// 将时间字符串转换为时间戳
t, err := time.Parse(time.RFC3339, string(data.Timestamp))
Expand All @@ -27,7 +28,7 @@ func (p *Processor) ProcessGuildATMessage(data *dto.WSATMessageData) error {
//获取s
s := client.GetGlobalS()
//转换at
messageText := handlers.RevertTransformedText(data.Content)
messageText := handlers.RevertTransformedText(data)
//转换appid
AppIDString := strconv.FormatUint(p.Settings.AppID, 10)
//构造echo
Expand Down Expand Up @@ -98,21 +99,30 @@ func (p *Processor) ProcessGuildATMessage(data *dto.WSATMessageData) error {
// 将 onebotMsg 结构体转换为 map[string]interface{}
msgMap := structToMap(onebotMsg)

// 使用 wsclient 发送消息
err = p.Wsclient.SendMessage(msgMap)
if err != nil {
return fmt.Errorf("error sending message via wsclient: %v", err)
var errors []string

for _, client := range p.Wsclient {
err = client.SendMessage(msgMap)
if err != nil {
// 记录错误信息,但不立即返回
errors = append(errors, fmt.Sprintf("error sending message via wsclient: %v", err))
}
}

// 在循环结束后处理记录的错误
if len(errors) > 0 {
// 使用strings.Join合并所有的错误信息
return fmt.Errorf(strings.Join(errors, "; "))
}
} else {
// GlobalChannelToGroup为true时的处理逻辑
//将频道转化为一个群
//获取s
s := client.GetGlobalS()
//将channelid写入ini,可取出guild_id todo 比ini更好的储存方式
idmap.WriteConfigv2(data.ChannelID, "guild_id", data.GuildID)
//转换at
messageText := handlers.RevertTransformedText(data.Content)
//转换at和图片
messageText := handlers.RevertTransformedText(data)
//转换appid
AppIDString := strconv.FormatUint(p.Settings.AppID, 10)
//构造echo
Expand Down Expand Up @@ -192,9 +202,20 @@ func (p *Processor) ProcessGuildATMessage(data *dto.WSATMessageData) error {

// Convert OnebotGroupMessage to map and send
groupMsgMap := structToMap(groupMsg)
err = p.Wsclient.SendMessage(groupMsgMap)
if err != nil {
return fmt.Errorf("error sending group message via wsclient: %v", err)
var errors []string

for _, client := range p.Wsclient {
err = client.SendMessage(groupMsgMap)
if err != nil {
// 记录错误信息,但不立即返回
errors = append(errors, fmt.Sprintf("error sending group message via wsclient: %v", err))
}
}

// 在循环结束后处理记录的错误
if len(errors) > 0 {
// 使用strings.Join合并所有的错误信息
return fmt.Errorf(strings.Join(errors, "; "))
}

}
Expand Down
Loading