Skip to content

Commit

Permalink
Format ban duration instead of unban time in login message.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkaeriit committed Aug 9, 2024
1 parent afca4b7 commit 7945c99
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 7945c99

Please sign in to comment.