mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 13:59:39 +08:00
✏️ 避免重复调用
This commit is contained in:
parent
70da534bfb
commit
f0d7b38a73
@ -19,6 +19,7 @@ var (
|
||||
// managers 每个插件对应的管理
|
||||
managers = map[string]*Control{}
|
||||
mu = sync.RWMutex{}
|
||||
hasinit bool
|
||||
)
|
||||
|
||||
// Control is to control the plugins.
|
||||
@ -122,13 +123,14 @@ func copyMap(m map[string]*Control) map[string]*Control {
|
||||
}
|
||||
|
||||
func init() {
|
||||
if !hasinit {
|
||||
mu.Lock()
|
||||
if !hasinit {
|
||||
err := os.MkdirAll("data/control", 0755)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func Init() {
|
||||
} else {
|
||||
hasinit = true
|
||||
zero.OnCommandGroup([]string{"启用", "enable"}, zero.AdminPermission, zero.OnlyGroup).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
model := extension.CommandModel{}
|
||||
@ -179,4 +181,8 @@ func Init() {
|
||||
})
|
||||
ctx.Send(message.Text(msg))
|
||||
})
|
||||
}
|
||||
}
|
||||
mu.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
3
main.go
3
main.go
@ -42,8 +42,6 @@ import (
|
||||
easy "github.com/t-tomalak/logrus-easy-formatter"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/driver"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -62,7 +60,6 @@ func init() {
|
||||
LogFormat: "[zero][%time%][%lvl%]: %msg% \n",
|
||||
})
|
||||
log.SetLevel(log.DebugLevel)
|
||||
control.Init()
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user