contrib/new-plugin.go (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 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) } } |