diff options
| author | Jokler <jokler.contact@gmail.com> | 2018-09-22 20:19:20 +0200 |
|---|---|---|
| committer | Jokler <jokler.contact@gmail.com> | 2018-09-22 20:19:20 +0200 |
| commit | f5c4786c14a3ef3868d8f11df897f36053bf29e3 (patch) | |
| tree | 4f9e5d2308354b52f71a559ed8f7bb567393f458 /src/plugins/quote/mod.rs | |
| parent | 9401a62004f3ac7313f6bf12d2649d5af61835c5 (diff) | |
| download | frippy-f5c4786c14a3ef3868d8f11df897f36053bf29e3.tar.gz frippy-f5c4786c14a3ef3868d8f11df897f36053bf29e3.zip | |
Quote: Fix get command when no index was specified
Diffstat (limited to 'src/plugins/quote/mod.rs')
| -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 } }; |
