@@ -7,6 +7,7 @@ package discord // import "github.com/wabarc/wayback/service/discord"
77import (
88 "context"
99 "encoding/base64"
10+ "fmt"
1011 "net/url"
1112 "strconv"
1213 "strings"
@@ -166,7 +167,7 @@ func (d *Discord) Shutdown() error {
166167
167168func (d * Discord ) commandHandlers () map [string ]func (* discord.Session , * discord.InteractionCreate ) {
168169 return map [string ]func (s * discord.Session , i * discord.InteractionCreate ){
169- "help" : func (s * discord.Session , i * discord.InteractionCreate ) {
170+ service . CommandHelp : func (s * discord.Session , i * discord.InteractionCreate ) {
170171 // nolint:errcheck
171172 s .InteractionRespond (i .Interaction , & discord.InteractionResponse {
172173 Type : discord .InteractionResponseChannelMessageWithSource ,
@@ -175,10 +176,10 @@ func (d *Discord) commandHandlers() map[string]func(*discord.Session, *discord.I
175176 },
176177 })
177178 },
178- "playback" : func (s * discord.Session , i * discord.InteractionCreate ) {
179+ service . CommandPlayback : func (s * discord.Session , i * discord.InteractionCreate ) {
179180 d .playback (s , i ) // nolint:errcheck
180181 },
181- "metrics" : func (s * discord.Session , i * discord.InteractionCreate ) {
182+ service . CommandMetrics : func (s * discord.Session , i * discord.InteractionCreate ) {
182183 stats := metrics .Gather .Export ("wayback" )
183184 if ! d .opts .EnabledMetrics () || stats == "" {
184185 return
@@ -191,12 +192,21 @@ func (d *Discord) commandHandlers() map[string]func(*discord.Session, *discord.I
191192 },
192193 })
193194 },
195+ service .CommandPrivacy : func (s * discord.Session , i * discord.InteractionCreate ) {
196+ // nolint:errcheck
197+ s .InteractionRespond (i .Interaction , & discord.InteractionResponse {
198+ Type : discord .InteractionResponseChannelMessageWithSource ,
199+ Data : & discord.InteractionResponseData {
200+ Content : fmt .Sprintf ("To read our privacy policy, please visit %s." , d .opts .PrivacyURL ()),
201+ },
202+ })
203+ },
194204 }
195205}
196206
197207func (d * Discord ) buttonHandlers () map [string ]func (* discord.Session , * discord.InteractionCreate ) {
198208 return map [string ]func (s * discord.Session , i * discord.InteractionCreate ){
199- "playback" : func (s * discord.Session , i * discord.InteractionCreate ) {
209+ service . CommandPlayback : func (s * discord.Session , i * discord.InteractionCreate ) {
200210 id , err := strconv .Atoi (i .MessageComponentData ().CustomID )
201211 if err != nil {
202212 logger .Warn ("invalid playback id: %s" , i .MessageComponentData ().CustomID )
@@ -439,18 +449,24 @@ func (d *Discord) setCommands(guild string) (err error) {
439449func (d * Discord ) requires () (commands []* discord.ApplicationCommand ) {
440450 if d .opts .DiscordHelptext () != "" {
441451 commands = append (commands , & discord.ApplicationCommand {
442- Name : "help" ,
452+ Name : service . CommandHelp ,
443453 Description : "Show help information" ,
444454 })
445455 }
446456 if d .opts .EnabledMetrics () {
447457 commands = append (commands , & discord.ApplicationCommand {
448- Name : "metrics" ,
458+ Name : service . CommandMetrics ,
449459 Description : "Show service metrics" ,
450460 })
451461 }
462+ if d .opts .PrivacyURL () != "" {
463+ commands = append (commands , & discord.ApplicationCommand {
464+ Name : service .CommandPrivacy ,
465+ Description : "Read our privacy policy" ,
466+ })
467+ }
452468 commands = append (commands , & discord.ApplicationCommand {
453- Name : "playback" ,
469+ Name : service . CommandPlayback ,
454470 Description : "Playback archived url" ,
455471 Options : []* discord.ApplicationCommandOption {
456472 {
0 commit comments