diff --git a/plugin_ai_false/ai_false.go b/plugin_ai_false/ai_false.go index b0421852..6d370f7d 100644 --- a/plugin_ai_false/ai_false.go +++ b/plugin_ai_false/ai_false.go @@ -19,25 +19,25 @@ func init() { // 插件主体 zero.OnFullMatchGroup([]string{"检查身体", "自检", "启动自检", "系统状态"}, zero.AdminPermission). Handle(func(ctx *zero.Ctx) { ctx.SendChain(message.Text( - "* CPU占用率: ", getCpuPercent(), "%\n", - "* RAM占用率: ", getMemPercent(), "%\n", - "* 硬盘活动率: ", getDiskPercent(), "%", + "* CPU占用率: ", cpuPercent(), "%\n", + "* RAM占用率: ", memPercent(), "%\n", + "* 硬盘活动率: ", diskPercent(), "%", ), ) }) } -func getCpuPercent() float64 { +func cpuPercent() float64 { percent, _ := cpu.Percent(time.Second, false) return math.Round(percent[0]) } -func getMemPercent() float64 { +func memPercent() float64 { memInfo, _ := mem.VirtualMemory() return math.Round(memInfo.UsedPercent) } -func getDiskPercent() float64 { +func diskPercent() float64 { parts, _ := disk.Partitions(true) diskInfo, _ := disk.Usage(parts[0].Mountpoint) return math.Round(diskInfo.UsedPercent) diff --git a/plugin_atri/atri.go b/plugin_atri/atri.go index 6d943191..fd11ead9 100644 --- a/plugin_atri/atri.go +++ b/plugin_atri/atri.go @@ -1,3 +1,4 @@ +// Package atri // 本文件基于 https://github.com/Kyomotoi/ATRI // 为 Golang 移植版,语料、素材均来自上述项目 // 本项目遵守 AGPL v3 协议进行开源 @@ -12,8 +13,11 @@ import ( ) var ( - PRIO = -1 - RES = "https://raw.dihe.moe/Yiwen-Chan/ZeroBot-Plugin/master/plugin_atri/" + // ATRI 所有命令的优先级 + PRIO = -1 + // ATRI 表情的 GitHub 镜像位置 + RES = "https://raw.dihe.moe/Yiwen-Chan/ZeroBot-Plugin/master/plugin_atri/" + // ATRI 的总开关 ENABLE = true ) @@ -89,8 +93,7 @@ func init() { // 插件主体 zero.OnFullMatchGroup([]string{"中午好", "午安"}, AtriSwitch()).SetBlock(true).SetPriority(PRIO). Handle(func(ctx *zero.Ctx) { now := time.Now().Hour() - switch { - case now < 6: // 凌晨 + if now > 11 && now < 15 { // 中午 ctx.SendChain(randText( "午安w", "午觉要好好睡哦,ATRI会陪伴在你身旁的w", diff --git a/plugin_bilibili/fansDaily.go b/plugin_bilibili/fansDaily.go index 84321c91..ec7ba86f 100644 --- a/plugin_bilibili/fansDaily.go +++ b/plugin_bilibili/fansDaily.go @@ -2,11 +2,12 @@ package plugin_bilibili import ( "encoding/json" + "net/http" + "time" + "github.com/robfig/cron" zero "github.com/wdvxdr1123/ZeroBot" "github.com/wdvxdr1123/ZeroBot/message" - "net/http" - "time" ) type follower struct { @@ -24,14 +25,14 @@ type follower struct { func init() { zero.OnFullMatch("/开启粉丝日报", zero.AdminPermission). Handle(func(ctx *zero.Ctx) { - FansDaily(130591566) //群号传进去给下面发信息的函数 + FansDaily(130591566) // 群号传进去给下面发信息的函数 }) } // 定时任务每天晚上最后2分钟执行一次 func FansDaily(groupID int64) { c := cron.New() - c.AddFunc("0 58 23 * * ?", func() { fansData(groupID) }) + _ = c.AddFunc("0 58 23 * * ?", func() { fansData(groupID) }) c.Start() } diff --git a/plugin_chat/chat.go b/plugin_chat/chat.go index 61f9544d..38d7489f 100644 --- a/plugin_chat/chat.go +++ b/plugin_chat/chat.go @@ -1,4 +1,5 @@ /* +Package plugin_chat 对话插件 example */ package plugin_chat @@ -74,13 +75,11 @@ func init() { // 插件主体 "❄️风速中", "\n", "群温度 ", AirConditTemp[ctx.Event.GroupID], "℃", )) - return } else { ctx.SendChain(message.Text( "💤", "\n", "群温度 ", AirConditTemp[ctx.Event.GroupID], "℃", )) - return } }) zero.OnFullMatch(`群温度`).SetBlock(true).FirstPriority(). @@ -93,13 +92,11 @@ func init() { // 插件主体 "❄️风速中", "\n", "群温度 ", AirConditTemp[ctx.Event.GroupID], "℃", )) - return } else { ctx.SendChain(message.Text( "💤", "\n", "群温度 ", AirConditTemp[ctx.Event.GroupID], "℃", )) - return } }) } diff --git a/plugin_image_finder/keyword.go b/plugin_image_finder/keyword.go index ae7f93b5..5cdf5013 100644 --- a/plugin_image_finder/keyword.go +++ b/plugin_image_finder/keyword.go @@ -70,7 +70,7 @@ func init() { } -// 请求api +// soutuapi 请求api func soutuapi(keyword string) *AutoGenerated { url := "https://api.pixivel.moe/pixiv?type=search&page=0&mode=partial_match_for_tags&word=" + keyword @@ -97,7 +97,7 @@ func soutuapi(keyword string) *AutoGenerated { return result } -//从json里的30条数据中随机获取一条返回 +// Suiji 从json里的30条数据中随机获取一条返回 func Suiji() int { rand.Seed(time.Now().UnixNano()) return rand.Intn(30) diff --git a/plugin_manager/manager.go b/plugin_manager/manager.go index 7bdd8457..18453e70 100644 --- a/plugin_manager/manager.go +++ b/plugin_manager/manager.go @@ -260,7 +260,7 @@ func init() { // 插件主体 if ok { t.Enable = false delete(*timer.Timers, ti) //避免重复取消 - timer.SaveTimers() + _ = timer.SaveTimers() ctx.Send("取消成功~") } else { ctx.Send("没有这个定时器哦~") diff --git a/plugin_music/selecter.go b/plugin_music/selecter.go index cf18d645..25e89c25 100644 --- a/plugin_music/selecter.go +++ b/plugin_music/selecter.go @@ -129,7 +129,7 @@ func kugou(keyword string) message.MessageSegment { // 返回音乐卡片 return message.CustomMusic( "https://www.kugou.com/song/#hash="+audio.Get("hash").Str+"&album_id="+audio.Get("album_id").Str, - strings.Replace(audio.Get("play_backup_url").Str, "\\/", "/", -1), + strings.ReplaceAll(audio.Get("play_backup_url").Str, "\\/", "/"), audio.Get("audio_name").Str, ).Add("content", audio.Get("author_name").Str).Add("image", audio.Get("img").Str) } @@ -202,7 +202,7 @@ func find(pre string, suf string, str string) string { if n == -1 { n = 0 } else { - n = n + len(pre) + n += len(pre) } str = str[n:] m := strings.Index(str, suf) diff --git a/plugin_runcode/code_runner.go b/plugin_runcode/code_runner.go index 0290e8e4..fdd7a36e 100644 --- a/plugin_runcode/code_runner.go +++ b/plugin_runcode/code_runner.go @@ -4,7 +4,7 @@ package plugin_runcode import ( - "fmt" + "errors" "io/ioutil" "net/http" "net/url" @@ -157,7 +157,7 @@ func init() { block = message.UnescapeCQCodeText(block) if block == "help" { - //输出模板 + // 输出模板 ctx.SendChain( message.Text("> ", ctx.Event.Sender.NickName, " ", language, "-template:\n"), message.Text( @@ -216,7 +216,7 @@ func runCode(code string, runType [2]string) (string, error) { } defer body.Body.Close() if body.StatusCode != http.StatusOK { - return "", fmt.Errorf("code %d", body.StatusCode) + return "", errors.New("code not 200") } res, err := ioutil.ReadAll(body.Body) if err != nil { @@ -225,7 +225,7 @@ func runCode(code string, runType [2]string) (string, error) { // 结果处理 content := gjson.ParseBytes(res) if e := content.Get("errors").Str; e != "\n\n" { - return "", fmt.Errorf(cutTooLong(clearNewLineSuffix(e))) + return "", errors.New(cutTooLong(clearNewLineSuffix(e))) } output := content.Get("output").Str