From 17826afb1e7ed63f8dc052a2e109cb2507400f20 Mon Sep 17 00:00:00 2001 From: Luther Wen Xu Date: Wed, 27 Nov 2019 20:16:32 +0800 Subject: [PATCH] modules/commands: Implement 'pgqversion' command --- modules/commands/commands.go | 4 ++++ modules/commands/version.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 modules/commands/version.go diff --git a/modules/commands/commands.go b/modules/commands/commands.go index 0a7e5f8..a73b6e9 100644 --- a/modules/commands/commands.go +++ b/modules/commands/commands.go @@ -24,4 +24,8 @@ var list = []command{ Name: "star", Handler: handleStarCommand, }, + command{ + Name: "version", + Handler: handleVersionCommand, + }, } diff --git a/modules/commands/version.go b/modules/commands/version.go new file mode 100644 index 0000000..f4fc6e5 --- /dev/null +++ b/modules/commands/version.go @@ -0,0 +1,34 @@ +package commands + +import ( + "fmt" + "os/exec" + "strings" + + "github.com/bwmarrin/discordgo" + + "PermissionGacha/modules/log" +) + +var versionString string + +func handleVersionCommand(s *discordgo.Session, args []string, m *discordgo.MessageCreate) error { + if versionString == "" { + out, err := exec.Command("git describe --tags").Output() + if err != nil { + log.Error( + s, + fmt.Errorf("modules/commands: error while requesting version information from git: %v", err), + ) + versionString = "Error while generating version string." + } else { + info := strings.Split(string(out), " ") + versionString = fmt.Sprintf( + "**VERSION > **Current running version: __%s.%s__ (Internal ID: %s)", + info[0], info[1], info[2], + ) + } + } + s.ChannelMessageSend(m.ChannelID, versionString) + return nil +}