Added version command

This commit is contained in:
Logan G 2022-07-17 17:43:08 -06:00
parent 369bca9547
commit 6d4cd79940
Signed by: logan
GPG key ID: E328528C921E7A7A
2 changed files with 24 additions and 0 deletions

View file

@ -7,6 +7,8 @@ import (
"github.com/bwmarrin/discordgo"
)
var gitCommit string
func ping(session *discordgo.Session, interaction *discordgo.InteractionCreate) {
session.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
@ -45,3 +47,20 @@ func slowping(session *discordgo.Session, interaction *discordgo.InteractionCrea
log.Println(err)
}
}
func version(session *discordgo.Session, interaction *discordgo.InteractionCreate) {
var response string
if gitCommit == "" {
response = "Commit string not defined."
} else {
response = gitCommit
}
session.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Flags: 1 << 6, // Only lets issuer see initial response
Content: response,
},
})
}

View file

@ -38,11 +38,16 @@ func main() {
Name: "slowping",
Description: "Hopefully replies with pong 10 seconds later or else I'll be sad.",
},
{
Name: "version",
Description: "Gets the bot's current version.",
},
}
commandHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate) {
"ping": ping,
"sping": sping,
"slowping": slowping,
"version": version,
}
)