time display rounded

This commit is contained in:
shoopea 2021-11-28 21:25:35 +08:00
parent cd98db8489
commit 3b878e0641
2 changed files with 15 additions and 15 deletions

22
bot.go
View File

@ -201,24 +201,24 @@ func botPlayers(m *tb.Message) {
d1 := time.Now().Sub(cfg.Game.StartDate)
days := int(time.Duration(d1.Hours()) / 24)
d2 := time.Duration(days+1)*(time.Hour)*24 - d1
str := fmt.Sprintf("Update in %s\r\n", d2)
str := fmt.Sprintf("Update in %s\r\n", d2.Round(time.Second))
online := ""
for _, cc := range cfg.Clients {
if cc.Online {
if co, ok := srv.Status.Companies[cc.CompanyID]; ok {
online = online + fmt.Sprintf(" - %s (%s) : %s", cc.Username, cc.TimeLeft, co.Name) + "\r\n"
online = online + fmt.Sprintf(" - %s (%s) : %s", cc.Username, cc.TimeLeft.Round(time.Second), co.Name) + "\r\n"
} else {
online = online + fmt.Sprintf(" - %s (%s) : none", cc.Username, cc.TimeLeft) + "\r\n"
online = online + fmt.Sprintf(" - %s (%s) : none", cc.Username, cc.TimeLeft.Round(time.Second)) + "\r\n"
}
}
}
offline := ""
for _, cc := range cfg.Clients {
if co, ok := srv.Status.Companies[cc.CompanyID]; ok && !cc.Online {
offline = offline + fmt.Sprintf(" - %s (%s) : %s", cc.Username, cc.TimeLeft, co.Name) + "\r\n"
offline = offline + fmt.Sprintf(" - %s (%s) : %s", cc.Username, cc.TimeLeft.Round(time.Second), co.Name) + "\r\n"
} else {
offline = offline + fmt.Sprintf(" - %s (%s) : none", cc.Username, cc.TimeLeft) + "\r\n"
offline = offline + fmt.Sprintf(" - %s (%s) : none", cc.Username, cc.TimeLeft.Round(time.Second)) + "\r\n"
}
}
@ -267,7 +267,7 @@ func botGive(m *tb.Message) {
cc := cfg.Clients[u]
cc.TimeLeft += d
bot.SendChat(m.Chat.ID, fmt.Sprintf("@%s now has %s left.", uStr, cc.TimeLeft))
bot.SendChat(m.Chat.ID, fmt.Sprintf("@%s now has %s left.", uStr, cc.TimeLeft.Round(time.Second)))
}
func botTransfer(m *tb.Message) {
@ -309,7 +309,7 @@ func botTransfer(m *tb.Message) {
ccTo.TimeLeft += d
ccFrom.TimeLeft -= d
bot.SendChat(m.Chat.ID, fmt.Sprintf("@%s now has %s left.\r\n@%s has %s left.", uStr, ccTo.TimeLeft, ccFrom.Username, ccFrom.TimeLeft))
bot.SendChat(m.Chat.ID, fmt.Sprintf("@%s now has %s left.\r\n@%s has %s left.", uStr, ccTo.TimeLeft.Round(time.Second), ccFrom.Username, ccFrom.TimeLeft.Round(time.Second)))
}
func botTake(m *tb.Message) {
@ -348,7 +348,7 @@ func botTake(m *tb.Message) {
cc := cfg.Clients[u]
cc.TimeLeft -= d
bot.SendChat(m.Chat.ID, fmt.Sprintf("@%s now has %s left.", uStr, cc.TimeLeft))
bot.SendChat(m.Chat.ID, fmt.Sprintf("@%s now has %s left.", uStr, cc.TimeLeft.Round(time.Second)))
}
func botHelp(m *tb.Message) {
@ -442,13 +442,13 @@ func botDeregister(m *tb.Message) {
for coID, co := range srv.Status.Companies {
if coID == cc.CompanyID {
cc.CompanyID = 255
bot.SendChat(m.Chat.ID, fmt.Sprintf("Deregistered from %s. %s playable left.", co.Name, cc.TimeLeft))
bot.SendChat(m.Chat.ID, fmt.Sprintf("Deregistered from %s. %s playable left.", co.Name, cc.TimeLeft.Round(time.Second)))
return
}
}
logInfoAlert("botRegister : %s : no such CompanyID : %d", cc.Username, cc.CompanyID)
cc.CompanyID = 255
bot.SendChat(m.Chat.ID, fmt.Sprintf("Registered company didn't exist anymore. %s playable left.", cc.TimeLeft))
bot.SendChat(m.Chat.ID, fmt.Sprintf("Registered company didn't exist anymore. %s playable left.", cc.TimeLeft.Round(time.Second)))
return
}
return
@ -530,7 +530,7 @@ func botRegister(m *tb.Message) {
days := int(time.Now().Sub(cfg.Game.StartDate).Hours() / 24)
cc.TimeLeft = cfg.Game.StartingAllotment + cfg.Game.DailyAllotment*time.Duration(days)
}
bot.SendChat(m.Chat.ID, fmt.Sprintf("@%s registered %s (with %s playable)", cc.Username, srv.Status.Companies[cc.CompanyID].Name, cc.TimeLeft))
bot.SendChat(m.Chat.ID, fmt.Sprintf("@%s registered %s (with %s playable)", cc.Username, srv.Status.Companies[cc.CompanyID].Name, cc.TimeLeft.Round(time.Second)))
return
}
}

View File

@ -1,6 +1,6 @@
// Code generated by version.sh (@generated) DO NOT EDIT.
package main
var githash = "9614fcc"
var buildstamp = "2021-11-28_10:31:27"
var commits = "208"
var version = "9614fcc-b208 - 2021-11-28_10:31:27"
var githash = "cd98db8"
var buildstamp = "2021-11-28_13:25:25"
var commits = "209"
var version = "cd98db8-b209 - 2021-11-28_13:25:25"