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 每个插件对应的管理
|
||||||
managers = map[string]*Control{}
|
managers = map[string]*Control{}
|
||||||
mu = sync.RWMutex{}
|
mu = sync.RWMutex{}
|
||||||
|
hasinit bool
|
||||||
)
|
)
|
||||||
|
|
||||||
// Control is to control the plugins.
|
// Control is to control the plugins.
|
||||||
@ -122,13 +123,14 @@ func copyMap(m map[string]*Control) map[string]*Control {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
if !hasinit {
|
||||||
|
mu.Lock()
|
||||||
|
if !hasinit {
|
||||||
err := os.MkdirAll("data/control", 0755)
|
err := os.MkdirAll("data/control", 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
} else {
|
||||||
}
|
hasinit = true
|
||||||
|
|
||||||
func Init() {
|
|
||||||
zero.OnCommandGroup([]string{"启用", "enable"}, zero.AdminPermission, zero.OnlyGroup).
|
zero.OnCommandGroup([]string{"启用", "enable"}, zero.AdminPermission, zero.OnlyGroup).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
model := extension.CommandModel{}
|
model := extension.CommandModel{}
|
||||||
@ -180,3 +182,7 @@ func Init() {
|
|||||||
ctx.Send(message.Text(msg))
|
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"
|
easy "github.com/t-tomalak/logrus-easy-formatter"
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
"github.com/wdvxdr1123/ZeroBot/driver"
|
"github.com/wdvxdr1123/ZeroBot/driver"
|
||||||
|
|
||||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -62,7 +60,6 @@ func init() {
|
|||||||
LogFormat: "[zero][%time%][%lvl%]: %msg% \n",
|
LogFormat: "[zero][%time%][%lvl%]: %msg% \n",
|
||||||
})
|
})
|
||||||
log.SetLevel(log.DebugLevel)
|
log.SetLevel(log.DebugLevel)
|
||||||
control.Init()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user