()
| 54 | ) |
| 55 | |
| 56 | func init() { // 插件主体 |
| 57 | engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{ |
| 58 | DisableOnDefault: false, |
| 59 | Brief: "自检, 全局限速", |
| 60 | Help: "- 查询计算机当前活跃度: [检查身体 | 自检 | 启动自检 | 系统状态]\n" + |
| 61 | "- 设置默认限速为每 m [分钟 | 秒] n 次触发", |
| 62 | }) |
| 63 | c, ok := control.Lookup("aifalse") |
| 64 | if !ok { |
| 65 | panic("register aifalse error") |
| 66 | } |
| 67 | m := c.GetData(0) |
| 68 | n := (m >> 16) & 0xffff |
| 69 | m &= 0xffff |
| 70 | if m != 0 || n != 0 { |
| 71 | ctxext.SetDefaultLimiterManagerParam(time.Duration(m)*time.Second, int(n)) |
| 72 | logrus.Infoln("设置默认限速为每", m, "秒触发", n, "次") |
| 73 | } |
| 74 | engine.OnFullMatchGroup([]string{"检查身体", "自检", "启动自检", "系统状态"}, zero.AdminPermission).SetBlock(true). |
| 75 | Handle(func(ctx *zero.Ctx) { |
| 76 | now := time.Now().Hour() |
| 77 | isday = now > 7 && now < 19 |
| 78 | |
| 79 | botrunstatus := ctx.CallAction("get_status", zero.Params{}).Data |
| 80 | botverisoninfo := ctx.GetVersionInfo() |
| 81 | sb := &strings.Builder{} |
| 82 | sb.WriteString("在线(") |
| 83 | sb.WriteString(botverisoninfo.Get("app_name").String()) |
| 84 | sb.WriteString("-") |
| 85 | sb.WriteString(botverisoninfo.Get("app_version").String()) |
| 86 | sb.WriteString(") | 收") |
| 87 | sb.WriteString(botrunstatus.Get("stat").Get("message_received").String()) |
| 88 | sb.WriteString(" | 发") |
| 89 | sb.WriteString(botrunstatus.Get("stat").Get("message_sent").String()) |
| 90 | sb.WriteString(" | 群") |
| 91 | sb.WriteString(strconv.Itoa(len(ctx.GetGroupList().Array()))) |
| 92 | sb.WriteString(" | 好友") |
| 93 | sb.WriteString(strconv.Itoa(len(ctx.GetFriendList().Array()))) |
| 94 | |
| 95 | img, err := drawstatus(ctx.State["manager"].(*ctrl.Control[*zero.Ctx]), ctx.Event.SelfID, zero.BotConfig.NickName[0], sb.String()) |
| 96 | if err != nil { |
| 97 | ctx.SendChain(message.Text("ERROR: ", err)) |
| 98 | return |
| 99 | } |
| 100 | sendimg, err := factory.ToBytes(img) |
| 101 | if err != nil { |
| 102 | ctx.SendChain(message.Text("ERROR: ", err)) |
| 103 | return |
| 104 | } |
| 105 | if id := ctx.SendChain(message.ImageBytes(sendimg)); id.ID() == 0 { |
| 106 | ctx.SendChain(message.Text("ERROR: 可能被风控了")) |
| 107 | } |
| 108 | }) |
| 109 | engine.OnRegex(`^设置默认限速为每\s*(\d+)\s*(分钟|秒)\s*(\d+)\s*次触发$`, zero.SuperUserPermission).SetBlock(true). |
| 110 | Handle(func(ctx *zero.Ctx) { |
| 111 | c, ok := ctx.State["manager"].(*ctrl.Control[*zero.Ctx]) |
| 112 | if !ok { |
| 113 | ctx.SendChain(message.Text("ERROR: no such plugin")) |
nothing calls this directly
no test coverage detected