Commit 719b6dd0ac
Unsigned
Layout: unified · split
internal/discord.go +12 −12
| @@ -10,29 +10,26 @@ func DiscordPresence(clientId string, anime Anime, IsPaused bool) error { | |||
| 10 | if err != nil { | 10 | if err != nil { |
| 11 | return err | 11 | return err |
| 12 | } | 12 | } |
| 13 | |||
| 13 | var state string | 14 | var state string |
| 14 | if IsPaused { | 15 | if IsPaused { |
| 15 | state = fmt.Sprintf("\nEpisode %d - %d:%02d (Paused)", | 16 | state = fmt.Sprintf("\nEpisode %d - %s (Paused)", |
| 16 | anime.Ep.Number, | 17 | anime.Ep.Number, |
| 17 | ConvertSecondsToMinutes(anime.Ep.Player.PlaybackTime), | 18 | FormatTime(anime.Ep.Player.PlaybackTime), |
| 18 | anime.Ep.Player.PlaybackTime % 60, | ||
| 19 | ) | 19 | ) |
| 20 | } else { | 20 | } else { |
| 21 | state = fmt.Sprintf("\nEpisode %d - %d:%02d / %d:%02d", | 21 | state = fmt.Sprintf("\nEpisode %d - %s / %s", |
| 22 | anime.Ep.Number, | 22 | anime.Ep.Number, |
| 23 | ConvertSecondsToMinutes(anime.Ep.Player.PlaybackTime), | 23 | FormatTime(anime.Ep.Player.PlaybackTime), |
| 24 | anime.Ep.Player.PlaybackTime % 60, | 24 | FormatTime(anime.Ep.Duration), |
| 25 | ConvertSecondsToMinutes(anime.Ep.Duration), | ||
| 26 | anime.Ep.Duration % 60, | ||
| 27 | ) | 25 | ) |
| 28 | } | 26 | } |
| 27 | |||
| 29 | err = client.SetActivity(client.Activity{ | 28 | err = client.SetActivity(client.Activity{ |
| 30 | Details: fmt.Sprintf("%s", GetAnimeName(anime)), // Large text | 29 | Details: fmt.Sprintf("%s", GetAnimeName(anime)), // Large text |
| 31 | LargeImage: anime.CoverImage, | 30 | LargeImage: anime.CoverImage, |
| 32 | LargeText: GetAnimeName(anime), // Would display while hovering over the large image | 31 | LargeText: GetAnimeName(anime), // Would display while hovering over the large image |
| 33 | State: state, | 32 | 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 | ||
| 36 | Buttons: []*client.Button{ | 33 | Buttons: []*client.Button{ |
| 37 | &client.Button{ | 34 | &client.Button{ |
| 38 | Label: "View on AniList", // Button label | 35 | Label: "View on AniList", // Button label |
| @@ -50,6 +47,9 @@ func DiscordPresence(clientId string, anime Anime, IsPaused bool) error { | |||
| 50 | return nil | 47 | return nil |
| 51 | } | 48 | } |
| 52 | 49 | ||
| 53 | func ConvertSecondsToMinutes(seconds int) int { | 50 | func FormatTime(seconds int) string { |
| 54 | return seconds / 60 | 51 | hours := seconds / 3600 |
| 52 | minutes := (seconds % 3600) / 60 | ||
| 53 | remainingSeconds := seconds % 60 | ||
| 54 | return fmt.Sprintf("%d:%02d:%02d", hours, minutes, remainingSeconds) | ||
| 55 | } | 55 | } |