modules/commands/version: Fix os.exec() call

master
Luther Wen Xu 2019-11-27 20:35:38 +07:00
parent 17826afb1e
commit a49f97dab1
Signed by: chanbakjsd
GPG Key ID: B7D77E3E9D102B70
1 changed files with 13 additions and 6 deletions

@ -14,7 +14,7 @@ var versionString string
func handleVersionCommand(s *discordgo.Session, args []string, m *discordgo.MessageCreate) error { func handleVersionCommand(s *discordgo.Session, args []string, m *discordgo.MessageCreate) error {
if versionString == "" { if versionString == "" {
out, err := exec.Command("git describe --tags").Output() out, err := exec.Command("git", "describe", "--tags").Output()
if err != nil { if err != nil {
log.Error( log.Error(
s, s,
@ -22,11 +22,18 @@ func handleVersionCommand(s *discordgo.Session, args []string, m *discordgo.Mess
) )
versionString = "Error while generating version string." versionString = "Error while generating version string."
} else { } else {
info := strings.Split(string(out), " ") info := strings.Split(strings.TrimSpace(string(out)), "-")
versionString = fmt.Sprintf( if len(info) == 1 {
"**VERSION > **Current running version: __%s.%s__ (Internal ID: %s)", versionString = fmt.Sprintf(
info[0], info[1], info[2], "**VERSION > **Current running version: __%s.0__ (Internal ID: unknown)",
) info[0],
)
} else {
versionString = fmt.Sprintf(
"**VERSION > **Current running version: __%s.%s__ (Internal ID: %s)",
info[0], info[1], info[2],
)
}
} }
} }
s.ChannelMessageSend(m.ChannelID, versionString) s.ChannelMessageSend(m.ChannelID, versionString)