From f5c4786c14a3ef3868d8f11df897f36053bf29e3 Mon Sep 17 00:00:00 2001 From: Jokler Date: Sat, 22 Sep 2018 20:19:20 +0200 Subject: Quote: Fix get command when no index was specified --- src/plugins/quote/mod.rs | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/plugins/quote/mod.rs b/src/plugins/quote/mod.rs index 9f8a29e..8a122d6 100644 --- a/src/plugins/quote/mod.rs +++ b/src/plugins/quote/mod.rs @@ -92,21 +92,20 @@ impl Quote { Err(ErrorKind::NotFound)?; } - let idx = match command.tokens.len() { - 1 | _ if command.tokens[1].is_empty() => thread_rng().gen_range(1, count + 1), - _ => { - let idx_string = &command.tokens[1]; - - let idx = match i32::from_str(idx_string) { - Ok(i) => i, - Err(_) => Err(ErrorKind::InvalidIndex)?, - }; - - if idx < 0 { - count + idx + 1 - } else { - idx - } + let len = command.tokens.len(); + let idx = if len < 2 || command.tokens[1].is_empty() { + thread_rng().gen_range(1, count + 1) + } else { + let idx_string = &command.tokens[1]; + let idx = match i32::from_str(idx_string) { + Ok(i) => i, + Err(_) => Err(ErrorKind::InvalidIndex)?, + }; + + if idx < 0 { + count + idx + 1 + } else { + idx } }; -- cgit v1.2.3-70-g09d2