aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/plugins/quote/database.rs7
-rw-r--r--src/plugins/quote/mod.rs33
2 files changed, 25 insertions, 15 deletions
diff --git a/src/plugins/quote/database.rs b/src/plugins/quote/database.rs
index c8f550e..3c904df 100644
--- a/src/plugins/quote/database.rs
+++ b/src/plugins/quote/database.rs
@@ -81,7 +81,9 @@ impl<S: ::std::hash::BuildHasher + Send + Sync> Database
.iter()
.filter(|&(&(_, ref c, _), _)| c == channel)
.nth(idx as usize - 1)
- .ok_or(ErrorKind::NotFound)?.1.clone())
+ .ok_or(ErrorKind::NotFound)?
+ .1
+ .clone())
}
fn count_user_quotes(&self, quotee: &str, channel: &str) -> Result<i32, QuoteError> {
@@ -121,7 +123,6 @@ use self::schema::quotes;
#[cfg(feature = "mysql")]
impl Database for Arc<Pool<ConnectionManager<MysqlConnection>>> {
fn insert_quote(&mut self, quote: &NewQuote) -> Result<(), QuoteError> {
-
let conn = &*self.get().context(ErrorKind::NoConnection)?;
diesel::insert_into(quotes::table)
.values(quote)
@@ -149,7 +150,6 @@ impl Database for Arc<Pool<ConnectionManager<MysqlConnection>>> {
}
fn count_user_quotes(&self, quotee: &str, channel: &str) -> Result<i32, QuoteError> {
-
let conn = &*self.get().context(ErrorKind::NoConnection)?;
let count: Result<i64, _> = quotes::table
.filter(quotes::columns::quotee.eq(quotee))
@@ -165,7 +165,6 @@ impl Database for Arc<Pool<ConnectionManager<MysqlConnection>>> {
}
fn count_channel_quotes(&self, channel: &str) -> Result<i32, QuoteError> {
-
let conn = &*self.get().context(ErrorKind::NoConnection)?;
let count: Result<i64, _> = quotes::table
.filter(quotes::columns::channel.eq(channel))
diff --git a/src/plugins/quote/mod.rs b/src/plugins/quote/mod.rs
index c6e33fe..9b7e6f5 100644
--- a/src/plugins/quote/mod.rs
+++ b/src/plugins/quote/mod.rs
@@ -109,28 +109,39 @@ impl<T: Database, C: Client> Quote<T, C> {
}
};
- let quote = if let Some(quotee) = quotee {
- self
+ let response = if let Some(quotee) = quotee {
+ let quote = self
.quotes
.read()
.get_user_quote(quotee, channel, idx)
- .context(ErrorKind::NotFound)?
+ .context(ErrorKind::NotFound)?;
+
+ format!(
+ "\"{}\" - {}[{}/{}]",
+ quote.content, quote.quotee, quote.idx, count
+ )
} else {
- self
+ let quote = self
.quotes
.read()
.get_channel_quote(channel, idx)
- .context(ErrorKind::NotFound)?
+ .context(ErrorKind::NotFound)?;
+
+ format!(
+ "\"{}\" - {}[{}]",
+ quote.content, quote.quotee, quote.idx
+ )
};
- Ok(format!(
- "\"{}\" - {}[{}/{}]",
- quote.content, quote.quotee, idx, count
- ))
+ Ok(response)
}
fn info(&self, command: &PluginCommand) -> Result<String, QuoteError> {
- let tokens = command.tokens.iter().filter(|t| !t.is_empty()).collect::<Vec<_>>();
+ let tokens = command
+ .tokens
+ .iter()
+ .filter(|t| !t.is_empty())
+ .collect::<Vec<_>>();
match tokens.len() {
0 => {
let channel = &command.target;
@@ -150,7 +161,7 @@ impl<T: Database, C: Client> Quote<T, C> {
Ok(match count {
0 => Err(ErrorKind::NotFound)?,
1 => format!("{} has 1 quote", quotee),
- _ => format!("{} has {} quotes", quotee, count),
+ _ => format!("{} has {} quotes", count, quotee),
})
}
_ => {