all repos — paprika @ 6db4885ec5acb77b0a73fe306c42874b18e2bed3

go rewrite of taigabot

Helper program to create a new plugin
Anirudh Oppiliappan x@icyphox.sh
Sun, 19 Dec 2021 19:47:44 +0530
commit

6db4885ec5acb77b0a73fe306c42874b18e2bed3

parent

66003ebebf1d467640c279c4d3025dac6c56eb40

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) + } + +}