✏️ 插件控制 增加当前群开启状态显示

This commit is contained in:
fumiama 2021-09-10 14:29:03 +08:00
parent f0d7b38a73
commit dbb681e8a6

View File

@ -69,13 +69,10 @@ func (m *Control) disable(groupID int64) {
m.Unlock()
}
// Handler 返回 预处理器
func (m *Control) Handler() zero.Rule {
return func(ctx *zero.Ctx) bool {
func (m *Control) isEnabledIn(gid int64) bool {
m.RLock()
ctx.State["manager"] = m
var c grpcfg
err := db.Find(m.service, &c, "WHERE gid = "+strconv.FormatInt(ctx.Event.GroupID, 10))
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)
@ -85,12 +82,19 @@ func (m *Control) Handler() zero.Rule {
}
m.RUnlock()
if m.options.DisableOnDefault {
m.disable(ctx.Event.GroupID)
m.disable(gid)
} else {
m.enable(ctx.Event.GroupID)
m.enable(gid)
}
return !m.options.DisableOnDefault
}
// Handler 返回 预处理器
func (m *Control) Handler() zero.Rule {
return func(ctx *zero.Ctx) bool {
ctx.State["manager"] = m
return m.isEnabledIn(ctx.Event.GroupID)
}
}
// lookup returns a Manager by the service name, if
@ -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))