simple plugin system added
1 parent ad4b487 commit 97249cfaa1a2ac1f8521ff66d6f23584b5d9f359
root authored on 25 Jun 2022
Showing 7 changed files
View
26
PluginSystem/README.md 0 → 100644
Plugin Example
===============
A simple plugin system so people can create simple plugin.go files to drop in a specific folder and they will be recognized and added to the app for use within the app.
 
*example use:*
 
```
$> ./Vic4
result of !help:
cmd:!help, name:Help
about:Display all plugins informaion
 
cmd:!add, name:Example Addition
about:Example plugin to add two numbers together
 
cmd:!echo, name:Example Echo
about:Example plugin to repeat what is sent to it
 
result of !echo: returning: this argument returned
result of !add (1+2): 3
```
 
Thanks
===============
A MASSIVE thanks to @MantisSTS for writing the majority of this!
View
29
PluginSystem/main.go 0 → 100755
package main
 
import (
"fmt"
 
"PluginSystem/plugins"
_ "PluginSystem/plugins/misc"
_ "PluginSystem/plugins/example"
)
 
func main() {
 
result := plugins.RunPlugin("!help", "")
fmt.Println("result of !help:")
fmt.Print(result)
 
cmd := "!echo"
arg := "this argument returned"
result = plugins.RunPlugin(cmd, arg)
fmt.Println("result of !echo:", result)
 
 
cmd = "!add"
arg = "{\"intA\":1, \"intB\":2}"
result = plugins.RunPlugin(cmd, arg)
fmt.Println("result of !add (1+2):", result)
 
}
View
45
PluginSystem/plugins/example/example_addition.go 0 → 100755
package example
 
import (
"fmt"
"strconv"
"encoding/json"
 
"PLuginExample/plugins"
)
 
type ExampleInts struct {
IntA int `json:"intA"`
IntB int `json:"intB"`
}
 
func add(firstNo int, secondNo int)string {
result := strconv.Itoa( firstNo + secondNo )
return result
}
 
func init() {
 
var commands plugins.Command
commands.Name = "!add"
commands.Callback = func(args ...interface{})(string) {
var ints ExampleInts
 
jsonToUse := []byte(args[0].(string))
err := json.Unmarshal(jsonToUse, &ints)
if err != nil {
fmt.Println(err.Error())
}
 
result := add(ints.IntA, ints.IntB)
return result
}
 
var p plugins.PluginInfo
p.Name = "Example Addition"
p.About = "Example plugin to add two numbers together"
p.Commands = commands
p.AddPluginInfo()
}
View
28
PluginSystem/plugins/example/example_echo.go 0 → 100755
package example
 
import (
//"fmt"
"PluginExample/plugins"
)
 
func echo(msg string)string {
result := "returning: " + msg
return result
}
 
func init() {
 
var commands plugins.Command
commands.Name = "!echo"
commands.Callback = func(args ...interface{})(string) {
result := echo(args[0].(string))
return result
}
 
var p plugins.PluginInfo
p.Name = "Example Echo"
p.About = "Example plugin to repeat what is sent to it"
p.Commands = commands
p.AddPluginInfo()
}
View
38
PluginSystem/plugins/misc/help.go 0 → 100755
package misc
 
import (
//"fmt"
"PluginExample/plugins"
)
 
func misc_help(msg string)string {
var result string
for _, element := range plugins.Plugins {
 
result += "cmd:" + element.Commands.Name + ", "
result += "name:" + element.Name + "\n"
result += "about:" + element.About + "\n\n"
//element.Commands[0].Callback()
 
//result += "cmd:", key, "=>", "info:", element
}
 
return result
}
 
func init() {
 
var commands plugins.Command
commands.Name = "!help"
commands.Callback = func(args ...interface{})(string) {
result := misc_help(args[0].(string))
return result
}
 
var p plugins.PluginInfo
p.Name = "Help"
p.About = "Display all plugins informaion"
p.Commands = commands
p.AddPluginInfo()
}
View
38
PluginSystem/plugins/pluginsHelper.go 0 → 100755
package plugins
 
//import "fmt"
 
type PluginInfo struct {
Name string
About string
Commands Command
}
 
type Command struct {
Name string
Callback func(args ...interface{})(string)
}
 
var Plugins []PluginInfo
 
func (p *PluginInfo) AddPluginInfo() {
Plugins = append(Plugins, *p)
}
 
func (p *PluginInfo) Handle() {
 
}
 
func RunPlugin(cmd string, arg string)string{
var result string
for _, element := range Plugins {
// fmt.Println("cmd:", key, "=>", "info:", element) // DEBUG
if element.Commands.Name == cmd {
result = element.Commands.Callback(arg)
return result
}
result = "command not found"
}
return result
}
View
5
README.md
**<u>WindowsShortcutFull</u>**
 
view, modify and create windows shortcut files (.lnk)
 
**<u>PLuginExample</u>**
 
A small PoC showing how to add a pluginsystem to your application
 
**<u>RunningAs</u>**
 
Alert box containing current user process running as
Buy Me A Coffee