-
Notifications
You must be signed in to change notification settings - Fork 919
/
simple.go
57 lines (45 loc) · 1.42 KB
/
simple.go
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
49
50
51
52
53
54
55
56
57
package main
/*
This example provides 2 basic commands with static responses.
The commands `[hey/hello` and `[bye/bai`
*/
import (
"log"
"os"
"github.com/botlabs-gg/yagpdb/v2/lib/dcmd"
"github.com/botlabs-gg/yagpdb/v2/lib/discordgo"
)
func main() {
system := dcmd.NewStandardSystem("[")
system.Root.AddCommand(&StaticCmd{
Response: "Hey there buddy",
Description: "Greets you",
}, dcmd.NewTrigger("Hello", "Hey"))
system.Root.AddCommand(&StaticCmd{
Response: "Bye friendo!",
Description: "Parting words",
}, dcmd.NewTrigger("Bye", "Bai"))
session, err := discordgo.New(os.Getenv("DISCORD_TOKEN"))
if err != nil {
log.Fatal("Failed setting up session:", err)
}
session.AddHandler(system.HandleMessageCreate)
err = session.Open()
if err != nil {
log.Fatal("Failed opening gateway connection:", err)
}
log.Println("Running, Ctrl-c to stop.")
select {}
}
type StaticCmd struct {
Response string
Description string
}
// Compilie time assertions, will not compiled unless StaticCmd implements these interfaces
var _ dcmd.Cmd = (*StaticCmd)(nil)
var _ dcmd.CmdWithDescriptions = (*StaticCmd)(nil)
// Descriptions should return a short description (used in the overall help overiview) and one long descriptions for targetted help
func (s *StaticCmd) Descriptions(d *dcmd.Data) (string, string) { return s.Description, "" }
func (e *StaticCmd) Run(data *dcmd.Data) (interface{}, error) {
return e.Response, nil
}