From dbb681e8a6fe066ff0f7a04d501287e576034ccd Mon Sep 17 00:00:00 2001 From: fumiama Date: Fri, 10 Sep 2021 14:29:03 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20=20=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=20=E5=A2=9E=E5=8A=A0=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E7=BE=A4=E5=BC=80=E5=90=AF=E7=8A=B6=E6=80=81=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- control/rule.go | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/control/rule.go b/control/rule.go index 05a54452..40e9e87b 100644 --- a/control/rule.go +++ b/control/rule.go @@ -69,27 +69,31 @@ func (m *Control) disable(groupID int64) { m.Unlock() } +func (m *Control) isEnabledIn(gid int64) bool { + m.RLock() + var c grpcfg + err := db.Find(m.service, &c, "WHERE gid = "+strconv.FormatInt(gid, 10)) + if err == nil { + m.RUnlock() + logrus.Debugf("[control] plugin %s of grp %d : %d", m.service, c.GroupID, c.Disable) + return c.Disable == 0 + } else { + logrus.Errorf("[control] %v", err) + } + m.RUnlock() + if m.options.DisableOnDefault { + m.disable(gid) + } else { + m.enable(gid) + } + return !m.options.DisableOnDefault +} + // Handler 返回 预处理器 func (m *Control) Handler() zero.Rule { return func(ctx *zero.Ctx) bool { - m.RLock() ctx.State["manager"] = m - var c grpcfg - err := db.Find(m.service, &c, "WHERE gid = "+strconv.FormatInt(ctx.Event.GroupID, 10)) - if err == nil { - m.RUnlock() - logrus.Debugf("[control] plugin %s of grp %d : %d", m.service, c.GroupID, c.Disable) - return c.Disable == 0 - } else { - logrus.Errorf("[control] %v", err) - } - m.RUnlock() - if m.options.DisableOnDefault { - m.disable(ctx.Event.GroupID) - } else { - m.enable(ctx.Event.GroupID) - } - return !m.options.DisableOnDefault + return m.isEnabledIn(ctx.Event.GroupID) } } @@ -177,6 +181,11 @@ func init() { forEach(func(key string, manager *Control) bool { i++ msg += "\n" + strconv.Itoa(i) + `: ` + key + if manager.isEnabledIn(ctx.Event.GroupID) { + msg += " ●" + } else { + msg += " ○" + } return true }) ctx.Send(message.Text(msg))