diff --git a/main.go b/main.go index 296fb3c2..068cfd68 100644 --- a/main.go +++ b/main.go @@ -427,7 +427,8 @@ func newUser(s ssh.Session) *User { Log.Println("Rejected " + u.Name + " [" + host + "] (banned)") u.writeln(Devbot, "**You are banned**. If you feel this was a mistake, please reach out to the server admin. Include the following information: [ID "+u.id+"]") if banInfo.UseTime { - u.writeln(Devbot, "You will be unbaned on "+banInfo.UnbanTime.Format(time.RFC3339)) + when := time.Until(banInfo.UnbanTime) + u.writeln(Devbot, "You will be unbaned in "+formatDuration(when)+".") } s.Close() return nil diff --git a/util.go b/util.go index 58f13f35..91d349a3 100644 --- a/util.go +++ b/util.go @@ -487,3 +487,28 @@ func genKey() (ed25519.PrivateKey, ssh.PublicKey, error) { } return priv, sshPubKey, nil } + +func formatDuration(d time.Duration) string { + seconds := int(d.Seconds()) + minutes := seconds / 60 + seconds = seconds % 60 + ret := fmt.Sprintf("%v seconds", seconds) + if minutes == 0 { + return ret + } + + hours := minutes / 60 + minutes = minutes % 60 + ret = fmt.Sprintf("%v minutes, and %v", minutes, ret) + if hours == 0 { + return ret + } + + days := hours / 24 + hours = hours % 24 + ret = fmt.Sprintf("%v hours, %v", hours, ret) + if days == 0 { + return ret + } + return fmt.Sprintf("%v days, %v", days, ret) +}