forked from bwmarrin/discordgo
/
main.go
125 lines (111 loc) · 3.18 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package main
import (
"flag"
dgo "github.com/bwmarrin/discordgo"
"log"
"os"
"os/signal"
"syscall"
"time"
)
var (
botToken = flag.String("bot_tok", "", "Bot token")
testGuild = flag.String("test_guild", "", "Guild for testing the bot")
)
func setup() *dgo.Session {
client, err := dgo.New("Bot " + *botToken)
if err != nil {
log.Fatal(err)
}
client.AddHandler(func(*dgo.Session, *dgo.Ready) {
log.Println("Bot is up!")
})
return client
}
func main() {
flag.Parse()
client := setup()
client.AddHandler(func(s *dgo.Session, i *dgo.InteractionCreate) {
responseType := dgo.InteractionResponseType(i.Interaction.Data.Options[0].Value.(float64))
responseData := &dgo.InteractionApplicationCommandResponseData{
TTS: false,
Content: "here we go",
// Flags: 1 << 6,
}
if responseType == dgo.InteractionResponseACKWithSource || responseType == dgo.InteractionResponseAcknowledge {
responseData = nil
}
log.Println("response parameters:", responseType, responseData)
err := s.InteractionRespond(i.Interaction, &dgo.InteractionResponse{
Type: responseType,
Data: responseData,
})
log.Println("response", err)
time.Sleep(time.Second * 2)
err = s.InteractionResponseEdit("", i.Interaction, &dgo.WebhookEdit{
Content: "here we go!",
})
log.Println("response edit", err)
time.Sleep(time.Second * 2)
err = s.InteractionResponseDelete("", i.Interaction)
log.Println("response delete", err)
err = s.InteractionResponseDelete("", i.Interaction)
log.Println("response delete 2", err)
followupMessage, err := s.FollowupMessageCreate("", i.Interaction, true, &dgo.WebhookParams{
Content: "followup messages rule!",
})
log.Println("followup message create", followupMessage, err)
time.Sleep(time.Second * 3)
err = s.FollowupMessageEdit("", i.Interaction, followupMessage.ID, &dgo.WebhookEdit{
Content: "that's true",
})
log.Println("followup message edit", err)
time.Sleep(time.Second * 3)
err = s.FollowupMessageDelete("", i.Interaction, followupMessage.ID)
log.Println("followup message delete", err)
})
if err := client.Open(); err != nil {
log.Fatal(err)
}
cmd, err := client.ApplicationCommandCreate("", &dgo.ApplicationCommand{
Name: "test-slashes",
Description: "Command for testing application commands",
Options: []*dgo.ApplicationCommandOption{
{
Type: dgo.ApplicationCommandOptionInteger,
Name: "typ",
Description: "Response type",
Choices: []*dgo.ApplicationCommandOptionChoice{
{
Name: "ACK",
Value: dgo.InteractionResponseAcknowledge,
},
{
Name: "ACK with source",
Value: dgo.InteractionResponseACKWithSource,
},
{
Name: "Channel message",
Value: dgo.InteractionResponseChannelMessage,
},
{
Name: "Channel message with source",
Value: dgo.InteractionResponseChannelMessageWithSource,
},
},
Required: false,
},
},
}, *testGuild)
if err != nil {
log.Fatal(err)
}
log.Println("Old command: ", cmd)
log.Println("Created command: ", cmd)
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGINT, os.Interrupt)
<-ch
if err := client.Close(); err != nil {
log.Fatal(err)
}
}