From 901652a21115dcfaf827fc8d777649133333fed5 Mon Sep 17 00:00:00 2001 From: kingston Date: Tue, 3 Nov 2026 12:51:18 -0600 Subject: [PATCH] Document all ten cogs --- AlbumOfTheDay.md | 118 ++++++++++++++++++++++++++++ Assistant.md | 112 +++++++++++++++++++++++++++ AutoRoom-Commands.md | 134 ++++++++++++++++++++++++++++++++ AutoRoom-Overview.md | 152 ++++++++++++++++++++++++++++++++++++ AutoRoom-Templates.md | 105 +++++++++++++++++++++++++ Cog-Catalog.md | 34 ++++++++ Data-and-Privacy.md | 52 +++++++++++++ Deadman.md | 93 ++++++++++++++++++++++ Development.md | 94 +++++++++++++++++++++++ ImageGrab.md | 70 +++++++++++++++++ Installation.md | 78 +++++++++++++++++++ Local-Services.md | 92 ++++++++++++++++++++++ PlayitStatus.md | 77 +++++++++++++++++++ Renamer.md | 64 ++++++++++++++++ Transcribe.md | 154 +++++++++++++++++++++++++++++++++++++ Troubleshooting.md | 103 +++++++++++++++++++++++++ TtsToy-Accessibility.md | 102 ++++++++++++++++++++++++ TtsToy-Commands.md | 142 ++++++++++++++++++++++++++++++++++ TtsToy-Overview.md | 146 +++++++++++++++++++++++++++++++++++ TtsToy-Servers.md | 166 ++++++++++++++++++++++++++++++++++++++++ YTAudio.md | 120 +++++++++++++++++++++++++++++ _Sidebar.md | 27 +++++++ 22 files changed, 2235 insertions(+) create mode 100644 AlbumOfTheDay.md create mode 100644 Assistant.md create mode 100644 AutoRoom-Commands.md create mode 100644 AutoRoom-Overview.md create mode 100644 AutoRoom-Templates.md create mode 100644 Cog-Catalog.md create mode 100644 Data-and-Privacy.md create mode 100644 Deadman.md create mode 100644 Development.md create mode 100644 ImageGrab.md create mode 100644 Installation.md create mode 100644 Local-Services.md create mode 100644 PlayitStatus.md create mode 100644 Renamer.md create mode 100644 Transcribe.md create mode 100644 Troubleshooting.md create mode 100644 TtsToy-Accessibility.md create mode 100644 TtsToy-Commands.md create mode 100644 TtsToy-Overview.md create mode 100644 TtsToy-Servers.md create mode 100644 YTAudio.md create mode 100644 _Sidebar.md diff --git a/AlbumOfTheDay.md b/AlbumOfTheDay.md new file mode 100644 index 0000000..0446061 --- /dev/null +++ b/AlbumOfTheDay.md @@ -0,0 +1,118 @@ +# 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. diff --git a/Assistant.md b/Assistant.md new file mode 100644 index 0000000..e1834aa --- /dev/null +++ b/Assistant.md @@ -0,0 +1,112 @@ +# Assistant + +A chat assistant that answers in a dedicated channel or when the bot is mentioned. It talks to any OpenAI-compatible chat completions API and defaults to a local Ollama server. + +## Requirements + +- An OpenAI-compatible backend. The default is `http://127.0.0.1:11434/v1`, which is Ollama's OpenAI-compatible endpoint. +- For any non-local backend, an API key. +- No Python package beyond `aiohttp`, which Red provides. + +## Backend configuration + +Global config: + +| Key | Default | Set by | +|---|---|---| +| `base_url` | `http://127.0.0.1:11434/v1` | `[p]assistant baseurl [url]` | +| `api_key` | `null` | `[p]assistant setkey` | + +`setkey` posts a button. Pressing it opens a modal, and the submitted value is written to global config. The key is never echoed back and is stored in plain text. + +`baseurl` with no argument resets the URL to the local default. A trailing slash is stripped. A URL containing `127.0.0.1` or `localhost` is reported as local and needs no key; any other URL is reported as remote and requires one. + +The local check is a substring test, so a URL such as `http://127.0.0.1.example.com/v1` counts as local even though it is remote. + +Per-guild config: + +| Key | Default | +|---|---| +| `enabled` | `true` | +| `chat_channel` | `null` | +| `model` | `llama3.2:3b-instruct-q4_K_M` | +| `vision_model` | `llama3.2:3b-instruct-q4_K_M` | +| `temperature` | `0.7` | +| `system_prompt` | A short instruction to be witty, playful and brief | +| `question_mode` | `false` | +| `max_tokens` | `null` (unlimited) | +| `reasoning_effort` | `null` (model default) | + +## Commands + +The group is `assistant`, guild only. Running it bare sends command help. + +| Command | Arguments | Permission | Behavior | +|---|---|---|---| +| `[p]assistant setkey` | none | Bot owner | Button and modal to store the API key | +| `[p]assistant baseurl` | `[url]` | Bot owner | Show or set the backend, no argument resets to local | +| `[p]assistant toggle` | none | Any member | Enables or disables the assistant for the guild | +| `[p]assistant channel` | `[channel]` | Any member | Sets or clears the dedicated chat channel | +| `[p]assistant model` | `` | Any member | Sets the model id | +| `[p]assistant visionmodel` | `[model]` | Any member | Shows or sets the vision model id | +| `[p]assistant models` | none | Any member | Lists models from the backend with reference prices | +| `[p]assistant temp` | `` | Any member | Sets temperature, 0.0 to 2.0 | +| `[p]assistant maxlength` | `[tokens]` | Any member | Sets or clears the response token cap | +| `[p]assistant reasoning` | `[level]` | Any member | Sets or clears reasoning effort | +| `[p]assistant system` | `` | Any member | Replaces the system prompt | +| `[p]assistant showprompt` | none | Manage Server | Prints the system prompt in a code block | +| `[p]assistant question` | none | Any member | Toggles question mode | +| `[p]assistant clear` | none | Any member | Deletes the in-memory history for the current channel | +| `[p]assistant settings` | none | Any member | Posts an embed of the current settings | + +The permission split is deliberate in only two places. `setkey` and `baseurl` are owner only because they control credentials and cost. `showprompt` is admin only because it may contain internal instructions. Everything else, including the model, temperature, token cap, system prompt and chat channel, can be changed by any member who can run commands. + +`reasoning` accepts `none`, `minimal`, `low`, `medium`, `high`, case-insensitively. An invalid value lists the options. No argument clears the setting. + +`maxlength` rejects values below 1. No argument clears the cap. + +`models` requires a key for remote backends and reports "API key not set" otherwise. It calls `GET /models`, filters out known embedding and reranker ids, attaches a price table in EUR per million tokens for known ids, sorts by output price and then id, marks the current model, and sends an embed. Unknown ids are listed last with "pricing unknown". The price table is hardcoded for one provider and does not reflect the local Ollama catalogue. + +## Message flow + +The listener ignores bots and direct messages, then requires the guild to be enabled and a key to be present when the backend is remote. It responds only when the message is in the configured chat channel or mentions the bot. Mention tokens are stripped from the content. + +The listener then collects image URLs from the invoking message's attachments and from the replied-to message's attachments and embeds. If there are any images, it replies "Images not supported at this time.", empties the list, and continues with the remaining text. If there is no text, it stops. + +Question mode requires the text to end with a question mark. A mention that fails this test gets a reply explaining the rule. A message in the chat channel that fails is ignored silently. + +The bot shows a typing indicator, calls the backend, and replies to the original message. A `None` reply produces "No response from the assistant." An empty string produces a note that the response was empty. Replies longer than 2000 characters are split into consecutive replies, each under the limit, in order. + +## Request construction + +The request body is: + +```json +{ + "model": "", + "messages": [{"role": "system", "content": ""}, ...history], + "temperature": 0.7 +} +``` + +`max_tokens` is added when configured. `reasoning_effort` is added when configured. An `Authorization: Bearer` header is added whenever a key exists, including for local backends. + +History is keyed by guild and channel and held in a dictionary. Each request sends the system prompt plus the last 20 entries. After a successful reply the history is trimmed to the last 20 entries once it exceeds 40, so the window grows to 40 and drops back to 20. History is lost on reload and is never written to disk. + +The HTTP timeout is 120 seconds total. A non-200 response returns "API error : ". Any exception returns "Request failed: ". A response without `choices[0].message` returns "Unexpected API response." + +## Vision + +Vision is not available in the current code. The image collection code and the multimodal request branch exist, but the handler clears the image list before calling the API, so the branch for image content is unreachable. The `visionmodel` command and setting have no effect. + +## Limits and failure modes + +- No cooldown and no concurrency limit. Every qualifying message triggers an API call, and a busy channel produces one call per message. +- Replies are posted as separate messages when chunked, which can trigger Discord rate limits during long outputs. +- A local backend that is down produces a request failure reply for each message. +- `[p]assistant clear` affects only the channel where it runs. +- The guild `enabled` flag defaults to true, so a freshly loaded cog starts answering in any channel where the bot is mentioned. + +## Stored data + +Global config under identifier `987654321` holds the API key and base URL. Guild config holds the keys listed above. Chat history exists only in memory. `red_delete_data_for_user` is not implemented for this cog, so deleting a user's Red data does not remove their prompts from a running history. diff --git a/AutoRoom-Commands.md b/AutoRoom-Commands.md new file mode 100644 index 0000000..335ac84 --- /dev/null +++ b/AutoRoom-Commands.md @@ -0,0 +1,134 @@ +# AutoRoom Commands + +Two command groups: `autoroom` for room owners and members, and `autoroomset` for server administrators. Both are guild only. + +## Member and owner commands + +Group: `[p]autoroom`, alias `[p]vc`. + +These commands operate on the room the invoking member is currently in, or the room they own. They do not require a permission check beyond being in the room. The cog verifies ownership and replies with a temporary error when the member is not allowed. + +| Command | Aliases | Arguments | Description | +|---|---|---|---| +| `[p]autoroom settings` | `about`, `info` | none | Shows room settings and current access overwrites | +| `[p]autoroom name` | none | `` | Renames the room, capped at 100 characters | +| `[p]autoroom bitrate` | `kbps` | `` | Sets bitrate, clamped to 8 and the guild limit | +| `[p]autoroom users` | `userlimit` | `` | Sets the user limit, clamped to 0 through 99 | +| `[p]autoroom claim` | none | none | Takes ownership when the previous owner has left | +| `[p]autoroom public` | none | none | Makes the room visible and joinable | +| `[p]autoroom locked` | none | none | Makes the room visible but not joinable | +| `[p]autoroom private` | none | none | Hides the room from everyone not allowed | +| `[p]autoroom allow` | `add` | `` | Grants access to one or more members or roles | +| `[p]autoroom deny` | `ban`, `block` | `` | Revokes access and disconnects affected members | + +### settings + +Reports the owner, or "Server Managed" when no owner is recorded. Then the access type derived from the source's member roles, the bitrate in kbps, and the channel's age. A second section lists allowed and denied members and roles taken from the channel's overwrites. Anyone in the room can run it, including members who do not own it. + +### name + +Rate limited by a per-channel bucket of two changes per 604 seconds, where the extra four seconds absorb Discord's own rename handling. Hitting the limit produces a message with the wait time and suggests renaming directly in Discord. When the server requires 2FA for moderation, the message notes that the member needs 2FA enabled to rename the channel manually. + +The command deletes the invoking message after a short delay on success. + +### bitrate and users + +`bitrate` converts kbps to bits per second and clamps between 8000 and the guild's `bitrate_limit`. `users` clamps between 0 and 99, where 0 removes the limit. Both confirm with a check mark reaction and delete the command message after five seconds. + +### claim + +Claiming is refused when the current owner is still in the room. Otherwise a two minute per-channel cooldown applies. Administrators, moderators, configured admin and mod roles, and the guild owner bypass both restrictions. + +On success the old owner's overwrites are reset to the source's default allow set and the new owner receives the source's owner permissions. The linked legacy text channel, when present, is updated the same way. The channel's stored `owner` is replaced. + +### allow and deny + +`allow` accepts several members or roles in one call. `deny` accepts one, disconnects any member in the room who can no longer connect, and records the denial. + +Both require the bot to have Manage Roles on the room. The source must still exist, otherwise the command explains that the room can no longer be modified. + +Denying a role removes access for everyone holding it. When the source uses member roles, those roles may still grant connect permission, so the deny can appear to have no effect. + +## Administrator commands + +Group: `[p]autoroomset`, requiring Manage Server or a Red admin role. + +| Command | Aliases | Arguments | Description | +|---|---|---|---| +| `[p]autoroomset settings` | none | none | Shows server access settings and every configured source | +| `[p]autoroomset permissions` | `perms` | none | Checks the bot's permissions for each source | +| `[p]autoroomset create` | `enable`, `add` | ` ` | Creates or enables a source with an interactive setup | +| `[p]autoroomset disable` | `delete`, `del` | `` | Removes a source and stops room creation | +| `[p]autoroomset access` | none | none | Parent group for access settings | + +### settings + +Prints a server section with admin access, moderator access and bot roles, then a section for each source showing its category, room type, name format and text settings. Source names are resolved to channel mentions where possible. + +### permissions + +Compares required permissions with the bot's effective permissions on the source and destination, and reports missing entries with a hint to grant them and rerun the command. This is the first command to run when room creation fails. + +### create + +Interactive. Asks for the source channel if not supplied, checks permissions, then asks for the destination category and room type. It can create a new source channel or adopt an existing one. On completion the source is stored in the custom `AUTOROOM_SOURCE` group with default settings. + +### disable + +Deletes the source configuration. Existing rooms are not deleted immediately; the cleanup task removes them once their source is gone. + +### access + +| Command | Behavior | +|---|---| +| `[p]autoroomset access admin` | Toggles administrator access to every room | +| `[p]autoroomset access mod` | Toggles moderator access to every room | +| `[p]autoroomset access bot add ` | Adds a role that may enter every room | +| `[p]autoroomset access bot remove ` | Removes such a role | + +Administrator and moderator checks use Red's configured roles for the guild, not Discord's permission flags alone. + +### modify + +Parent group for per-source settings. Each subcommand takes the source channel when a guild has more than one. + +| Subcommand | Purpose | +|---|---| +| `[p]autoroomset modify category` | Changes the destination category | +| `[p]autoroomset modify type` | Sets the default room type: `public`, `locked`, `private` or `server` | +| `[p]autoroomset modify name` | Chooses the name format: `username`, `game` or `custom`, and accepts a custom template | +| `[p]autoroomset modify text` | Sets the hint message posted in a new room's text channel, or disables it | +| `[p]autoroomset modify legacytext` | Enables or disables a legacy per-room text channel | +| `[p]autoroomset modify legacytexttopic` | Sets or disables the topic on that legacy text channel | +| `[p]autoroomset modify defaults` | Resets source settings to their defaults | +| `[p]autoroomset specialperms` | Parent group for owner permission toggles | + +`specialperms ownermodify` controls whether owners may change the room's channel settings. `specialperms sendmessage` controls whether owners and members may send messages in the linked text channel. Both are stored per source as `perm_owner_manage_channels` and `perm_send_messages`. + +### modify type server + +The `server` type behaves like a public room, with the server as the owner instead of the creating member. No owner record is written, the creating member receives no owner permissions, and the room cannot be modified through the owner commands. It is the fourth option and can only be set as a source default by an administrator. + +## Cooldowns + +| Action | Limit | Scope | +|---|---|---| +| Room creation | 2 per 60 seconds | Member | +| Creation warning message | 1 per 3600 seconds | Member | +| Rename through command | 2 per 604 seconds | Channel | +| Ownership claim | 1 per 120 seconds | Channel | + +Cooldowns are in memory and reset when the cog reloads. + +## Failure messages + +Messages are sent as temporary errors and often delete themselves. + +| Situation | Message | +|---|---| +| Command used outside the author's room | A request to use the command in their own AutoRoom | +| Source deleted | The source no longer exists, so the room cannot be modified | +| Missing Manage Roles | The bot lacks the permission and the message asks the member to tell staff | +| Claim while owner present | Ownership can only be claimed after the owner leaves | +| Claim cooldown | Wait time before claiming, in case the previous owner returns | +| Rename cooldown | The limit, the window, and the remaining wait | diff --git a/AutoRoom-Overview.md b/AutoRoom-Overview.md new file mode 100644 index 0000000..f02577d --- /dev/null +++ b/AutoRoom-Overview.md @@ -0,0 +1,152 @@ +# AutoRoom Overview + +AutoRoom creates a temporary voice channel for a member who joins a designated source channel, gives that member control of the new channel, and deletes it when the last person leaves. + +The cog is PhasecoreX's AutoRoom version 4.0.7 with local modifications. Its command names, aliases and general design follow that upstream project. The notes below describe the code in this repository. + +## Concepts + +| Term | Meaning | +|---|---| +| AutoRoom Source | A voice channel marked as a source. Joining it creates a room | +| AutoRoom | The temporary voice channel created for a member | +| AutoRoom Owner | The member who owns the room, normally the member who triggered creation | +| Member roles | The roles allowed to connect to a source, which decide who can use it | +| Destination category | The category new rooms are created in | + +A guild can have several sources, each with its own category, room type, name format and text settings. + +## Requirements + +- Manage Channels, Manage Roles, Move Members, View Channel, Connect and Send Messages in the relevant channels. +- A voice channel to use as the source and a category for the new rooms. +- `func-timeout` and `jinja2` from the manifest. + +`[p]autoroomset permissions` checks the bot's permissions against a source and reports what is missing. + +## Setup + +``` +[p]autoroomset create +``` + +The command walks through the setup with prompts, offering to create a source, choose a room type, and set a name format. It warns when permissions are missing. After setup, join the source to confirm a room is created and you are moved into it. + +Further changes are made with `[p]autoroomset modify`, which has subcommands for the category, room type, name format, text channel behaviour and defaults. `[p]autoroomset settings` shows the current server and source configuration. + +## Room types + +A room's type is stored per source and can be changed per room by its owner. + +| Type | Behavior | +|---|---| +| Public | Everyone who can see the category can see and join | +| Locked | Everyone who can see the category can see the room, nobody can join unless allowed | +| Private | Nobody can see or join unless allowed | + +`[p]autoroom public`, `locked` and `private` switch between these. `[p]autoroom allow` and `deny` add member or role overwrites that survive type changes. + +## Member roles + +Member roles are not a stored list. They are derived from the source channel's permission overwrites: a role counts as a member role when it is allowed to connect to the source while `@everyone` is denied connect. This behaviour comes from schema migration 6, which removed the old stored `member_role` setting. + +Two consequences: + +- Roles can be changed without a command, by editing the source channel's permissions in Discord. +- A source that allows `@everyone` to connect has no member roles, and every member can create rooms from it. + +Denying roles in a room that uses member roles can produce unexpected results, because allowed member roles may grant access back. + +## Creating and deleting rooms + +1. A member joins a source channel. +2. The cog checks the member's create cooldown: two creations per 60 seconds per member. A warning is shown at most once per hour. +3. A new voice channel is created in the source's destination category, named from the configured template. +4. The member is moved into it and becomes the owner. The owner gets the permissions configured for owners, which by default include managing the channel, moving members and managing messages in the linked text channel. +5. When the last member leaves, the channel is deleted. A channel with a bot inside stays alive, and so does one with a member who cannot be moved. + +An owner who leaves and returns keeps ownership while the room exists. `[p]autoroom claim` transfers ownership when the owner has left, subject to a two minute cooldown per channel and the server access rules. + +## Deletion and cleanup + +Rooms are deleted when the last member leaves. A bot that remains in the channel counts as a member, so it keeps the room alive. + +On load, a cleanup task walks every stored room record and deletes the record when the channel no longer exists in Discord. This clears entries after a room was deleted by hand or lost to a reset. The task does not delete live channels. + +## Server access overrides + +`[p]autoroomset access` controls who can enter rooms regardless of the room's type. + +| Setting | Default | Command | +|---|---|---| +| Admin access to all rooms | On | `[p]autoroomset access admin` | +| Moderator access to all rooms | Off | `[p]autoroomset access mod` | +| Bot roles allowed in all rooms | Empty | `[p]autoroomset access bot add` and `remove` | + +Admin and moderator access uses Red's role definitions, so a server's configured admin and mod roles apply. + +## AutoRoom Source permissions + +The bot needs these on a source: + +- View Channel +- Connect +- Move Members + +On the destination category it needs: + +- View Channel +- Connect +- Send Messages +- Manage Channels +- Manage Messages +- Move Members + +`[p]autoroomset permissions` performs the check and reports missing entries. + +## Limits + +- Channel names are capped at 100 characters by the cog, and Discord enforces its own limit. +- Owners can rename through the `name` command twice per roughly ten minutes per channel, with a four second allowance for Discord's own rename. The error message suggests renaming the channel directly in Discord instead. +- Bitrate is clamped between 8 kbps and the guild's boost dependent limit. +- User limit is clamped between 0 and 99, where 0 means no limit. +- Room state lives in Discord channels plus config. Deleting a room's channel manually leaves its config entry until the next cleanup, which clears missing channels. + +## Stored data + +Global config under identifier `1224364860` holds `schema_version`. + +Guild config: + +| Key | Default | +|---|---| +| `admin_access` | `true` | +| `mod_access` | `false` | +| `bot_access` | `[]` | + +Custom group `AUTOROOM_SOURCE`, keyed by guild and source channel: + +| Key | Default | +|---|---| +| `dest_category_id` | `null` | +| `room_type` | `public` | +| `legacy_text_channel` | `false` | +| `text_channel_hint` | `null` | +| `text_channel_topic` | empty | +| `channel_name_type` | `username` | +| `channel_name_format` | empty | +| `perm_owner_manage_channels` | `true` | +| `perm_send_messages` | `true` | + +Channel config for each created room: + +| Key | Meaning | +|---|---| +| `source_channel` | ID of the source that created it | +| `owner` | Member ID of the owner, or null | +| `associated_text_channel` | ID of the linked text channel, when applicable | +| `denied` | Stored deny list | + +`red_delete_data_for_user` does nothing, so deleting a user's data does not remove ownership records from their rooms. + +Next: [AutoRoom Commands](AutoRoom-Commands) and [AutoRoom Templates](AutoRoom-Templates). diff --git a/AutoRoom-Templates.md b/AutoRoom-Templates.md new file mode 100644 index 0000000..6371d55 --- /dev/null +++ b/AutoRoom-Templates.md @@ -0,0 +1,105 @@ +# AutoRoom Templates + +Room names and text channel hints are rendered with a small Jinja subset implemented in `pcx_template.py`. It supports variable substitution, `if`, `elif`, `else` and `endif`, comparison operators, and two filters. + +## Variables + +| Variable | Available in | Value | +|---|---|---| +| `username` | Name and hint | The owner's display name | +| `game` | Name and hint | The game the owner is playing, or an empty string | +| `dupenum` | Name | A counter starting at 1, incremented when a generated name already exists | +| `mention` | Hint only | The owner's mention | + +`game` is read at creation time. Starting or stopping a game later does not rename the room. + +`dupenum` is computed by generating the name, checking for an existing channel with that name in the category, and incrementing until the name is free. A template that does not include `dupenum` therefore produces a duplicate name, and Discord allows duplicate channel names, so rooms can share a name. + +## Default templates + +The `username` format: + +``` +{{username}}'s Room{% if dupenum > 1 %} ({{dupenum}}){% endif %} +``` + +The `game` format: + +``` +{{game}}{% if not game %}{{username}}'s Room{% endif %}{% if dupenum > 1 %} ({{dupenum}}){% endif %} +``` + +Both append the duplicate number only from the second duplicate onward, so the first room has no suffix. + +## Conditionals + +The template engine accepts: + +``` +{% if game %}...{% elif username %}...{% else %}...{% endif %} +``` + +Conditions can compare a variable with a literal using `==`, `!=`, `>`, `<`, `>=` and `<=`, or test a variable for truth with `if game` and `if not game`. Undefined variables are treated as empty, so they are falsy. + +Whitespace inside tags is ignored. Tags may appear inline with text. + +## Filters + +``` +{{username | lower}} +{{game | upper}} +``` + +| Filter | Effect | +|---|---| +| `lower` | Lowercases the value | +| `upper` | Uppercases the value | + +Filters are applied before insertion. Unknown filters raise a template error, which is reported to the administrator and the operation is cancelled. + +## Hint message + +`[p]autoroomset modify text set