Commit a57bac35a5
Unsigned
Layout: unified · split
internal/discord.go added +45
| @@ -0,0 +1,45 @@ | ||
| 1 | package internal | |
| 2 | ||
| 3 | import ( | |
| 4 | "fmt" | |
| 5 | "github.com/hugolgst/rich-go/client" | |
| 6 | ) | |
| 7 | ||
| 8 | func DiscordPresence(clientId string, anime Anime) error { | |
| 9 | err := client.Login(clientId) | |
| 10 | if err != nil { | |
| 11 | return err | |
| 12 | } | |
| 13 | ||
| 14 | err = client.SetActivity(client.Activity{ | |
| 15 | Details: fmt.Sprintf("%s", anime.Title.English), // Large text | |
| 16 | LargeImage: anime.CoverImage, | |
| 17 | LargeText: anime.Title.Romaji, // Would display while hovering over the large image | |
| 18 | State: fmt.Sprintf("\nEpisode %d - %d:%02d / %d:%02d", | |
| 19 | anime.Ep.Number, | |
| 20 | convertSecondsToMinutes(anime.Ep.Player.PlaybackTime), | |
| 21 | anime.Ep.Player.PlaybackTime % 60, | |
| 22 | convertSecondsToMinutes(anime.Ep.Duration), | |
| 23 | anime.Ep.Duration % 60), | |
| 24 | // SmallImage: anime.CoverImage, // Image would appear in the bottom left corner | |
| 25 | // SmallText: fmt.Sprintf("%s", anime.Ep.Title.English), // Would display while hovering over the small image | |
| 26 | Buttons: []*client.Button{ | |
| 27 | &client.Button{ | |
| 28 | Label: "View on AniList", // Button label | |
| 29 | Url: fmt.Sprintf("https://anilist.co/anime/%d", anime.AnilistId), // Button link | |
| 30 | }, | |
| 31 | &client.Button{ | |
| 32 | Label: "View on MAL", // Button label | |
| 33 | Url: fmt.Sprintf("https://myanimelist.net/anime/%d", anime.MalId), // Button link | |
| 34 | }, | |
| 35 | }, | |
| 36 | }) | |
| 37 | if err != nil { | |
| 38 | return err | |
| 39 | } | |
| 40 | return nil | |
| 41 | } | |
| 42 | ||
| 43 | func convertSecondsToMinutes(seconds int) int { | |
| 44 | return seconds / 60 | |
| 45 | } | |