# AlbumOfTheDay Posts the current album from a 1001 Albums Generator group into a Discord channel once a day, with an embed containing the album, group statistics, genres and streaming links. This cog replaces a GitHub Actions workflow that posted through a webhook. The equivalent work happens inside the bot, with per-guild settings and an internal scheduler. ## Requirements - A 1001 Albums Generator group and its API URL. - Outbound HTTPS access from the bot host. - Manage Server or a Red admin role for setup commands. The manual post command has no restriction. ## Setup 1. Open the group page. The public URL looks like `https://1001albumsgenerator.com/groups/`. 2. Build the API URL by inserting `/api/v1` before `/groups`: ``` https://1001albumsgenerator.com/api/v1/groups/ ``` 3. Configure the guild: ``` [p]aotd seturl https://1001albumsgenerator.com/api/v1/groups/ [p]aotd setchannel #album-of-the-day [p]aotd settime 8 0 ``` 4. Test immediately with `[p]aotd now`. `seturl` requires the URL to start with `https://` but performs no other validation. A wrong slug is reported by the API as a 404 when a post is attempted. ## Commands The group is `albumoftheday`, alias `aotd`, and it is guild only. | Command | Arguments | Permission | Behavior | |---|---|---|---| | `[p]aotd now` | none | Any member | Posts today's album in the current channel | | `[p]aotd seturl` | `` | Manage Server | Saves the API URL after an HTTPS check | | `[p]aotd setchannel` | `[channel]` | Manage Server | Sets the daily channel, defaulting to the current one | | `[p]aotd settime` | ` [minute]` | Manage Server | Sets the daily time in the configured timezone, 24 hour clock | | `[p]aotd settz` | `` | Manage Server | Sets the timezone, alias `settimezone` | | `[p]aotd settings` | none | Manage Server | Shows URL, channel, time, current local time and last posted date | | `[p]aotd clear` | none | Manage Server | Resets the guild configuration and stops daily posting | `settime` rejects hours outside 0-23 and minutes outside 0-59. `settz` validates the name against `zoneinfo.available_timezones()` and suggests `America/Chicago`, `America/New_York` or `Europe/London` on failure. `settings` resolves the channel mention when the channel still exists and computes the current local time in the configured zone. `clear` restores the defaults, which unset the URL and channel and therefore stop posting. ## Scheduling The scheduler is a `tasks.loop` with a one minute interval. It is started in `__init__`, restarted by `on_ready` if it is not running, and waits for Red to be ready before its first iteration. Each iteration: 1. Loads every guild's configuration. 2. Skips guilds without both an API URL and a channel ID. 3. Reads the timezone. An invalid stored value logs a warning and falls back to `America/Chicago`. 4. Compares the guild's local hour and minute with the configured values. Anything other than an exact match is skipped. 5. Skips when `last_posted` equals the local date, which prevents duplicates within one local day, including across reloads and restarts. 6. Resolves the guild and channel. A missing channel is logged and skipped. 7. Fetches, posts and stores the local date as `last_posted`. Because the match is exact and the loop runs once a minute, a bot that is offline for the scheduled minute does not post later. There is no catch-up. Two guilds can share a time without interfering, and each keeps its own last posted date. Daylight saving is handled by `zoneinfo`, so a time stays fixed in local terms year-round. ## Embed contents - Title: album name, artist, and the release date when present. - Description: a genre list with hyphens replaced by spaces and title cased, followed by links. - Links: Reviews from the group URL, Wikipedia, Spotify from `spotifyId`, Apple Music from `appleMusicId`. Missing links are omitted. - All-Time Favorite: the top entry of `highestRatedAlbums`, with name, artist and average rating out of 5. - Least Favorite: the top entry of `lowestRatedAlbums`. - Favorite Genre and Worst Genre: from `favoriteGenres` and `worstGenres`, with the rating. - Footer: number of generated albums, total votes, and group average. - Thumbnail: the first image URL. Empty lists produce readable fallbacks such as "No favorites yet" and "No favorite genre yet". ## API handling Requests use a 15 second total timeout. Failures produce a specific message: | Condition | Message | |---|---| | Non-200 response | "API returned status N. Check the API URL points to a valid group." | | Unparseable JSON | "API returned malformed JSON." | | Connection failure | "Could not connect to the API. Check the bot's internet connection and the API URL." | | Timeout | "API request timed out after 15 seconds." | | Other client error | "API request failed: ..." | | Missing `currentAlbum` | "API response missing 'currentAlbum'. Check the API URL points to a valid group." | `now` reports these to the channel. The scheduled post logs them at warning level and leaves `last_posted` unchanged. Since the loop only matches the configured minute once per day, a failed scheduled post is not retried until the next day. ## Limits - One post per guild per local day. - The bot must be online during the configured minute. - The embed content depends entirely on the third-party API shape. A change to that API results in a logged failure rather than a partial post. - The scheduled path catches `ValueError` and `discord.DiscordException`. Other exceptions inside the loop are contained by the task framework and logged by Red. ## Stored data Guild config under identifier `0xA1B00FDA`: | Key | Default | |---|---| | `api_url` | `null` | | `channel_id` | `null` | | `post_hour` | `8` | | `post_minute` | `0` | | `timezone` | `America/Chicago` | | `last_posted` | `null` | The group API URL is public and the API returns group statistics, so no Discord user data is sent anywhere.