diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/plugins/quote/mod.rs | 29 |
1 files changed, 14 insertions, 15 deletions
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<T: Database, C: Client> Quote<T, C> { 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 } }; |
