2016-12-11 16:06:17 +00:00
|
|
|
/* Copyright Azareal 2016 - 2017 */
|
|
|
|
package main
|
|
|
|
|
|
|
|
var plugins map[string]Plugin = make(map[string]Plugin)
|
|
|
|
var hooks map[string]func(interface{})interface{} = make(map[string]func(interface{})interface{})
|
2016-12-13 02:14:14 +00:00
|
|
|
var vhooks map[string]func(...interface{})interface{} = make(map[string]func(...interface{})interface{})
|
2016-12-11 16:06:17 +00:00
|
|
|
|
|
|
|
type Plugin struct
|
|
|
|
{
|
|
|
|
UName string
|
|
|
|
Name string
|
|
|
|
Author string
|
|
|
|
URL string
|
|
|
|
Settings string
|
|
|
|
Active bool
|
2016-12-16 10:37:42 +00:00
|
|
|
Tag string
|
2016-12-11 16:06:17 +00:00
|
|
|
Type string
|
|
|
|
Init func()
|
2016-12-16 10:37:42 +00:00
|
|
|
Activate func()error
|
2016-12-13 02:14:14 +00:00
|
|
|
Deactivate func()
|
2016-12-11 16:06:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func add_hook(name string, handler func(interface{})interface{}) {
|
|
|
|
hooks[name] = handler
|
|
|
|
}
|
|
|
|
|
2016-12-13 02:14:14 +00:00
|
|
|
func remove_hook(name string) {
|
|
|
|
delete(hooks, name)
|
|
|
|
}
|
|
|
|
|
2016-12-11 16:06:17 +00:00
|
|
|
func run_hook(name string, data interface{}) interface{} {
|
|
|
|
return hooks[name](data)
|
2016-12-13 02:14:14 +00:00
|
|
|
}
|
|
|
|
|
2016-12-16 10:37:42 +00:00
|
|
|
func add_vhook(name string, handler func(...interface{}) interface{}) {
|
|
|
|
vhooks[name] = handler
|
|
|
|
}
|
|
|
|
|
|
|
|
func remove_vhook(name string) {
|
|
|
|
delete(vhooks, name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func run_vhook(name string, data ...interface{}) interface{} {
|
|
|
|
return vhooks[name](data...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func run_vhook_noreturn(name string, data ...interface{}) {
|
|
|
|
_ = vhooks[name](data...)
|
2016-12-11 16:06:17 +00:00
|
|
|
}
|