mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
add version tag to ping response
This commit is contained in:
parent
cc6e6b5fc1
commit
7208fb6556
|
@ -10,7 +10,9 @@ import (
|
|||
func Ping() string {
|
||||
botUptime := humanize.Time(common.GetUptime())
|
||||
commandsUsed := common.GetCommandsUsed()
|
||||
commit := common.GetVersion()
|
||||
|
||||
reply := fmt.Sprintf("Pong! :) Commands used: %v, Last restart: %v, Running on commit: %v", commandsUsed, botUptime, commit)
|
||||
|
||||
reply := fmt.Sprintf("Pong! :) Commands used: %v, Last restart: %v", commandsUsed, botUptime)
|
||||
return reply
|
||||
}
|
||||
|
|
43
internal/common/version.go
Normal file
43
internal/common/version.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
// File pretty much completely stolen from a generated
|
||||
// Autostrada project I used a while ago. They don't
|
||||
// require attribution but I still want to give them
|
||||
// credit for their amazing project.
|
||||
// https://autostrada.dev/
|
||||
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime/debug"
|
||||
)
|
||||
|
||||
func GetVersion() string {
|
||||
var revision string
|
||||
var modified bool
|
||||
|
||||
bi, ok := debug.ReadBuildInfo()
|
||||
if ok {
|
||||
for _, s := range bi.Settings {
|
||||
switch s.Key {
|
||||
case "vcs.revision":
|
||||
revision = s.Value
|
||||
case "vcs.modified":
|
||||
if s.Value == "true" {
|
||||
modified = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if revision == "" {
|
||||
return "unavailable"
|
||||
}
|
||||
|
||||
if modified {
|
||||
return fmt.Sprintf("%s-dirty", revision)
|
||||
}
|
||||
|
||||
fmt.Println(revision)
|
||||
|
||||
return revision
|
||||
}
|
Loading…
Reference in a new issue