-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
50 lines (42 loc) · 1.26 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
package main
import (
"context"
"log"
"net/http"
"os"
"github.com/Karitham/corde"
)
var command = corde.NewSlashCommand("bongo", "send a big bongo")
func main() {
token := os.Getenv("DISCORD_BOT_TOKEN")
if token == "" {
log.Fatalln("DISCORD_BOT_TOKEN not set")
}
appID := corde.SnowflakeFromString(os.Getenv("DISCORD_APP_ID"))
if appID == 0 {
log.Fatalln("DISCORD_APP_ID not set")
}
pk := os.Getenv("DISCORD_PUBLIC_KEY")
if pk == "" {
log.Fatalln("DISCORD_PUBLIC_KEY not set")
}
m := corde.NewMux(pk, appID, token)
m.SlashCommand("bongo", bongoHandler)
g := corde.GuildOpt(corde.SnowflakeFromString(os.Getenv("DISCORD_GUILD_ID")))
if err := m.RegisterCommand(command, g); err != nil {
log.Fatalln("error registering command: ", err)
}
log.Println("serving on :8070")
if err := m.ListenAndServe(":8070"); err != nil {
log.Fatalln(err)
}
}
func bongoHandler(ctx context.Context, w corde.ResponseWriter, _ *corde.Interaction[corde.SlashCommandInteractionData]) {
resp, err := http.Get("https://cdn.discordapp.com/emojis/745709799890747434.gif?size=128")
if err != nil {
w.Respond(corde.NewResp().Content("couldn't retrieve bongo").Ephemeral())
return
}
defer resp.Body.Close()
w.Respond(corde.NewResp().Attachment(resp.Body, "bongo.gif"))
}