mirror of
https://github.com/Luzifer/discord-community.git
synced 2024-11-09 23:50:04 +00:00
Simplify presence module and make better readable
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
d7fa78acdf
commit
19c1c4d7b5
1 changed files with 10 additions and 17 deletions
|
@ -4,7 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
|
@ -87,7 +86,7 @@ func (m modPresence) cronUpdatePresence() {
|
||||||
// @attr fallback_text required string "" What to set the text to when no stream is found (`playing <text>`)
|
// @attr fallback_text required string "" What to set the text to when no stream is found (`playing <text>`)
|
||||||
status := m.attrs.MustString("fallback_text", nil)
|
status := m.attrs.MustString("fallback_text", nil)
|
||||||
if nextStream != nil {
|
if nextStream != nil {
|
||||||
status = fmt.Sprintf("in: %s", m.durationToHumanReadable(time.Since(*nextStream)))
|
status = m.durationToHumanReadable(time.Since(*nextStream))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := m.discord.UpdateGameStatus(0, status); err != nil {
|
if err := m.discord.UpdateGameStatus(0, status); err != nil {
|
||||||
|
@ -99,24 +98,18 @@ func (m modPresence) cronUpdatePresence() {
|
||||||
|
|
||||||
func (m modPresence) durationToHumanReadable(d time.Duration) string {
|
func (m modPresence) durationToHumanReadable(d time.Duration) string {
|
||||||
d = time.Duration(math.Abs(float64(d)))
|
d = time.Duration(math.Abs(float64(d)))
|
||||||
|
|
||||||
if d > presenceTimeDay {
|
if d > presenceTimeDay {
|
||||||
return fmt.Sprintf("%.0f Tagen", math.Round(float64(d)/float64(presenceTimeDay)))
|
return fmt.Sprintf("in %.0f Tagen", math.Round(float64(d)/float64(presenceTimeDay)))
|
||||||
}
|
}
|
||||||
|
|
||||||
var elements []string
|
if d > time.Hour {
|
||||||
|
return fmt.Sprintf("in %.0f Stunden", math.Round(float64(d)/float64(time.Hour)))
|
||||||
for div, req := range map[time.Duration]bool{
|
|
||||||
time.Hour: true,
|
|
||||||
time.Minute: true,
|
|
||||||
} {
|
|
||||||
if d < div && !req {
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pt := d / div
|
if d > time.Minute {
|
||||||
d -= pt * div
|
return fmt.Sprintf("in %.0f Minuten", math.Round(float64(d)/float64(time.Minute)))
|
||||||
elements = append(elements, fmt.Sprintf("%.2d", pt))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.Join(elements, ":")
|
return "gleich"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue