mirror of
https://git.klmp200.net/ALFRED/ALFRED.git
synced 2025-01-19 02:56:45 +01:00
58 lines
905 B
Go
58 lines
905 B
Go
/**
|
|
* @Author: KLIPFEL Arthur
|
|
* @Date: 2018-08-24 12:17:17
|
|
*/
|
|
package plugin_manager
|
|
|
|
import (
|
|
tb "gopkg.in/tucnak/telebot.v2"
|
|
"io/ioutil"
|
|
"log"
|
|
"plugin"
|
|
"strings"
|
|
)
|
|
|
|
type Plugin interface {
|
|
Load()
|
|
HandleMessage(bot *tb.Bot, msg string)
|
|
Unload()
|
|
}
|
|
|
|
func GetSoFiles(dir string) []string {
|
|
var slice []string
|
|
|
|
files, err := ioutil.ReadDir(dir)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
} else {
|
|
for _, f := range files {
|
|
if strings.HasSuffix(f.Name(), ".so") {
|
|
slice = append(slice, f.Name())
|
|
}
|
|
}
|
|
}
|
|
return slice
|
|
}
|
|
|
|
func LoadSoFile(file string) Plugin {
|
|
plug, err := plugin.Open(file)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
return nil
|
|
}
|
|
|
|
symPlugin, err := plug.Lookup("Plugin")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
return nil
|
|
}
|
|
|
|
var plugin Plugin
|
|
plugin, ok := symPlugin.(Plugin)
|
|
if !ok {
|
|
log.Fatal(file + ": unexpected type from module symbol")
|
|
return nil
|
|
}
|
|
return plugin
|
|
}
|