mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 13:59:39 +08:00
chore(lint): 改进代码样式 (#1143)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
parent
e292b69ee5
commit
6c6699a5d6
@ -3,13 +3,14 @@ package minecraftobserver
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
ctrl "github.com/FloatTech/zbpctrl"
|
ctrl "github.com/FloatTech/zbpctrl"
|
||||||
"github.com/FloatTech/zbputils/control"
|
"github.com/FloatTech/zbputils/control"
|
||||||
zbpCtxExt "github.com/FloatTech/zbputils/ctxext"
|
zbpCtxExt "github.com/FloatTech/zbputils/ctxext"
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -240,7 +241,7 @@ func singleServerScan(oldSubStatus *serverStatus) (changed bool, notifyMsg messa
|
|||||||
err = nil
|
err = nil
|
||||||
// 计数器没有超限,增加计数器并跳过
|
// 计数器没有超限,增加计数器并跳过
|
||||||
if cnt, ts := addPingServerUnreachableCounter(oldSubStatus.ServerAddr, time.Now()); cnt < pingServerUnreachableCounterThreshold &&
|
if cnt, ts := addPingServerUnreachableCounter(oldSubStatus.ServerAddr, time.Now()); cnt < pingServerUnreachableCounterThreshold &&
|
||||||
time.Now().Sub(ts) < pingServerUnreachableCounterTimeThreshold {
|
time.Since(ts) < pingServerUnreachableCounterTimeThreshold {
|
||||||
// logrus.Warnln(logPrefix+"server ", oldSubStatus.ServerAddr, " unreachable, counter: ", cnt, " ts:", ts)
|
// logrus.Warnln(logPrefix+"server ", oldSubStatus.ServerAddr, " unreachable, counter: ", cnt, " ts:", ts)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,11 +4,12 @@ import (
|
|||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/Tnze/go-mc/chat"
|
"github.com/Tnze/go-mc/chat"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ====================
|
// ====================
|
||||||
@ -237,13 +238,13 @@ func formatSubStatusChangeText(oldStatus, newStatus *serverStatus) string {
|
|||||||
// 状态由不可达变为可达,反之
|
// 状态由不可达变为可达,反之
|
||||||
if oldStatus.PingDelay == pingDelayUnreachable && newStatus.PingDelay != pingDelayUnreachable {
|
if oldStatus.PingDelay == pingDelayUnreachable && newStatus.PingDelay != pingDelayUnreachable {
|
||||||
msgBuilder.WriteString("\n-----[Ping延迟]-----\n")
|
msgBuilder.WriteString("\n-----[Ping延迟]-----\n")
|
||||||
msgBuilder.WriteString(fmt.Sprintf("[旧]\n超时\n"))
|
msgBuilder.WriteString("[旧]\n超时\n")
|
||||||
msgBuilder.WriteString(fmt.Sprintf("[新]\n%v毫秒\n", newStatus.PingDelay))
|
msgBuilder.WriteString(fmt.Sprintf("[新]\n%v毫秒\n", newStatus.PingDelay))
|
||||||
}
|
}
|
||||||
if oldStatus.PingDelay != pingDelayUnreachable && newStatus.PingDelay == pingDelayUnreachable {
|
if oldStatus.PingDelay != pingDelayUnreachable && newStatus.PingDelay == pingDelayUnreachable {
|
||||||
msgBuilder.WriteString("\n-----[Ping延迟]-----\n")
|
msgBuilder.WriteString("\n-----[Ping延迟]-----\n")
|
||||||
msgBuilder.WriteString(fmt.Sprintf("[旧]\n%v毫秒\n", oldStatus.PingDelay))
|
msgBuilder.WriteString(fmt.Sprintf("[旧]\n%v毫秒\n", oldStatus.PingDelay))
|
||||||
msgBuilder.WriteString(fmt.Sprintf("[新]\n超时\n"))
|
msgBuilder.WriteString("[新]\n超时\n")
|
||||||
}
|
}
|
||||||
return msgBuilder.String()
|
return msgBuilder.String()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,9 +2,10 @@ package minecraftobserver
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/RomiChan/syncx"
|
"github.com/RomiChan/syncx"
|
||||||
"github.com/Tnze/go-mc/bot"
|
"github.com/Tnze/go-mc/bot"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@ -2,13 +2,14 @@ package minecraftobserver
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"os"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
fcext "github.com/FloatTech/floatbox/ctxext"
|
fcext "github.com/FloatTech/floatbox/ctxext"
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
"os"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -60,8 +61,7 @@ var (
|
|||||||
dbInstance *db
|
dbInstance *db
|
||||||
// 开启并检查数据库链接
|
// 开启并检查数据库链接
|
||||||
getDB = fcext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
|
getDB = fcext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
|
||||||
var err error
|
var err error = initializeDB(engine.DataFolder() + dbPath)
|
||||||
err = initializeDB(engine.DataFolder() + dbPath)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// logrus.Errorln(logPrefix+"initializeDB ERROR: ", err)
|
// logrus.Errorln(logPrefix+"initializeDB ERROR: ", err)
|
||||||
ctx.SendChain(message.Text("[mc-ob] ERROR: ", err))
|
ctx.SendChain(message.Text("[mc-ob] ERROR: ", err))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user