aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/quote/mod.rs
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2018-09-21 00:59:44 +0200
committerJokler <jokler.contact@gmail.com>2018-09-21 00:59:44 +0200
commit9401a62004f3ac7313f6bf12d2649d5af61835c5 (patch)
treeb39a4e4c700039bb2e59cf514d1eeb695e1bb8a1 /src/plugins/quote/mod.rs
parent625ca41cf54bac0268f7bde9d7ad9017c03d5919 (diff)
downloadfrippy-9401a62004f3ac7313f6bf12d2649d5af61835c5.tar.gz
frippy-9401a62004f3ac7313f6bf12d2649d5af61835c5.zip
Quote: Ignore trailing space when no index was specified
Diffstat (limited to 'src/plugins/quote/mod.rs')
-rw-r--r--src/plugins/quote/mod.rs20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/plugins/quote/mod.rs b/src/plugins/quote/mod.rs
index 43333e7..9f8a29e 100644
--- a/src/plugins/quote/mod.rs
+++ b/src/plugins/quote/mod.rs
@@ -3,9 +3,9 @@ use std::marker::PhantomData;
use std::str::FromStr;
use antidote::RwLock;
+use chrono::NaiveDateTime;
use irc::client::prelude::*;
use rand::{thread_rng, Rng};
-use chrono::NaiveDateTime;
use time;
use plugin::*;
@@ -56,7 +56,8 @@ impl<T: Database, C: Client> Quote<T, C> {
created: NaiveDateTime::from_timestamp(tm.sec, 0u32),
};
- Ok(self.quotes
+ Ok(self
+ .quotes
.write()
.insert_quote(&quote)
.map(|()| "Successfully added!")?)
@@ -92,9 +93,11 @@ impl<T: Database, C: Client> Quote<T, C> {
}
let idx = match command.tokens.len() {
- 1 => thread_rng().gen_range(1, count + 1),
+ 1 | _ if command.tokens[1].is_empty() => thread_rng().gen_range(1, count + 1),
_ => {
- let idx = match i32::from_str(&command.tokens[1]) {
+ let idx_string = &command.tokens[1];
+
+ let idx = match i32::from_str(idx_string) {
Ok(i) => i,
Err(_) => Err(ErrorKind::InvalidIndex)?,
};
@@ -107,13 +110,16 @@ impl<T: Database, C: Client> Quote<T, C> {
}
};
- let quote = self.quotes
+ let quote = self
+ .quotes
.read()
.get_quote(quotee, channel, idx)
.context(ErrorKind::NotFound)?;
-
- Ok(format!("\"{}\" - {}[{}/{}]", quote.content, quote.quotee, idx, count))
+ Ok(format!(
+ "\"{}\" - {}[{}/{}]",
+ quote.content, quote.quotee, idx, count
+ ))
}
fn info(&self, command: &PluginCommand) -> Result<String, QuoteError> {