forked from git.klmp200.net/ALFRED
69 lines
1.5 KiB
Go
69 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"./plugin_manager"
|
|
tb "gopkg.in/tucnak/telebot.v2"
|
|
)
|
|
|
|
type plugin string
|
|
|
|
func (g plugin) GetCommands() []string {
|
|
return []string{"plugin"}
|
|
}
|
|
|
|
func (g plugin) HandleCommand(bot *tb.Bot, msg *tb.Message, cmd string, args []string) {
|
|
if cmd == "plugin" {
|
|
ok := false
|
|
if len(args) >= 1 {
|
|
if args[0] == "list" {
|
|
lst := ""
|
|
for _, pName := range plugin_manager.GetPluginList() {
|
|
lst = lst + "-" + pName + " (status: "
|
|
if plugin_manager.IsPluginEnable(pName) {
|
|
lst += "enable, "
|
|
} else {
|
|
lst += "disable, "
|
|
}
|
|
if plugin_manager.IsPluginRunning(pName) {
|
|
lst += "running"
|
|
} else {
|
|
lst += "stopped"
|
|
}
|
|
lst += ")\n"
|
|
}
|
|
bot.Send(msg.Chat, "liste des plugins disponible:\n"+lst)
|
|
ok = true
|
|
}
|
|
if args[0] == "enable" && len(args) >= 2 {
|
|
for _, name := range args[1:] {
|
|
if plugin_manager.ExistPlugin(name) {
|
|
plugin_manager.EnablePlugin(name, true)
|
|
bot.Send(msg.Chat, "enable plugin "+name)
|
|
}
|
|
}
|
|
ok = true
|
|
}
|
|
if args[0] == "disable" && len(args) >= 2 {
|
|
for _, name := range args[1:] {
|
|
if plugin_manager.ExistPlugin(name) {
|
|
plugin_manager.EnablePlugin(name, false)
|
|
bot.Send(msg.Chat, "disable plugin "+name)
|
|
}
|
|
}
|
|
ok = true
|
|
}
|
|
}
|
|
if !ok {
|
|
bot.Send(msg.Chat, "command inconnue\n"+
|
|
"liste de plugin:\n"+
|
|
"/plugin list\n"+
|
|
"activer un/des plugins\n"+
|
|
"/plugin enable nom_plugin\n"+
|
|
"désactiver un/des plugins\n"+
|
|
"/plugin disable nom_plugin")
|
|
}
|
|
}
|
|
}
|
|
|
|
var Plugin plugin
|