mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 22:00:11 +08:00
✏️ 插件控制 增加当前群开启状态显示
This commit is contained in:
parent
f0d7b38a73
commit
dbb681e8a6
@ -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))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user