diff --git a/assets/brand/gen.py b/assets/brand/gen.py index 7186a02..a828473 100644 --- a/assets/brand/gen.py +++ b/assets/brand/gen.py @@ -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""" +{defs} + + +{MARK} +{tag} +{title} +{sub} + +""" + 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 & bot info", "LOKI DEV / INFORMATION") +poster("help-moderation", "MODERATION", "mod tools - requires perms", "LOKI DEV / MODERATION") +poster("help-tickets", "TICKETS", "support tickets & blacklist", "LOKI DEV / TICKETS") +poster("help-utility", "UTILITY", "polls, reminders, blog", "LOKI DEV / UTILITY") + avatar = f""" diff --git a/assets/brand/help-information.png b/assets/brand/help-information.png new file mode 100644 index 0000000..af5366a Binary files /dev/null and b/assets/brand/help-information.png differ diff --git a/assets/brand/help-information.svg b/assets/brand/help-information.svg new file mode 100644 index 0000000..de59ffc --- /dev/null +++ b/assets/brand/help-information.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + +LOKI DEV / INFORMATION +INFORMATION +server & bot info + + \ No newline at end of file diff --git a/assets/brand/help-moderation.png b/assets/brand/help-moderation.png new file mode 100644 index 0000000..234827b Binary files /dev/null and b/assets/brand/help-moderation.png differ diff --git a/assets/brand/help-moderation.svg b/assets/brand/help-moderation.svg new file mode 100644 index 0000000..aa22d78 --- /dev/null +++ b/assets/brand/help-moderation.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + +LOKI DEV / MODERATION +MODERATION +mod tools - requires perms + + \ No newline at end of file diff --git a/assets/brand/help-tickets.png b/assets/brand/help-tickets.png new file mode 100644 index 0000000..633b5b4 Binary files /dev/null and b/assets/brand/help-tickets.png differ diff --git a/assets/brand/help-tickets.svg b/assets/brand/help-tickets.svg new file mode 100644 index 0000000..e513895 --- /dev/null +++ b/assets/brand/help-tickets.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + +LOKI DEV / TICKETS +TICKETS +support tickets & blacklist + + \ No newline at end of file diff --git a/assets/brand/help-utility.png b/assets/brand/help-utility.png new file mode 100644 index 0000000..cf33237 Binary files /dev/null and b/assets/brand/help-utility.png differ diff --git a/assets/brand/help-utility.svg b/assets/brand/help-utility.svg new file mode 100644 index 0000000..7e0a0dc --- /dev/null +++ b/assets/brand/help-utility.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + +LOKI DEV / UTILITY +UTILITY +polls, reminders, blog + + \ No newline at end of file diff --git a/src/feature/help/handler.rs b/src/feature/help/handler.rs index 441d421..b60d5d6 100644 --- a/src/feature/help/handler.rs +++ b/src/feature/help/handler.rs @@ -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 { /// 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; diff --git a/src/util/brand.rs b/src/util/brand.rs index 653cff5..bfcfa8b 100644 --- a/src/util/brand.rs +++ b/src/util/brand.rs @@ -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 { + 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()); + } + } +}