-
Notifications
You must be signed in to change notification settings - Fork 6
/
modules.go
81 lines (67 loc) · 1.83 KB
/
modules.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
//"github.com/Clinet/clinet/bot/modules/core"
//A convenient std plugin replacement written for me to reload plugins
//"github.com/superwhiskers/uwu"
//std necessities
"io/ioutil"
)
var Modules []*Module
type Module struct {
// Plugin *uwu.Plugin
}
func loadModules() {
log.Trace("--- loadModules() ---")
log.Warn("Modules are not supported yet!")
/*wd, _ := os.Getwd()
modulesDir := wd + "/modules"
log.Debug("Searching for modules")
recurseCall(modulesDir, func(path string) {
if strings.HasSuffix(path, ".so") {
log.Debug("Loading module (", path, ") into memory")
plugin, err := uwu.LoadPlugin(path)
if err != nil {
log.Error("Error loading module (", path, ") into memory: ", err)
return
}
log.Debug("Loading symbols from module (", path, ")")
err = plugin.Load()
if err != nil {
log.Error("Error loading symbols from module (", path, "): ", err)
plugin.Unload()
return
}
log.Debug("Initializing module (", path, ")")
err = plugin.Init()
if err != nil {
log.Error("Error initializing module (", path, "): ", err)
plugin.Unload()
return
}
log.Debug("Calling for metadata from module (", path, ")")
voidMetadata, err := plugin.Call("GetMetadata")
if err != nil {
log.Error("Error getting metadata from module (", path, "): ", err)
plugin.Unload()
return
}
ptrMetadata := unsafe.Pointer(&voidMetadata)
metadata := *(*modulecore.Metadata)(ptrMetadata)
log.Debug("METADATA: ", metadata)
plugin.Unload()
}
})*/
}
func recurseCall(path string, function func(path string)) error {
files, err := ioutil.ReadDir(path)
if err != nil {
return err
}
for _, result := range files {
if result.IsDir() {
recurseCall(path + "/" + result.Name(), function)
}
go function(path + "/" + result.Name())
}
return nil
}