From cf55ca8e6dc911edba3f881a3f5d6aa528662a57 Mon Sep 17 00:00:00 2001 From: astar76 Date: Sat, 24 Oct 2026 15:46:55 -0500 Subject: [PATCH] /convert type: file: output: quality:<..>; /image and /media restored Co-Authored-By: Claude Sonnet 5.5 --- src/commands/channels.rs | 1 - src/commands/media/convert.rs | 16 ++++++++-------- src/commands/media/images.rs | 6 +++--- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/commands/channels.rs b/src/commands/channels.rs index cf9d0f0..0669a5f 100644 --- a/src/commands/channels.rs +++ b/src/commands/channels.rs @@ -188,7 +188,6 @@ async fn vote(state: &State, channel: Id, message: Id Vec { vec![ Command::new("media", "server", "Make a channel media-only (or back to normal)", |c| media(c).boxed()) - .slash_as("mediaonly") .usage(" [#channel]") .opt(Opt::opt("action", "Lock to media-only, or unlock", OptKind::String).choices(&["lock", "unlock"])) .opt(Opt::opt("channel", "Defaults to this channel", OptKind::Channel)) diff --git a/src/commands/media/convert.rs b/src/commands/media/convert.rs index 5b1d0e9..1b280bd 100644 --- a/src/commands/media/convert.rs +++ b/src/commands/media/convert.rs @@ -1,6 +1,6 @@ //! `/convert` · `D!convert` — turn any picture, clip or sound into any image, video or audio format. //! -//! The slash command asks for a **type** (image / video / audio), then a **format** that depends on it (as you type +//! `/convert type:image file: output:gif quality:720p` — the slash command asks for a **type** (image / video / audio), then an **output** format that depends on it (as you type //! the list shows only the formats of that type), then an optional **quality**: *adaptive* (the best that fits //! Discord's upload limit), a height in pixels like `1080p` / `720p` / `900p` for pictures and video (smaller sources //! are upscaled with Lanczos and a little sharpening), or a bitrate like `192k` for audio. @@ -47,7 +47,7 @@ fn kbps_label(k: u32) -> &'static str { } fn media_type_of(siblings: &HashMap) -> Option { - siblings.get("type").and_then(|t| MediaType::parse(t)).or_else(|| siblings.get("format").and_then(|f| find_format(f, None)).map(|f| f.ty)) + siblings.get("type").and_then(|t| MediaType::parse(t)).or_else(|| siblings.get("output").and_then(|f| find_format(f, None)).map(|f| f.ty)) } /// What the dropdowns show: formats of the chosen type, and qualities that fit the type (and the format). @@ -55,7 +55,7 @@ async fn suggest(_: Arc, option: String, typed: String, siblings: HashMap let typed = typed.trim().to_lowercase(); let ty = media_type_of(&siblings); match option.as_str() { - "format" => { + "output" => { let list: Vec<&ffmpeg::Format> = match ty { Some(t) => formats_for(t), None => ffmpeg::FORMATS.iter().collect(), @@ -67,7 +67,7 @@ async fn suggest(_: Arc, option: String, typed: String, siblings: HashMap .collect() } "quality" => { - let lossless = siblings.get("format").and_then(|f| find_format(f, ty)).is_some_and(|f| f.lossless); + let lossless = siblings.get("output").and_then(|f| find_format(f, ty)).is_some_and(|f| f.lossless); let mut out = vec![("Adaptive — best that fits Discord".to_string(), "adaptive".to_string())]; if lossless && ty == Some(MediaType::Audio) { out = vec![("Lossless — no bitrate to pick".to_string(), "adaptive".to_string())]; @@ -94,7 +94,7 @@ fn mb(bytes: usize) -> String { async fn convert_cmd(ctx: Arc) -> Result<()> { let a = &ctx.args; let mut ty = a.str("type").and_then(MediaType::parse); - let mut format = a.str("format").unwrap_or("").to_string(); + let mut format = a.str("output").unwrap_or("").to_string(); let mut quality_text = a.str("quality").unwrap_or("").to_string(); let mut rest = a.str("rest").unwrap_or("").to_string(); if !ctx.is_slash() { @@ -156,12 +156,12 @@ async fn convert_cmd(ctx: Arc) -> Result<()> { pub fn commands() -> Vec { vec![Command::new("convert", "fun", "Convert any picture, video or audio to another format (pick a type, a format and a quality)", |c| convert_cmd(c).boxed()) .aliases(&["conv"]) - .usage("[type] [quality] [link | @user] (reply to or attach a file)") + .usage("[type] [quality] [link | @user] (reply to or attach a file)") .opt(Opt::req("type", "What kind of file to make", OptKind::String).choices(&["image", "video", "audio"]).slash_only()) - .opt(Opt::req("format", "The format to make (the list depends on the type)", OptKind::String).autocomplete()) + .opt(Opt::req("output", "The format to make (the list depends on the type)", OptKind::String).autocomplete()) .opt(Opt::opt("quality", "Adaptive, a height (1080p, 720p…) or an audio bitrate (320k, 128k…)", OptKind::String).autocomplete().slash_only()) .opt(Opt::opt("rest", "Quality, then a link or @user (or attach / reply)", OptKind::String).prefix_only()) - .opt(Opt::opt("media", "The picture, GIF, video or audio to convert", OptKind::Attachment).slash_only()) + .opt(Opt::opt("file", "The picture, GIF, video or audio to convert", OptKind::Attachment).slash_only()) .opt(Opt::opt("user", "…or use someone's avatar", OptKind::User).slash_only()) .opt(Opt::opt("url", "…or a link", OptKind::String).slash_only()) .suggest_with(|_state, option, typed, siblings| suggest(_state, option, typed, siblings).boxed())] diff --git a/src/commands/media/images.rs b/src/commands/media/images.rs index 251676a..f744861 100644 --- a/src/commands/media/images.rs +++ b/src/commands/media/images.rs @@ -322,7 +322,7 @@ pub fn squish_gif(bytes: &[u8]) -> Option> { pub(super) async fn pick(ctx: &Ctx, text: &str) -> Result<(String, String)> { let state = &ctx.state; if ctx.is_slash() { - if let Some(a) = ctx.args.id("media").and_then(|id| ctx.attachments.iter().find(|a| a.id.get() == id)) { + if let Some(a) = ctx.args.id("file").or_else(|| ctx.args.id("image")).and_then(|id| ctx.attachments.iter().find(|a| a.id.get() == id)) { return Ok((a.url.clone(), text.to_string())); } if let Some(u) = ctx.args.user("user") { @@ -521,11 +521,11 @@ pub fn commands() -> Vec { vec![ Command::new("fx", "fun", fx_help, |c| image_cmd(c).boxed()) .aliases(&["effect", "filter", "imagefx"]) - .slash_as("media") + .slash_as("image") .usage(" [text]") .opt(Opt::opt("name", "Effect or filter", OptKind::String).prefix_only()) .opt(Opt::opt("rest", "Text, a link, a @user…", OptKind::String).prefix_only()) - .opt(Opt::opt("media", "A picture or GIF to edit", OptKind::Attachment).slash_only()) + .opt(Opt::opt("image", "A picture or GIF to edit", OptKind::Attachment).slash_only()) .opt(Opt::opt("user", "…or use someone's avatar", OptKind::User).slash_only()) .opt(Opt::opt("url", "…or a link", OptKind::String).slash_only()) .opt(Opt::opt("effect", "Speech bubble, caption, blur, deepfry…", OptKind::String).choices(&EFFECTS).slash_only())