-
Notifications
You must be signed in to change notification settings - Fork 927
/
plugins.go
49 lines (41 loc) · 1.34 KB
/
plugins.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package common
var (
Plugins []Plugin
)
type PluginCategory struct {
Name string
Order int
}
var (
PluginCategoryCore = &PluginCategory{Name: "Core", Order: 0}
PluginCategoryModeration = &PluginCategory{Name: "Moderation", Order: 10}
PluginCategoryMisc = &PluginCategory{Name: "Misc", Order: 20}
PluginCategoryFeeds = &PluginCategory{Name: "Feeds", Order: 30}
)
// PluginInfo represents basic plugin information
type PluginInfo struct {
Name string // Human readable name of the plugin
SysName string // snake_case version of the name in lower case
Category *PluginCategory
}
// Plugin represents a plugin, all plugins needs to implement this at a bare minimum
type Plugin interface {
PluginInfo() *PluginInfo
}
// RegisterPlugin registers a plugin, should be called when the bot is starting up
func RegisterPlugin(plugin Plugin) {
Plugins = append(Plugins, plugin)
logger.Info("Registered plugin: " + plugin.PluginInfo().Name)
}
// PluginWithCommonRun is for plugins that include a function that's always run, no matter if its the webserver frontend, bot or whatever
type PluginWithCommonRun interface {
CommonRun()
}
// RunCommonRunPlugins runs plugins that implement PluginWithCommonRun
func RunCommonRunPlugins() {
for _, v := range Plugins {
if cast, ok := v.(PluginWithCommonRun); ok {
go cast.CommonRun()
}
}
}