modules/commands: Implement 'pgqversion' command

master 0.8
Luther Wen Xu 2019-11-27 20:16:32 +07:00
parent 76b7707b2b
commit 17826afb1e
Signed by: chanbakjsd
GPG Key ID: B7D77E3E9D102B70
2 changed files with 38 additions and 0 deletions

@ -24,4 +24,8 @@ var list = []command{
Name: "star", Name: "star",
Handler: handleStarCommand, Handler: handleStarCommand,
}, },
command{
Name: "version",
Handler: handleVersionCommand,
},
} }

@ -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
}