-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
90 lines (69 loc) · 1.79 KB
/
main.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"context"
"flag"
"fmt"
"net/http"
"strings"
"wumpgo.dev/wumpgo/interactions"
"wumpgo.dev/wumpgo/objects"
"wumpgo.dev/wumpgo/rest"
"wumpgo.dev/wumpgo/router"
)
type Echo struct {
Message string `discord:"message,description:Message to echo back"`
}
type EchoCaps struct {
Message string `discord:"message,description:Message to echo back"`
}
type Log struct {
Channel *objects.Channel `discord:",channelTypes:0"`
}
type MyCommand struct {
Echo
EchoCaps
Log
}
func (e MyCommand) Description() string {
return "Test base command"
}
func (e Echo) Description() string {
return "Echos the message you type back to you"
}
func (e EchoCaps) Description() string {
return "Echos the message you type back to you, but in all uppercase"
}
func (e Echo) Handle(r router.CommandResponder, ctx *router.CommandContext) {
r.Content(e.Message)
}
func (e EchoCaps) Handle(r router.CommandResponder, ctx *router.CommandContext) {
r.Content(strings.ToUpper(e.Message))
}
func Check(err error) {
if err != nil {
panic(err.Error())
}
}
func main() {
pubKey := flag.String("pubkey", "", "Discord interactions public key")
token := flag.String("token", "", "Discord token for creating application commands")
flag.Parse()
app, err := interactions.New(*pubKey)
Check(err)
r := router.New(router.WithInteractionsApp(app))
r.MustRegisterCommand(&MyCommand{})
if *token != "" {
fmt.Println("Creating commands with Discord")
c := rest.New(
rest.WithToken(objects.TokenTypeBot, *token),
rest.WithRateLimiter(rest.NewLeakyBucketRatelimiter()),
)
ctx := context.Background()
me, err := c.GetCurrentUser(ctx)
Check(err)
_, err = c.BulkOverwriteGlobalCommands(ctx, me.ID, r.Commands())
Check(err)
}
fmt.Println("Listening on :8080")
http.ListenAndServe(":8080", app)
}