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

Beta418 #424

Merged
merged 21 commits into from
Jun 10, 2024
93 changes: 48 additions & 45 deletions Processor/Processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,52 +268,55 @@ func (p *Processors) BroadcastMessageToAll(message map[string]interface{}, api o
failed++
}

// 检查是否所有尝试都失败了
if failed == len(p.Wsclient)+len(p.WsServerClients) {
// 处理全部失败的情况
fmt.Println("All message sending attempts failed.")
downtimemessgae := config.GetDowntimeMessage()
switch v := data.(type) {
case *dto.WSGroupATMessageData:
msgtocreate := &dto.MessageToCreate{
Content: downtimemessgae,
MsgID: v.ID,
MsgSeq: 1,
MsgType: 0, // 默认文本类型
// 仅对连接正反ws的bot应用这个判断
if !p.Settings.HttpOnlyBot {
// 检查是否所有尝试都失败了
if failed == len(p.Wsclient)+len(p.WsServerClients) {
// 处理全部失败的情况
fmt.Println("All ws event sending attempts failed.")
downtimemessgae := config.GetDowntimeMessage()
switch v := data.(type) {
case *dto.WSGroupATMessageData:
msgtocreate := &dto.MessageToCreate{
Content: downtimemessgae,
MsgID: v.ID,
MsgSeq: 1,
MsgType: 0, // 默认文本类型
}
api.PostGroupMessage(context.Background(), v.GroupID, msgtocreate)
case *dto.WSATMessageData:
msgtocreate := &dto.MessageToCreate{
Content: downtimemessgae,
MsgID: v.ID,
MsgSeq: 1,
MsgType: 0, // 默认文本类型
}
api.PostMessage(context.Background(), v.ChannelID, msgtocreate)
case *dto.WSMessageData:
msgtocreate := &dto.MessageToCreate{
Content: downtimemessgae,
MsgID: v.ID,
MsgSeq: 1,
MsgType: 0, // 默认文本类型
}
api.PostMessage(context.Background(), v.ChannelID, msgtocreate)
case *dto.WSDirectMessageData:
msgtocreate := &dto.MessageToCreate{
Content: downtimemessgae,
MsgID: v.ID,
MsgSeq: 1,
MsgType: 0, // 默认文本类型
}
api.PostMessage(context.Background(), v.GuildID, msgtocreate)
case *dto.WSC2CMessageData:
msgtocreate := &dto.MessageToCreate{
Content: downtimemessgae,
MsgID: v.ID,
MsgSeq: 1,
MsgType: 0, // 默认文本类型
}
api.PostC2CMessage(context.Background(), v.Author.ID, msgtocreate)
}
api.PostGroupMessage(context.Background(), v.GroupID, msgtocreate)
case *dto.WSATMessageData:
msgtocreate := &dto.MessageToCreate{
Content: downtimemessgae,
MsgID: v.ID,
MsgSeq: 1,
MsgType: 0, // 默认文本类型
}
api.PostMessage(context.Background(), v.ChannelID, msgtocreate)
case *dto.WSMessageData:
msgtocreate := &dto.MessageToCreate{
Content: downtimemessgae,
MsgID: v.ID,
MsgSeq: 1,
MsgType: 0, // 默认文本类型
}
api.PostMessage(context.Background(), v.ChannelID, msgtocreate)
case *dto.WSDirectMessageData:
msgtocreate := &dto.MessageToCreate{
Content: downtimemessgae,
MsgID: v.ID,
MsgSeq: 1,
MsgType: 0, // 默认文本类型
}
api.PostMessage(context.Background(), v.GuildID, msgtocreate)
case *dto.WSC2CMessageData:
msgtocreate := &dto.MessageToCreate{
Content: downtimemessgae,
MsgID: v.ID,
MsgSeq: 1,
MsgType: 0, // 默认文本类型
}
api.PostC2CMessage(context.Background(), v.Author.ID, msgtocreate)
}
}

Expand Down
19 changes: 17 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,16 +318,31 @@ func main() {
p = Processor.NewProcessor(api, apiV2, &conf.Settings, wsClients)
}
} else {
log.Println("提示,目前只启动了正向ws或httpapi")
// p一定需要初始化
p = Processor.NewProcessorV2(api, apiV2, &conf.Settings)
// 如果只启动了http api
if !conf.Settings.EnableWsServer {
if conf.Settings.HttpAddress != "" {
// 对全局生效
conf.Settings.HttpOnlyBot = true
log.Println("提示,目前只启动了httpapi,正反向ws均未配置.")
} else {
log.Println("提示,目前你配置了个寂寞,httpapi没设置,正反ws都没配置.")
}
} else {
if conf.Settings.HttpAddress != "" {
log.Println("提示,目前启动了正向ws和httpapi,未连接反向ws")
} else {
log.Println("提示,目前启动了正向ws,未连接反向ws,httpapi未开启")
}
}
}
} else {
// 设置颜色为红色
red := color.New(color.FgRed)
// 输出红色文本
red.Println("请设置正确的appid、token、clientsecret再试")
}

}

//图片上传 调用次数限制
Expand Down
5 changes: 5 additions & 0 deletions server/wsserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"net/http"
"strings"
"sync"
"time"

"github.com/gin-gonic/gin"
Expand All @@ -20,6 +21,7 @@ type WebSocketServerClient struct {
Conn *websocket.Conn
API openapi.OpenAPI
APIv2 openapi.OpenAPI
mu sync.Mutex // 互斥锁保护 conn
}

var upgrader = websocket.Upgrader{
Expand Down Expand Up @@ -155,6 +157,9 @@ func processWSMessage(client *WebSocketServerClient, msg []byte) {

// 发信息给client
func (c *WebSocketServerClient) SendMessage(message map[string]interface{}) error {
c.mu.Lock()
defer c.mu.Unlock()

msgBytes, err := json.Marshal(message)
if err != nil {
mylog.Println("Error marshalling message:", err)
Expand Down
3 changes: 2 additions & 1 deletion structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ type Settings struct {
EnableChangeWord bool `yaml:"enableChangeWord"`
DefaultChangeWord string `yaml:"defaultChangeWord"`
//错误临时修复类
Fix11300 bool `yaml:"fix_11300"`
Fix11300 bool `yaml:"fix_11300"`
HttpOnlyBot bool `yaml:"http_only_bot"`
//内置指令
BindPrefix string `yaml:"bind_prefix"`
MePrefix string `yaml:"me_prefix"`
Expand Down
2 changes: 1 addition & 1 deletion template/config_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ settings:

#错误临时修复类
fix_11300: false #修复11300报错,需要在develop_bot_id填入自己机器人的appid. 11300原因暂时未知,临时修复方案.

http_only_bot : false #这个配置项会自动配置,请不要修改,保持false.

#内置指令类
bind_prefix : "/bind" #需设置 #增强配置项 master_id 可触发
Expand Down
Loading