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

Beta479 #483

Merged
merged 34 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 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
ec0f3c7
Merge branch 'main' into beta479
Hoshinonyaruko Aug 17, 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
1 change: 1 addition & 0 deletions Processor/ProcessC2CMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func (p *Processors) ProcessC2CMessage(data *dto.WSC2CMessageData) error {

if data.Author.ID == "" {
mylog.Printf("出现ID为空未知错误.%v\n", data)
return nil
}

//获取当前的s值 当前ws连接所收到的信息条数
Expand Down
1 change: 1 addition & 0 deletions Processor/ProcessGroupMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func (p *Processors) ProcessGroupMessage(data *dto.WSGroupATMessageData) error {

if data.Author.ID == "" {
mylog.Printf("出现ID为空未知错误.%v\n", data)
return nil
}

if !config.GetStringOb11() {
Expand Down
16 changes: 15 additions & 1 deletion botgo/sessions/multi/multi.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package multi

import (
"fmt"
"sync"
"time"

Expand Down Expand Up @@ -93,6 +94,19 @@ func (sm *ShardManager) newConnect(session dto.Session, shardID uint32) {
}
if err := wsClient.Listening(); err != nil {
log.Errorf("[ws/session] Listening error: %+v", err)
sm.SessionChans[shardID] <- session // Reconnect
currentSession := wsClient.Session()
// 对于不能够进行重连的session,需要清空 session id 与 seq
if manager.CanNotResume(err) {
currentSession.ID = ""
currentSession.LastSeq = 0
}
// 一些错误不能够鉴权,比如机器人被封禁,这里就直接退出了
if manager.CanNotIdentify(err) {
msg := fmt.Sprintf("can not identify because server return %+v, so process exit", err)
log.Errorf(msg)
panic(msg) // 当机器人被下架,或者封禁,将不能再连接,所以 panic
}
// 将 session 放到 session chan 中,用于启动新的连接,当前连接退出
sm.SessionChans[shardID] <- *currentSession // Reconnect
}
}
5 changes: 4 additions & 1 deletion handlers/send_private_msg_sse.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func HandleSendPrivateMsgSSE(client callapi.Client, api openapi.OpenAPI, apiv2 o

// 输出反序列化后的对象,确认是否成功转换
fmt.Printf("Recovered InterfaceBody: %+v\n", messageBody)

// 使用 echo 获取消息ID
var messageID string
if config.GetLazyMessageId() {
Expand All @@ -135,7 +136,9 @@ func HandleSendPrivateMsgSSE(client callapi.Client, api openapi.OpenAPI, apiv2 o

// 获取并打印相关ID
relatedID := GetRelatedID(messageID)
fmt.Println("相关ID:", relatedID)

//fmt.Println("相关ID:", relatedID)

dtoSSE := generateMessageSSE(messageBody, messageID, relatedID)

mylog.Printf("私聊发信息sse:%v", dtoSSE)
Expand Down
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"syscall"
"time"

// _ "net/http/pprof"

"github.com/fatih/color"
"github.com/fsnotify/fsnotify"
"github.com/hoshinonyaruko/gensokyo/Processor"
Expand Down Expand Up @@ -125,6 +127,7 @@ func main() {
//logger
logLevel := mylog.GetLogLevelFromConfig(config.GetLogLevel())
loggerAdapter := mylog.NewMyLogAdapter(logLevel, config.GetSaveLogs())
mylog.SetLogLevel(logLevel)
botgo.SetLogger(loggerAdapter)

if *m {
Expand Down Expand Up @@ -577,6 +580,14 @@ func main() {
}()
}

// // 启动一个用于 pprof 的 HTTP 服务器
// go func() {
// log.Println("pprof server running on :6060")
// if err := http.ListenAndServe("localhost:6060", nil); err != nil {
// log.Fatalf("pprof server failed: %s", err)
// }
// }()

//杂七杂八的地方
if conf.Settings.MemoryMsgid {
echo.StartCleanupRoutine()
Expand Down
54 changes: 40 additions & 14 deletions mylog/mylog.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const (
LogLevelError
)

var currentLevel = LogLevelInfo // 默认日志级别为 INFO

type Client struct {
conn *websocket.Conn
send chan EnhancedLogEntry
Expand Down Expand Up @@ -249,32 +251,56 @@ type EnhancedLogEntry struct {
// 日志频道,所有的 WebSocket 客户端都会在此监听日志事件
var logChannel = make(chan EnhancedLogEntry, 1000)

func SetLogLevel(level LogLevel) {
if level >= LogLevelDebug && level <= LogLevelError {
currentLevel = level
} else {
log.Printf("Invalid log level: %d", level)
}
}

func Println(v ...interface{}) {
log.Println(v...)
message := fmt.Sprint(v...)
emitLog("INFO", message)
LogToFile("INFO", message)
if currentLevel <= LogLevelInfo {
log.Println(v...)
message := fmt.Sprint(v...)
emitLog("INFO", message)
LogToFile("INFO", message)
}
}

func Printf(format string, v ...interface{}) {
log.Printf(format, v...)
message := fmt.Sprintf(format, v...)
emitLog("INFO", message)
LogToFile("INFO", message)
if currentLevel <= LogLevelInfo {
log.Printf(format, v...)
message := fmt.Sprintf(format, v...)
emitLog("INFO", message)
LogToFile("INFO", message)
}
}

func Warnf(format string, v ...interface{}) {
if currentLevel <= LogLevelWarn {
log.Printf(format, v...)
message := fmt.Sprintf(format, v...)
emitLog("WARN", message)
LogToFile("WARN", message)
}
}

func Errorf(format string, v ...interface{}) {
log.Printf(format, v...)
message := fmt.Sprintf(format, v...)
emitLog("ERROR", message)
LogToFile("ERROR", message)
if currentLevel <= LogLevelError {
log.Printf(format, v...)
message := fmt.Sprintf(format, v...)
emitLog("ERROR", message)
LogToFile("ERROR", message)
}
}

func Fatalf(format string, v ...interface{}) {
log.Printf(format, v...)
message := fmt.Sprintf(format, v...)
emitLog("Fatal", message)
LogToFile("Fatal", message)
emitLog("FATAL", message)
LogToFile("FATAL", message)
os.Exit(1) // Fatal logs usually terminate the program
}

func emitLog(level, message string) {
Expand Down
Loading