This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
2019-11-27 12:16:32 +07:00
|
|
|
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 == "" {
|
2019-11-27 12:35:38 +07:00
|
|
|
out, err := exec.Command("git", "describe", "--tags").Output()
|
2019-11-27 12:16:32 +07:00
|
|
|
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 {
|
2019-11-27 12:35:38 +07:00
|
|
|
info := strings.Split(strings.TrimSpace(string(out)), "-")
|
|
|
|
if len(info) == 1 {
|
|
|
|
versionString = fmt.Sprintf(
|
|
|
|
"**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],
|
|
|
|
)
|
|
|
|
}
|
2019-11-27 12:16:32 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
s.ChannelMessageSend(m.ChannelID, versionString)
|
|
|
|
return nil
|
|
|
|
}
|