Files
scrapyard-cogworks/wiki/AutoRoom-Templates.md
T
kingston 26a0728e14 docs: move cog documentation into the wiki and stub the README
The root README carried the full ten cog manual while the wiki held the
authoritative pages. Point the repository at the wiki, keep only install and
catalog basics in the README, and remove the per cog documents that are now
folded into wiki source under wiki/.
2026-11-03 12:54:42 -06:00

4.1 KiB

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 <template> sets the message posted in a new room's text channel. It has access to mention, username and game. [p]autoroomset modify text disable turns the hint off.

The hint is posted once when the room is created, not on every join.

Legacy text channels

[p]autoroomset modify legacytext enable creates a text channel alongside each room, with the owner allowed to manage it and read its history. disable stops creating them.

[p]autoroomset modify legacytexttopic set <template> sets the topic of those channels, using the same variables. disable clears the topic setting.

The modern alternative is Discord's own text chat inside a voice channel. The legacy option exists for servers that still want a separate channel.

Length and validation

  • Rendered names are truncated to 100 characters after rendering.
  • A template error cancels the operation and reports the error.
  • Empty output is rejected by Discord as an invalid channel name, which surfaces as a failed channel edit.
  • Templates are validated when saved through modify name custom, so a syntax error is reported immediately rather than at creation time.

Examples

Game name with a fallback and a room number:

{{game}}{% if not game %}{{username}}'s hangout{% endif %}{% if dupenum > 1 %} #{{dupenum}}{% endif %}

Lowercased owner name with a fixed suffix:

{{username | lower}} room

Role-neutral hint:

Welcome {{mention}}. This room belongs to you until everyone leaves.

Implementation notes

The renderer is a purpose-built parser, not full Jinja2. It does not support loops, macros, includes, arithmetic, filters with arguments, or attribute access. The bundled test file pcx_template_test.py covers the supported subset, including nested conditionals, comparisons and the duplicate number.

An administrator writing a template that uses an unsupported feature sees a template error rather than silent output. Test a new format with [p]autoroomset modify name custom and create a room before applying it to a busy source.