From 719b6dd0ac5c882f8933cc410d7d5f126c7fd576 Mon Sep 17 00:00:00 2001 From: Vedant Deshmukh <73630434+Vedant9500@users.noreply.github.com> Date: Wed, 18 Dec 2024 15:32:54 +0000 Subject: [PATCH 1/5] Better Time formatting --- internal/discord.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/internal/discord.go b/internal/discord.go index 9fd61bf..a8db63a 100644 --- a/internal/discord.go +++ b/internal/discord.go @@ -10,29 +10,26 @@ func DiscordPresence(clientId string, anime Anime, IsPaused bool) error { if err != nil { return err } + var state string if IsPaused { - state = fmt.Sprintf("\nEpisode %d - %d:%02d (Paused)", + state = fmt.Sprintf("\nEpisode %d - %s (Paused)", anime.Ep.Number, - ConvertSecondsToMinutes(anime.Ep.Player.PlaybackTime), - anime.Ep.Player.PlaybackTime % 60, + FormatTime(anime.Ep.Player.PlaybackTime), ) } else { - state = fmt.Sprintf("\nEpisode %d - %d:%02d / %d:%02d", + state = fmt.Sprintf("\nEpisode %d - %s / %s", anime.Ep.Number, - ConvertSecondsToMinutes(anime.Ep.Player.PlaybackTime), - anime.Ep.Player.PlaybackTime % 60, - ConvertSecondsToMinutes(anime.Ep.Duration), - anime.Ep.Duration % 60, + FormatTime(anime.Ep.Player.PlaybackTime), + FormatTime(anime.Ep.Duration), ) } + err = client.SetActivity(client.Activity{ Details: fmt.Sprintf("%s", GetAnimeName(anime)), // Large text LargeImage: anime.CoverImage, LargeText: GetAnimeName(anime), // Would display while hovering over the large image State: state, - // SmallImage: anime.CoverImage, // Image would appear in the bottom left corner - // SmallText: fmt.Sprintf("%s", anime.Ep.Title.English), // Would display while hovering over the small image Buttons: []*client.Button{ &client.Button{ Label: "View on AniList", // Button label @@ -50,6 +47,9 @@ func DiscordPresence(clientId string, anime Anime, IsPaused bool) error { return nil } -func ConvertSecondsToMinutes(seconds int) int { - return seconds / 60 +func FormatTime(seconds int) string { + hours := seconds / 3600 + minutes := (seconds % 3600) / 60 + remainingSeconds := seconds % 60 + return fmt.Sprintf("%d:%02d:%02d", hours, minutes, remainingSeconds) } From 990948408af25c07c948cb9e301d17f8504e758a Mon Sep 17 00:00:00 2001 From: Vedant Deshmukh <73630434+Vedant9500@users.noreply.github.com> Date: Wed, 18 Dec 2024 15:42:04 +0000 Subject: [PATCH 2/5] Better time formatting --- internal/discord.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/discord.go b/internal/discord.go index a8db63a..50d1a6b 100644 --- a/internal/discord.go +++ b/internal/discord.go @@ -28,8 +28,12 @@ func DiscordPresence(clientId string, anime Anime, IsPaused bool) error { err = client.SetActivity(client.Activity{ Details: fmt.Sprintf("%s", GetAnimeName(anime)), // Large text LargeImage: anime.CoverImage, - LargeText: GetAnimeName(anime), // Would display while hovering over the large image + LargeText: GetAnimeName(anime), // Displays while hovering over the large image State: state, + + //SmallImage: anime.SmallCoverImage, // Image for the bottom left corner + //SmallText: fmt.Sprintf("Episode: %s", anime.Ep.Title.English), // Text when hovering over the small image + Buttons: []*client.Button{ &client.Button{ Label: "View on AniList", // Button label From d4c9b2a492e73c0998bf4395790e60dca8856620 Mon Sep 17 00:00:00 2001 From: Vedant Deshmukh <73630434+Vedant9500@users.noreply.github.com> Date: Wed, 18 Dec 2024 15:46:30 +0000 Subject: [PATCH 3/5] Better time formatting --- .vscode/settings.json | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b242572 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "githubPullRequests.ignoredPullRequestBranches": [ + "main" + ] +} \ No newline at end of file From f1f1938da5955ca165dcd905468f02a2909b8cc6 Mon Sep 17 00:00:00 2001 From: Vedant Deshmukh <73630434+Vedant9500@users.noreply.github.com> Date: Wed, 18 Dec 2024 15:53:50 +0000 Subject: [PATCH 4/5] The FormatTime function has been updated to use minutes if episode length is less than one hour --- internal/discord.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/discord.go b/internal/discord.go index 50d1a6b..0c1c75a 100644 --- a/internal/discord.go +++ b/internal/discord.go @@ -28,12 +28,10 @@ func DiscordPresence(clientId string, anime Anime, IsPaused bool) error { err = client.SetActivity(client.Activity{ Details: fmt.Sprintf("%s", GetAnimeName(anime)), // Large text LargeImage: anime.CoverImage, - LargeText: GetAnimeName(anime), // Displays while hovering over the large image + LargeText: GetAnimeName(anime), // Would display while hovering over the large image State: state, - //SmallImage: anime.SmallCoverImage, // Image for the bottom left corner //SmallText: fmt.Sprintf("Episode: %s", anime.Ep.Title.English), // Text when hovering over the small image - Buttons: []*client.Button{ &client.Button{ Label: "View on AniList", // Button label @@ -55,5 +53,9 @@ func FormatTime(seconds int) string { hours := seconds / 3600 minutes := (seconds % 3600) / 60 remainingSeconds := seconds % 60 - return fmt.Sprintf("%d:%02d:%02d", hours, minutes, remainingSeconds) + + if hours > 0 { + return fmt.Sprintf("%d:%02d:%02d", hours, minutes, remainingSeconds) + } + return fmt.Sprintf("%d:%02d", minutes, remainingSeconds) } From c190c7f79323ef2c6e0ebdce22691d5ab587c10c Mon Sep 17 00:00:00 2001 From: Vedant Deshmukh <73630434+Vedant9500@users.noreply.github.com> Date: Wed, 18 Dec 2024 21:28:37 +0530 Subject: [PATCH 5/5] Delete .vscode/settings.json --- .vscode/settings.json | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index b242572..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "githubPullRequests.ignoredPullRequestBranches": [ - "main" - ] -} \ No newline at end of file