/convert type:<image|video|audio> file:<file> output:<format> quality:<..>; /image and /media restored
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
parent
6d6117d56b
commit
cf55ca8e6d
3 changed files with 11 additions and 12 deletions
|
|
@ -188,7 +188,6 @@ async fn vote(state: &State, channel: Id<ChannelMarker>, message: Id<MessageMark
|
|||
pub fn commands() -> Vec<Command> {
|
||||
vec![
|
||||
Command::new("media", "server", "Make a channel media-only (or back to normal)", |c| media(c).boxed())
|
||||
.slash_as("mediaonly")
|
||||
.usage("<lock|unlock> [#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))
|
||||
|
|
|
|||
|
|
@ -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:<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<String, String>) -> Option<MediaType> {
|
||||
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<State>, 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<State>, 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<Ctx>) -> 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<Ctx>) -> Result<()> {
|
|||
pub fn commands() -> Vec<Command> {
|
||||
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] <format> [quality] [link | @user] (reply to or attach a file)")
|
||||
.usage("[type] <output> [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())]
|
||||
|
|
|
|||
|
|
@ -322,7 +322,7 @@ pub fn squish_gif(bytes: &[u8]) -> Option<Vec<u8>> {
|
|||
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<Command> {
|
|||
vec![
|
||||
Command::new("fx", "fun", fx_help, |c| image_cmd(c).boxed())
|
||||
.aliases(&["effect", "filter", "imagefx"])
|
||||
.slash_as("media")
|
||||
.slash_as("image")
|
||||
.usage("<effect | filter> [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())
|
||||
|
|
|
|||
Loading…
Reference in a new issue