Commit 719b6dd0ac

719b6dd0ac5c882f8933cc410d7d5f126c7fd576

parent: 7ab564381a

Unsigned

Vedant Deshmukh <73630434+Vedant9500@users.noreply.github.com> · 2024-12-18 15:32 UTC

Better Time formatting

Layout: unified · split

internal/discord.go +12 −12
@@ -10,29 +10,26 @@ func DiscordPresence(clientId string, anime Anime, IsPaused bool) error {
1010 if err != nil {
1111 return err
1212 }
13
1314 var state string
1415 if IsPaused {
15 state = fmt.Sprintf("\nEpisode %d - %d:%02d (Paused)",
16 state = fmt.Sprintf("\nEpisode %d - %s (Paused)",
1617 anime.Ep.Number,
17 ConvertSecondsToMinutes(anime.Ep.Player.PlaybackTime),
18 anime.Ep.Player.PlaybackTime % 60,
18 FormatTime(anime.Ep.Player.PlaybackTime),
1919 )
2020 } else {
21 state = fmt.Sprintf("\nEpisode %d - %d:%02d / %d:%02d",
21 state = fmt.Sprintf("\nEpisode %d - %s / %s",
2222 anime.Ep.Number,
23 ConvertSecondsToMinutes(anime.Ep.Player.PlaybackTime),
24 anime.Ep.Player.PlaybackTime % 60,
25 ConvertSecondsToMinutes(anime.Ep.Duration),
26 anime.Ep.Duration % 60,
23 FormatTime(anime.Ep.Player.PlaybackTime),
24 FormatTime(anime.Ep.Duration),
2725 )
2826 }
27
2928 err = client.SetActivity(client.Activity{
3029 Details: fmt.Sprintf("%s", GetAnimeName(anime)), // Large text
3130 LargeImage: anime.CoverImage,
3231 LargeText: GetAnimeName(anime), // Would display while hovering over the large image
3332 State: state,
34 // SmallImage: anime.CoverImage, // Image would appear in the bottom left corner
35 // SmallText: fmt.Sprintf("%s", anime.Ep.Title.English), // Would display while hovering over the small image
3633 Buttons: []*client.Button{
3734 &client.Button{
3835 Label: "View on AniList", // Button label
@@ -50,6 +47,9 @@ func DiscordPresence(clientId string, anime Anime, IsPaused bool) error {
5047 return nil
5148}
5249
53func ConvertSecondsToMinutes(seconds int) int {
54 return seconds / 60
50func FormatTime(seconds int) string {
51 hours := seconds / 3600
52 minutes := (seconds % 3600) / 60
53 remainingSeconds := seconds % 60
54 return fmt.Sprintf("%d:%02d:%02d", hours, minutes, remainingSeconds)
5555}