Newer
Older
GoModules / PluginSystem / plugins / example / example_addition.go
root on 25 Jun 2022 899 bytes simple plugin system added
  1. package example
  2.  
  3. import (
  4. "fmt"
  5. "strconv"
  6. "encoding/json"
  7.  
  8. "PLuginExample/plugins"
  9. )
  10.  
  11. type ExampleInts struct {
  12. IntA int `json:"intA"`
  13. IntB int `json:"intB"`
  14. }
  15.  
  16. func add(firstNo int, secondNo int)string {
  17. result := strconv.Itoa( firstNo + secondNo )
  18. return result
  19. }
  20.  
  21. func init() {
  22.  
  23. var commands plugins.Command
  24. commands.Name = "!add"
  25. commands.Callback = func(args ...interface{})(string) {
  26. var ints ExampleInts
  27.  
  28. jsonToUse := []byte(args[0].(string))
  29. err := json.Unmarshal(jsonToUse, &ints)
  30. if err != nil {
  31. fmt.Println(err.Error())
  32. }
  33.  
  34. result := add(ints.IntA, ints.IntB)
  35. return result
  36. }
  37.  
  38. var p plugins.PluginInfo
  39. p.Name = "Example Addition"
  40. p.About = "Example plugin to add two numbers together"
  41. p.Commands = commands
  42. p.AddPluginInfo()
  43. }
Buy Me A Coffee