Helper program to create a new plugin
Anirudh Oppiliappan x@icyphox.sh
Sun, 19 Dec 2021 19:47:44 +0530
1 files changed,
48 insertions(+),
0 deletions(-)
jump to
A
contrib/new-plugin.go
@@ -0,0 +1,48 @@
+package main + +// usage: go run new-plugin.go <name> + +import ( + "fmt" + "os" + "path/filepath" + "strings" +) + +func main() { + var name string + if len(os.Args) == 2 { + name = os.Args[1] + } else { + fmt.Println("usage: new-plugin <name>") + os.Exit(1) + } + + // make plugin name Title case + tc := strings.Title(name) + + template := `package plugins + +import ( + "gopkg.in/irc.v3" +) + +func init() { + Register(%s{}) +} + +type %s struct{} + +func (%s) Triggers() []string { + return []string{} +} + +func (%s) Execute(m *irc.Message) (string, error) { + return "", nil +}` + out := fmt.Sprintf(template, tc, tc, tc, tc) + if err := os.WriteFile(filepath.Join("plugins", name+".go"), []byte(out), 0644); err != nil { + fmt.Println(err) + } + +}