From caf5fae723f9af78421cf154afd75ec7e344a0dd Mon Sep 17 00:00:00 2001 From: Jokler Date: Tue, 6 Nov 2018 05:40:39 +0100 Subject: Quote: Info: Add negative indexing and fix error --- src/plugins/quote/mod.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/plugins/quote/mod.rs b/src/plugins/quote/mod.rs index 8a122d6..edeed40 100644 --- a/src/plugins/quote/mod.rs +++ b/src/plugins/quote/mod.rs @@ -139,7 +139,18 @@ impl Quote { let quotee = &command.tokens[0]; let channel = &command.target; let idx = i32::from_str(&command.tokens[1]).context(ErrorKind::InvalidIndex)?; - let quote = self.quotes.read().get_quote(quotee, channel, idx)?; + + let idx = if idx < 0 { + self.quotes.read().count_quotes(quotee, channel)? + idx + 1 + } else { + idx + }; + + let quote = self + .quotes + .read() + .get_quote(quotee, channel, idx) + .context(ErrorKind::NotFound)?; Ok(format!( "{}'s quote was added by {} at {} UTC", -- cgit v1.2.3-70-g09d2