diff options
Diffstat (limited to 'src/commands')
| -rw-r--r-- | src/commands/meme/create.rs | 2 | ||||
| -rw-r--r-- | src/commands/meme/history.rs | 4 | ||||
| -rw-r--r-- | src/commands/meme/invoke.rs | 30 | ||||
| -rw-r--r-- | src/commands/meme/mod.rs | 11 | ||||
| -rw-r--r-- | src/commands/mod.rs | 2 |
5 files changed, 21 insertions, 28 deletions
diff --git a/src/commands/meme/create.rs b/src/commands/meme/create.rs index ef6090e..2cd9465 100644 --- a/src/commands/meme/create.rs +++ b/src/commands/meme/create.rs @@ -156,7 +156,7 @@ pub async fn addaudiomeme(ctx: &Context, msg: &Message, args: Args) -> CommandRe .arg("-i") .arg(youtube_url) .args(duration_opts) - .args(&[ + .args([ "-ac", "2", "-ar", "48000", "-f", "opus", "-acodec", "libopus", "-b:a", "96k", "-fs", "5M", "-", ]) diff --git a/src/commands/meme/history.rs b/src/commands/meme/history.rs index 33a2de2..e2953d1 100644 --- a/src/commands/meme/history.rs +++ b/src/commands/meme/history.rs @@ -128,7 +128,7 @@ pub async fn history(ctx: &Context, msg: &Message, mut args: Args) -> CommandRes InvocationRecord::last_n(&mut conn, n)? }; - if records.len() == 0 { + if records.is_empty() { info!("no memes in history"); return util::send(ctx, msg.channel_id, "i don't remember anything :(", msg.tts) .map_err(CommandError::from) @@ -393,7 +393,7 @@ pub async fn query(ctx: &Context, msg: &Message, mut args: Args) -> CommandResul }) .join("\n"); - if result.len() == 0 { + if result.is_empty() { info!("no memes matched query"); return util::send(ctx, msg.channel_id, "no match".to_owned(), msg.tts) diff --git a/src/commands/meme/invoke.rs b/src/commands/meme/invoke.rs index 13996da..2db9e83 100644 --- a/src/commands/meme/invoke.rs +++ b/src/commands/meme/invoke.rs @@ -76,7 +76,7 @@ async fn _meme( args: Args, audio_playback: AudioPlayback, ) -> CommandResult { - if args.len() == 0 || audio_playback != AudioPlayback::Optional { + if args.is_empty() || audio_playback != AudioPlayback::Optional { return rand_meme(ctx, msg, audio_playback).await; } @@ -133,18 +133,15 @@ async fn rand_meme( Ok(()) }, Err(e) => { - match e.downcast_ref::<DieselError>() { - Some(NotFound) => { - info!("random meme not found"); - return util::send(ctx, message.channel_id, "i don't know any :(", message.tts) - .map_err(CommandError::from) - .await; - }, - _ => {}, + if let Some(NotFound) = e.downcast_ref::<DieselError>() { + info!("random meme not found"); + return util::send(ctx, message.channel_id, "i don't know any :(", message.tts) + .map_err(CommandError::from) + .await; } util::send(ctx, message.channel_id, "HELP", message.tts).await?; - return Err(e.into()); + Err(e.into()) }, } } @@ -163,14 +160,11 @@ pub async fn rare_meme(ctx: &Context, msg: &Message, _args: Args) -> CommandResu send_meme(ctx, &meme, &mut conn, msg).await }, Err(e) => { - match e.downcast_ref::<DieselError>() { - Some(NotFound) => { - info!("rare meme not found"); - return util::send(ctx, msg.channel_id, "i don't know any :(", msg.tts) - .map_err(CommandError::from) - .await; - }, - _ => {}, + if let Some(NotFound) = e.downcast_ref::<DieselError>() { + info!("rare meme not found"); + return util::send(ctx, msg.channel_id, "i don't know any :(", msg.tts) + .map_err(CommandError::from) + .await; } util::send(ctx, msg.channel_id, "THE MEME MARKET IS IN FREEFALL", msg.tts) diff --git a/src/commands/meme/mod.rs b/src/commands/meme/mod.rs index fe69b1c..c40e80a 100644 --- a/src/commands/meme/mod.rs +++ b/src/commands/meme/mod.rs @@ -74,7 +74,7 @@ async fn send_meme( msg: &Message, ) -> CommandResult { let should_tts = - t.content.as_ref().map(|t| t.len() > 0).unwrap_or(false) && random::<u32>() % 25 == 0; + t.content.as_ref().map(|t| !t.is_empty()).unwrap_or(false) && random::<u32>() % 25 == 0; debug!("sending meme (tts: {}): {:?}", should_tts, t); @@ -85,7 +85,7 @@ async fn send_meme( let ret = CreateMessage::default().tts(should_tts); match t.content { - Some(ref text) if text.len() > 0 => ret.content(text), + Some(ref text) if !text.is_empty() => ret.content(text), _ => ret, } }; @@ -98,11 +98,10 @@ async fn send_meme( msg.channel_id.send_files(ctx, vec![att], cmsg).await?; }, - None => match t.content { - Some(_) => { + None => { + if t.content.is_some() { msg.channel_id.send_message(ctx, cmsg).await?; - }, - None => {}, + } }, }; diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 3f69a3b..8eac09c 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -36,7 +36,7 @@ pub fn register_commands(f: StandardFramework) -> StandardFramework { result.help(&help::HELP).unrecognised_command(|ctx, msg, unrec| { Box::pin(async move { - let url = match msg.content.split_whitespace().skip(1).next() { + let url = match msg.content.split_whitespace().nth(1) { Some(x) if x.starts_with("http") => x, _ => { info!("bad command formatting: '{}'", unrec); |
