From 98f6d0443141f5d5790d00c3fb4508fd7f0b47bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E6=B2=90=E9=A6=A8?= <70338354+LingMuXing@users.noreply.github.com> Date: Tue, 29 Jun 2021 19:35:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0AIfalse.go=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 咕咕咕速度更新中 --- plugin_AIfalse/AIfalse.go | 67 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 plugin_AIfalse/AIfalse.go diff --git a/plugin_AIfalse/AIfalse.go b/plugin_AIfalse/AIfalse.go new file mode 100644 index 00000000..54384c63 --- /dev/null +++ b/plugin_AIfalse/AIfalse.go @@ -0,0 +1,67 @@ +package ASfalse + +import ( + "math/rand" + "time" + "github.com/shirou/gopsutil/cpu" + "github.com/shirou/gopsutil/disk" + "github.com/shirou/gopsutil/mem" + "strconv" + + zero "github.com/wdvxdr1123/ZeroBot" + "github.com/wdvxdr1123/ZeroBot/message" +) + +var ( + PRIO = -1 + RES = "file:///E:/Picture data/" + ENABLE = true +) + + +func GetCpuPercent() float64 { + percent, _:= cpu.Percent(time.Second, false) + return percent[0] +} + +func GetMemPercent() float64 { + memInfo, _ := mem.VirtualMemory() + return memInfo.UsedPercent +} + +func GetDiskPercent() float64 { + parts, _ := disk.Partitions(true) + diskInfo, _ := disk.Usage(parts[0].Mountpoint) + return diskInfo.UsedPercent +} + +func init() { // 插件主体 + zero.OnKeywordGroup([]string{"身体检查","自检","启动自检","系统状态"}, zero.AdminPermission). + Handle(func(ctx *zero.Ctx) { + ctx.SendChain(message.Text( + "人家当前CPU占用率是: ",GetCpuPercent(),"%\n", + "人家当前RAM占用率是: ",GetMemPercent(),"%\n", + "人家当前硬盘活动率是: ", GetDiskPercent(), "%\n", + ), + ) + }) +} + +func randText(text ...string) message.MessageSegment { + length := len(text) + return message.Text(text[rand.Intn(length)]) +} + +func randImage(file ...string) message.MessageSegment { + length := len(file) + return message.Image(RES + file[rand.Intn(length)]) +} + +func randRecord(file ...string) message.MessageSegment { + length := len(file) + return message.Record(RES + file[rand.Intn(length)]) +} +func strToInt(str string) int64 { + val, _ := strconv.ParseInt(str, 10, 64) + return val +}