Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main #20

Merged
merged 7 commits into from
Dec 18, 2024
Merged

Main #20

Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions internal/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Loading