From 6d4cd799405b8b1c5928a8edd88bbea3df48a0d1 Mon Sep 17 00:00:00 2001 From: Logan Gartner Date: Sun, 17 Jul 2022 17:43:08 -0600 Subject: [PATCH] Added version command --- commands.go | 19 +++++++++++++++++++ main.go | 5 +++++ 2 files changed, 24 insertions(+) diff --git a/commands.go b/commands.go index ac98f32..0603eb4 100644 --- a/commands.go +++ b/commands.go @@ -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, + }, + }) +} + diff --git a/main.go b/main.go index 1c3b48a..e255468 100644 --- a/main.go +++ b/main.go @@ -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, } )