aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2018-11-06 05:40:39 +0100
committerJokler <jokler.contact@gmail.com>2018-11-06 05:40:39 +0100
commitcaf5fae723f9af78421cf154afd75ec7e344a0dd (patch)
tree2833f453fb026e16091365f63c477afc2d66aa1e /src
parentf9e3022756ea454a31f797bfc9cfdc1d81ee86cf (diff)
downloadfrippy-caf5fae723f9af78421cf154afd75ec7e344a0dd.tar.gz
frippy-caf5fae723f9af78421cf154afd75ec7e344a0dd.zip
Quote: Info: Add negative indexing and fix error
Diffstat (limited to 'src')
-rw-r--r--src/plugins/quote/mod.rs13
1 files changed, 12 insertions, 1 deletions
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<T: Database, C: Client> Quote<T, C> {
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",