Send plain version number to WhatsApp

This commit is contained in:
Tulir Asokan 2020-06-03 20:59:44 +03:00
parent 4b23ca9ff2
commit 3f35a90145
3 changed files with 10 additions and 8 deletions

View file

@ -179,11 +179,11 @@ func (handler *CommandHandler) CommandDevTest(_ *CommandEvent) {
const cmdVersionHelp = `version - View the bridge version`
func (handler *CommandHandler) CommandVersion(ce *CommandEvent) {
version := fmt.Sprintf("%s.unknown", Version)
version := fmt.Sprintf("v%s.unknown", Version)
if Tag == Version {
version = fmt.Sprintf("[%s](%s/releases/%s) (%s)", Version, URL, Tag, BuildTime)
version = fmt.Sprintf("[v%s](%s/releases/%s) (%s)", Version, URL, Tag, BuildTime)
} else if len(Commit) > 8 {
version = fmt.Sprintf("%s.[%s](%s/commit/%s) (%s)", Version, Commit[:8], URL, Commit, BuildTime)
version = fmt.Sprintf("v%s.[%s](%s/commit/%s) (%s)", Version, Commit[:8], URL, Commit, BuildTime)
}
ce.Reply(fmt.Sprintf("[%s](%s) %s", Name, URL, version))
}

10
main.go
View file

@ -42,12 +42,13 @@ import (
var (
// These are static
Name = "mautrix-whatsapp"
URL = "https://github.com/tulir/mautrix-whatsapp"
URL = "https://github.com/tulir/mautrix-whatsapp"
// This is changed when making a release
Version = "0.1.0+dev"
Version = "0.1.0+dev"
WAVersion = ""
// These are filled at build time with the -X linker flag
Tag = "unknown"
Commit = "unknown"
Tag = "unknown"
Commit = "unknown"
BuildTime = "unknown"
)
@ -58,6 +59,7 @@ func init() {
if Tag != Version && !strings.HasSuffix(Version, "+dev") {
Version += "+dev"
}
WAVersion = strings.FieldsFunc(Version, func(r rune) bool { return r == '-' || r == '+' })[0]
}
var configPath = flag.MakeFull("c", "config", "The path to your config file.", "config.yaml").String()

View file

@ -235,7 +235,7 @@ func (user *User) Connect(evenIfNoSession bool) bool {
return false
}
user.Conn = whatsappExt.ExtendConn(conn)
_ = user.Conn.SetClientName("Mautrix-WhatsApp bridge", "mx-wa", Version)
_ = user.Conn.SetClientName("Mautrix-WhatsApp bridge", "mx-wa", WAVersion)
user.log.Debugln("WhatsApp connection successful")
user.Conn.AddHandler(user)
return user.RestoreSession()