mirror of
https://git.klmp200.net/ALFRED/ALFRED.git
synced 2025-05-25 05:01:16 +02:00
Plugins in plugin folder
This commit is contained in:
parent
9b5c849dcc
commit
d43ffcb445
7 changed files with 19 additions and 14 deletions
68
plugin/plugin.go
Normal file
68
plugin/plugin.go
Normal file
|
@ -0,0 +1,68 @@
|
|||
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
|
40
plugin/test.go
Normal file
40
plugin/test.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
tb "gopkg.in/tucnak/telebot.v2"
|
||||
"log"
|
||||
)
|
||||
|
||||
type plugin string
|
||||
|
||||
func (g plugin) GetCommands() []string {
|
||||
return []string{"ping", "test"}
|
||||
}
|
||||
|
||||
func (g plugin) Load() bool {
|
||||
log.Println("plugin test loaded!")
|
||||
return true
|
||||
}
|
||||
|
||||
func (g plugin) HandleMessage(bot *tb.Bot, msg *tb.Message) {
|
||||
log.Println("plugin test message: " + msg.Text)
|
||||
}
|
||||
|
||||
func (g plugin) HandleCommand(bot *tb.Bot, msg *tb.Message, cmd string, args []string) {
|
||||
if cmd == "ping" {
|
||||
bot.Send(msg.Chat, "pong!")
|
||||
}
|
||||
argsS := ""
|
||||
for _, arg := range args {
|
||||
argsS = argsS + " " + arg
|
||||
}
|
||||
log.Print("plugin test cmd: " + cmd + " (args:" + argsS + ")")
|
||||
|
||||
}
|
||||
|
||||
func (g plugin) Unload() bool {
|
||||
log.Println("plugin test unloaded!")
|
||||
return true
|
||||
}
|
||||
|
||||
var Plugin plugin
|
22
plugin/test2.go
Normal file
22
plugin/test2.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
tb "gopkg.in/tucnak/telebot.v2"
|
||||
"log"
|
||||
)
|
||||
|
||||
type plugin string
|
||||
|
||||
func (g plugin) Load() {
|
||||
log.Println("plugin test2 loaded!")
|
||||
}
|
||||
|
||||
func (g plugin) HandleMessage(bot *tb.Bot, msg string) {
|
||||
log.Println("test2 message: " + msg)
|
||||
}
|
||||
|
||||
func (g plugin) Unload() {
|
||||
log.Println("plugin test2 unloaded!")
|
||||
}
|
||||
|
||||
var Plugin plugin
|
Loading…
Add table
Add a link
Reference in a new issue