feat(help): vertical category posters on /help category pages

This commit is contained in:
Loki 2026-10-21 15:44:29 +02:00
parent ee43b32ed8
commit b7d368e4fe
Signed by: boba
GPG key ID: 253067914055423B
11 changed files with 146 additions and 10 deletions

View file

@ -33,6 +33,30 @@ banner("verify", "VERIFY", "react to unlock the server", "LOKI DEV / ACCESS")
banner("welcome", "WELCOME", "good to have you here", "LOKI DEV / COMMUNITY")
banner("help", "COMMANDS", "everything the bot can do", "LOKI DEV / HELP")
def poster(name, title, sub, tag):
"""Vertical 3:4 poster for help category pages; title size shrinks to fit the width."""
w, h = 900, 1200
size = min(150, int(760 / (0.66 * len(title))))
defs = DEFS.replace('"W"', f'"{w}"').replace('"H"', f'"{h}"').replace('cx="82%" cy="50%"', 'cx="50%" cy="36%"')
svg = f"""<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {w} {h}" width="{w}" height="{h}">
{defs}
<rect width="{w}" height="{h}" fill="#100f0e"/>
<rect width="{w}" height="{h}" fill="url(#dots)" mask="url(#halo)" opacity="0.9"/>
<g transform="translate(258 180) scale(8)">{MARK}</g>
<text x="70" y="860" font-family="'JetBrains Mono','DejaVu Sans Mono',monospace" font-size="26" letter-spacing="4" fill="#ff793f">{tag}</text>
<text x="64" y="{880 + size}" font-family="Inter,'Helvetica Neue',Arial,sans-serif" font-weight="800" font-size="{size}" letter-spacing="-4" fill="#f2ede5">{title}</text>
<text x="70" y="1100" font-family="'JetBrains Mono','DejaVu Sans Mono',monospace" font-size="28" fill="#b8afa5">{sub}</text>
<rect x="70" y="1130" width="160" height="6" fill="#ff793f"/>
</svg>"""
open(f"{name}.svg", "w").write(svg)
subprocess.run(["rsvg-convert", "-w", str(w), f"{name}.svg", "-o", f"{name}.png"], check=True)
poster("help-information", "INFORMATION", "server &amp; bot info", "LOKI DEV / INFORMATION")
poster("help-moderation", "MODERATION", "mod tools - requires perms", "LOKI DEV / MODERATION")
poster("help-tickets", "TICKETS", "support tickets &amp; blacklist", "LOKI DEV / TICKETS")
poster("help-utility", "UTILITY", "polls, reminders, blog", "LOKI DEV / UTILITY")
avatar = f"""<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="1024" height="1024">
<defs>
<linearGradient id="bg" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#ff9a5d"/><stop offset="1" stop-color="#ff5a1f"/></linearGradient>

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 KiB

View file

@ -0,0 +1,18 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 900 1200" width="900" height="1200">
<defs>
<linearGradient id="face" x1="0" y1="0" x2="0.4" y2="1"><stop offset="0" stop-color="#ffb27a"/><stop offset="1" stop-color="#ff5d1f"/></linearGradient>
<mask id="cut"><rect width="48" height="48" fill="#fff"/><path d="M24 2V46" stroke="#000" stroke-width="3"/>
<path d="M16 22l8 4 8-4" stroke="#000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/></mask>
<radialGradient id="fade" cx="50%" cy="36%" r="55%"><stop offset="0" stop-color="#fff"/><stop offset="0.6" stop-color="#fff" stop-opacity="0.35"/><stop offset="1" stop-color="#000"/></radialGradient>
<mask id="halo"><rect width="900" height="1200" fill="url(#fade)"/></mask>
<pattern id="dots" width="8" height="8" patternUnits="userSpaceOnUse"><rect x="1" y="1" width="4" height="4" fill="#ff6a2b"/><rect x="5" y="5" width="2" height="2" fill="#ff6a2b"/></pattern>
</defs>
<rect width="900" height="1200" fill="#100f0e"/>
<rect width="900" height="1200" fill="url(#dots)" mask="url(#halo)" opacity="0.9"/>
<g transform="translate(258 180) scale(8)"><path d="M24 4l18 20-18 20L6 24z" fill="url(#face)" mask="url(#cut)"/></g>
<text x="70" y="860" font-family="'JetBrains Mono','DejaVu Sans Mono',monospace" font-size="26" letter-spacing="4" fill="#ff793f">LOKI DEV / INFORMATION</text>
<text x="64" y="984" font-family="Inter,'Helvetica Neue',Arial,sans-serif" font-weight="800" font-size="104" letter-spacing="-4" fill="#f2ede5">INFORMATION</text>
<text x="70" y="1100" font-family="'JetBrains Mono','DejaVu Sans Mono',monospace" font-size="28" fill="#b8afa5">server &amp; bot info</text>
<rect x="70" y="1130" width="160" height="6" fill="#ff793f"/>
</svg>

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 KiB

View file

@ -0,0 +1,18 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 900 1200" width="900" height="1200">
<defs>
<linearGradient id="face" x1="0" y1="0" x2="0.4" y2="1"><stop offset="0" stop-color="#ffb27a"/><stop offset="1" stop-color="#ff5d1f"/></linearGradient>
<mask id="cut"><rect width="48" height="48" fill="#fff"/><path d="M24 2V46" stroke="#000" stroke-width="3"/>
<path d="M16 22l8 4 8-4" stroke="#000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/></mask>
<radialGradient id="fade" cx="50%" cy="36%" r="55%"><stop offset="0" stop-color="#fff"/><stop offset="0.6" stop-color="#fff" stop-opacity="0.35"/><stop offset="1" stop-color="#000"/></radialGradient>
<mask id="halo"><rect width="900" height="1200" fill="url(#fade)"/></mask>
<pattern id="dots" width="8" height="8" patternUnits="userSpaceOnUse"><rect x="1" y="1" width="4" height="4" fill="#ff6a2b"/><rect x="5" y="5" width="2" height="2" fill="#ff6a2b"/></pattern>
</defs>
<rect width="900" height="1200" fill="#100f0e"/>
<rect width="900" height="1200" fill="url(#dots)" mask="url(#halo)" opacity="0.9"/>
<g transform="translate(258 180) scale(8)"><path d="M24 4l18 20-18 20L6 24z" fill="url(#face)" mask="url(#cut)"/></g>
<text x="70" y="860" font-family="'JetBrains Mono','DejaVu Sans Mono',monospace" font-size="26" letter-spacing="4" fill="#ff793f">LOKI DEV / MODERATION</text>
<text x="64" y="995" font-family="Inter,'Helvetica Neue',Arial,sans-serif" font-weight="800" font-size="115" letter-spacing="-4" fill="#f2ede5">MODERATION</text>
<text x="70" y="1100" font-family="'JetBrains Mono','DejaVu Sans Mono',monospace" font-size="28" fill="#b8afa5">mod tools - requires perms</text>
<rect x="70" y="1130" width="160" height="6" fill="#ff793f"/>
</svg>

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 215 KiB

View file

@ -0,0 +1,18 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 900 1200" width="900" height="1200">
<defs>
<linearGradient id="face" x1="0" y1="0" x2="0.4" y2="1"><stop offset="0" stop-color="#ffb27a"/><stop offset="1" stop-color="#ff5d1f"/></linearGradient>
<mask id="cut"><rect width="48" height="48" fill="#fff"/><path d="M24 2V46" stroke="#000" stroke-width="3"/>
<path d="M16 22l8 4 8-4" stroke="#000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/></mask>
<radialGradient id="fade" cx="50%" cy="36%" r="55%"><stop offset="0" stop-color="#fff"/><stop offset="0.6" stop-color="#fff" stop-opacity="0.35"/><stop offset="1" stop-color="#000"/></radialGradient>
<mask id="halo"><rect width="900" height="1200" fill="url(#fade)"/></mask>
<pattern id="dots" width="8" height="8" patternUnits="userSpaceOnUse"><rect x="1" y="1" width="4" height="4" fill="#ff6a2b"/><rect x="5" y="5" width="2" height="2" fill="#ff6a2b"/></pattern>
</defs>
<rect width="900" height="1200" fill="#100f0e"/>
<rect width="900" height="1200" fill="url(#dots)" mask="url(#halo)" opacity="0.9"/>
<g transform="translate(258 180) scale(8)"><path d="M24 4l18 20-18 20L6 24z" fill="url(#face)" mask="url(#cut)"/></g>
<text x="70" y="860" font-family="'JetBrains Mono','DejaVu Sans Mono',monospace" font-size="26" letter-spacing="4" fill="#ff793f">LOKI DEV / TICKETS</text>
<text x="64" y="1030" font-family="Inter,'Helvetica Neue',Arial,sans-serif" font-weight="800" font-size="150" letter-spacing="-4" fill="#f2ede5">TICKETS</text>
<text x="70" y="1100" font-family="'JetBrains Mono','DejaVu Sans Mono',monospace" font-size="28" fill="#b8afa5">support tickets &amp; blacklist</text>
<rect x="70" y="1130" width="160" height="6" fill="#ff793f"/>
</svg>

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 KiB

View file

@ -0,0 +1,18 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 900 1200" width="900" height="1200">
<defs>
<linearGradient id="face" x1="0" y1="0" x2="0.4" y2="1"><stop offset="0" stop-color="#ffb27a"/><stop offset="1" stop-color="#ff5d1f"/></linearGradient>
<mask id="cut"><rect width="48" height="48" fill="#fff"/><path d="M24 2V46" stroke="#000" stroke-width="3"/>
<path d="M16 22l8 4 8-4" stroke="#000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/></mask>
<radialGradient id="fade" cx="50%" cy="36%" r="55%"><stop offset="0" stop-color="#fff"/><stop offset="0.6" stop-color="#fff" stop-opacity="0.35"/><stop offset="1" stop-color="#000"/></radialGradient>
<mask id="halo"><rect width="900" height="1200" fill="url(#fade)"/></mask>
<pattern id="dots" width="8" height="8" patternUnits="userSpaceOnUse"><rect x="1" y="1" width="4" height="4" fill="#ff6a2b"/><rect x="5" y="5" width="2" height="2" fill="#ff6a2b"/></pattern>
</defs>
<rect width="900" height="1200" fill="#100f0e"/>
<rect width="900" height="1200" fill="url(#dots)" mask="url(#halo)" opacity="0.9"/>
<g transform="translate(258 180) scale(8)"><path d="M24 4l18 20-18 20L6 24z" fill="url(#face)" mask="url(#cut)"/></g>
<text x="70" y="860" font-family="'JetBrains Mono','DejaVu Sans Mono',monospace" font-size="26" letter-spacing="4" fill="#ff793f">LOKI DEV / UTILITY</text>
<text x="64" y="1030" font-family="Inter,'Helvetica Neue',Arial,sans-serif" font-weight="800" font-size="150" letter-spacing="-4" fill="#f2ede5">UTILITY</text>
<text x="70" y="1100" font-family="'JetBrains Mono','DejaVu Sans Mono',monospace" font-size="28" fill="#b8afa5">polls, reminders, blog</text>
<rect x="70" y="1130" width="160" height="6" fill="#ff793f"/>
</svg>

After

Width:  |  Height:  |  Size: 1.7 KiB

View file

@ -64,7 +64,7 @@ fn build_category_embed(cat: &str, requester: &str) -> CreateEmbed {
desc.push_str(&format!("**`{usage}`**\n-# {d}\n\n"));
}
}
CreateEmbed::new()
let mut e = CreateEmbed::new()
.author(CreateEmbedAuthor::new(format!("LOKI DEV · {}", cat.to_uppercase())))
.title(format!("{} {}", c.emoji, cat))
.description(desc)
@ -72,7 +72,11 @@ fn build_category_embed(cat: &str, requester: &str) -> CreateEmbed {
.footer(CreateEmbedFooter::new(format!(
"{} commands · requested by {requester}",
cmds.len()
)))
)));
if let Some(poster) = brand::Banner::for_category(cat) {
e = e.image(poster.url());
}
e
}
fn build_main_embed(
@ -122,11 +126,9 @@ pub fn components() -> Vec<CreateActionRow> {
/// Handles `help:category` select. Edits the original help message.
pub async fn on_select(ctx: Context, interaction: ComponentInteraction) {
// UpdateMessage always replaces attachments, so the overview re-uploads its banner;
// category pages carry no image and simply drop it.
let home = interaction.data.custom_id == "help:home";
let embed = match interaction.data.custom_id.as_str() {
"help:home" => main_embed("!", &interaction.user.name, None),
// UpdateMessage always replaces attachments, so every page re-uploads its own image.
let (embed, image) = match interaction.data.custom_id.as_str() {
"help:home" => (main_embed("!", &interaction.user.name, None), Some(brand::Banner::Help)),
"help:category" => {
let value = match &interaction.data.kind {
ComponentInteractionDataKind::StringSelect { values } => {
@ -135,15 +137,15 @@ pub async fn on_select(ctx: Context, interaction: ComponentInteraction) {
_ => return,
};
let Some(cat) = value.strip_prefix("category:") else { return };
build_category_embed(cat, &interaction.user.name)
(build_category_embed(cat, &interaction.user.name), brand::Banner::for_category(cat))
}
_ => return,
};
let mut msg = serenity::all::CreateInteractionResponseMessage::new()
.embed(embed)
.components(components());
if home {
msg = msg.add_file(brand::Banner::Help.attachment());
if let Some(image) = image {
msg = msg.add_file(image.attachment());
}
let _ =
interaction.create_response(&ctx.http, CreateInteractionResponse::UpdateMessage(msg)).await;

View file

@ -21,15 +21,35 @@ pub enum Banner {
Verify,
Welcome,
Help,
/// Vertical 3:4 posters for `/help` category pages.
HelpInformation,
HelpModeration,
HelpTickets,
HelpUtility,
}
impl Banner {
/// Poster for a `/help` category (by display name, e.g. `"Moderation"`).
pub fn for_category(name: &str) -> Option<Self> {
match name {
"Information" => Some(Self::HelpInformation),
"Moderation" => Some(Self::HelpModeration),
"Tickets" => Some(Self::HelpTickets),
"Utility" => Some(Self::HelpUtility),
_ => None,
}
}
fn file(self) -> &'static str {
match self {
Self::Ticket => "ticket.png",
Self::Verify => "verify.png",
Self::Welcome => "welcome.png",
Self::Help => "help.png",
Self::HelpInformation => "help-information.png",
Self::HelpModeration => "help-moderation.png",
Self::HelpTickets => "help-tickets.png",
Self::HelpUtility => "help-utility.png",
}
}
@ -39,6 +59,10 @@ impl Banner {
Self::Verify => include_bytes!("../../assets/brand/verify.png"),
Self::Welcome => include_bytes!("../../assets/brand/welcome.png"),
Self::Help => include_bytes!("../../assets/brand/help.png"),
Self::HelpInformation => include_bytes!("../../assets/brand/help-information.png"),
Self::HelpModeration => include_bytes!("../../assets/brand/help-moderation.png"),
Self::HelpTickets => include_bytes!("../../assets/brand/help-tickets.png"),
Self::HelpUtility => include_bytes!("../../assets/brand/help-utility.png"),
}
}
@ -52,3 +76,17 @@ impl Banner {
format!("attachment://{}", self.file())
}
}
#[cfg(test)]
mod tests {
use super::Banner;
#[test]
fn every_help_category_has_a_poster() {
for (name, _) in crate::feature::help::categories::all() {
let b = Banner::for_category(name).expect("poster for category");
assert!(b.url().starts_with("attachment://help-"));
assert!(!b.bytes().is_empty());
}
}
}