all repos — paprika @ 4f5ac048596e44147f9d9db0731b987a3e92d1bf

go rewrite of taigabot

contrib/new-plugin.go (view raw)

 1package main
 2
 3// Usage: go run new-plugin.go <name>
 4
 5import (
 6	"fmt"
 7	"os"
 8	"path/filepath"
 9	"strings"
10)
11
12func main() {
13	var name string
14	if len(os.Args) == 2 {
15		name = os.Args[1]
16	} else {
17		fmt.Println("usage: new-plugin <name>")
18		os.Exit(1)
19	}
20
21	// make plugin name Title case
22	tc := strings.Title(name)
23
24	template := `package plugins
25
26import (
27	"gopkg.in/irc.v3"
28)
29
30func init() {
31	Register(%s{})
32}
33
34type %s struct{}
35
36func (%s) Triggers() []string {
37	return []string{}
38}
39
40func (%s) Execute(m *irc.Message) (string, error) {
41	return "", nil
42}`
43	out := fmt.Sprintf(template, tc, tc, tc, tc)
44	if err := os.WriteFile(filepath.Join("plugins", name+".go"), []byte(out), 0644); err != nil {
45		fmt.Println(err)
46	}
47
48}