aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/currency.rs64
-rw-r--r--src/plugins/emoji.rs22
-rw-r--r--src/plugins/keepnick.rs7
-rw-r--r--src/plugins/url.rs38
4 files changed, 65 insertions, 66 deletions
diff --git a/src/plugins/currency.rs b/src/plugins/currency.rs
index 21330a1..393df9b 100644
--- a/src/plugins/currency.rs
+++ b/src/plugins/currency.rs
@@ -34,7 +34,6 @@ macro_rules! try_option {
impl<'a> ConvertionRequest<'a> {
fn send(&self) -> Option<f64> {
-
let response = Client::new()
.get("https://api.fixer.io/latest")
.form(&[("base", self.source)])
@@ -49,7 +48,6 @@ impl<'a> ConvertionRequest<'a> {
let convertion_rates: Result<Value, _> = serde_json::from_str(&body);
match convertion_rates {
Ok(convertion_rates) => {
-
let rates: &Value = try_option!(convertion_rates.get("rates"));
let target_rate: &Value =
try_option!(rates.get(self.target.to_uppercase()));
@@ -68,14 +66,15 @@ impl Currency {
Currency {}
}
- fn eval_command<'a>(&self,
- tokens: &'a [String])
- -> Result<ConvertionRequest<'a>, ParseFloatError> {
+ fn eval_command<'a>(
+ &self,
+ tokens: &'a [String],
+ ) -> Result<ConvertionRequest<'a>, ParseFloatError> {
Ok(ConvertionRequest {
- value: tokens[0].parse()?,
- source: &tokens[1],
- target: &tokens[2],
- })
+ value: tokens[0].parse()?,
+ source: &tokens[1],
+ target: &tokens[2],
+ })
}
fn convert(&self, client: &IrcClient, command: &mut PluginCommand) -> Result<String, String> {
@@ -92,33 +91,41 @@ impl Currency {
match request.send() {
Some(response) => {
- let response = format!("{} {} => {:.4} {}",
- request.value,
- request.source.to_lowercase(),
- response / 1.00000000,
- request.target.to_lowercase());
+ let response = format!(
+ "{} {} => {:.4} {}",
+ request.value,
+ request.source.to_lowercase(),
+ response / 1.00000000,
+ request.target.to_lowercase()
+ );
Ok(response)
}
- None => Err(String::from("An error occured during the conversion of the given currency")),
+ None => Err(String::from(
+ "An error occured during the conversion of the given currency",
+ )),
}
}
fn help(&self, client: &IrcClient) -> String {
- format!("usage: {} currency value from_currency to_currency\r\n\
- example: {0} currency 1.5 eur usd\r\n\
- available currencies: AUD, BGN, BRL, CAD, \
- CHF, CNY, CZK, DKK, GBP, HKD, HRK, HUF, \
- IDR, ILS, INR, JPY, KRW, MXN, MYR, NOK, \
- NZD, PHP, PLN, RON, RUB, SEK, SGD, THB, \
- TRY, USD, ZAR",
- client.current_nickname())
+ format!(
+ "usage: {} currency value from_currency to_currency\r\n\
+ example: {0} currency 1.5 eur usd\r\n\
+ available currencies: AUD, BGN, BRL, CAD, \
+ CHF, CNY, CZK, DKK, GBP, HKD, HRK, HUF, \
+ IDR, ILS, INR, JPY, KRW, MXN, MYR, NOK, \
+ NZD, PHP, PLN, RON, RUB, SEK, SGD, THB, \
+ TRY, USD, ZAR",
+ client.current_nickname()
+ )
}
fn invalid_command(&self, client: &IrcClient) -> String {
- format!("Incorrect Command. \
- Send \"{} currency help\" for help.",
- client.current_nickname())
+ format!(
+ "Incorrect Command. \
+ Send \"{} currency help\" for help.",
+ client.current_nickname()
+ )
}
}
@@ -132,7 +139,6 @@ impl Plugin for Currency {
}
fn command(&self, client: &IrcClient, mut command: PluginCommand) -> Result<(), IrcError> {
-
if command.tokens.is_empty() {
return client.send_notice(&command.source, &self.invalid_command(client));
}
@@ -142,11 +148,11 @@ impl Plugin for Currency {
_ => match self.convert(client, &mut command) {
Ok(msg) => client.send_privmsg(&command.target, &msg),
Err(msg) => client.send_notice(&command.source, &msg),
- }
+ },
}
}
- fn evaluate(&self, client: &IrcClient, mut command: PluginCommand) -> Result<String, String>{
+ fn evaluate(&self, client: &IrcClient, mut command: PluginCommand) -> Result<String, String> {
if command.tokens.is_empty() {
return Err(self.invalid_command(client));
}
diff --git a/src/plugins/emoji.rs b/src/plugins/emoji.rs
index 02a31f8..fcb04d1 100644
--- a/src/plugins/emoji.rs
+++ b/src/plugins/emoji.rs
@@ -14,7 +14,6 @@ struct EmojiHandle {
impl fmt::Display for EmojiHandle {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-
let name = match unicode_names::name(self.symbol) {
Some(sym) => sym.to_string().to_lowercase(),
None => String::from("UNKNOWN"),
@@ -52,7 +51,6 @@ impl Emoji {
count: 0,
};
-
for c in string.chars() {
if !self.is_emoji(&c) {
continue;
@@ -60,7 +58,6 @@ impl Emoji {
if current.symbol == c {
current.count += 1;
-
} else {
if current.count > 0 {
emojis.push(current);
@@ -99,13 +96,12 @@ impl Emoji {
impl Plugin for Emoji {
fn execute(&self, client: &IrcClient, message: &Message) -> ExecutionStatus {
match message.command {
- Command::PRIVMSG(_, ref content) => {
- match client.send_privmsg(message.response_target().unwrap(),
- &self.emoji(content)) {
- Ok(_) => ExecutionStatus::Done,
- Err(e) => ExecutionStatus::Err(e),
- }
- }
+ Command::PRIVMSG(_, ref content) => match client
+ .send_privmsg(message.response_target().unwrap(), &self.emoji(content))
+ {
+ Ok(_) => ExecutionStatus::Done,
+ Err(e) => ExecutionStatus::Err(e),
+ },
_ => ExecutionStatus::Done,
}
}
@@ -115,8 +111,10 @@ impl Plugin for Emoji {
}
fn command(&self, client: &IrcClient, command: PluginCommand) -> Result<(), IrcError> {
- client.send_notice(&command.source,
- "This Plugin does not implement any commands.")
+ client.send_notice(
+ &command.source,
+ "This Plugin does not implement any commands.",
+ )
}
fn evaluate(&self, _: &IrcClient, command: PluginCommand) -> Result<String, String> {
diff --git a/src/plugins/keepnick.rs b/src/plugins/keepnick.rs
index e973769..73f4893 100644
--- a/src/plugins/keepnick.rs
+++ b/src/plugins/keepnick.rs
@@ -29,7 +29,6 @@ impl KeepNick {
Ok(_) => ExecutionStatus::Done,
Err(e) => ExecutionStatus::Err(e),
}
-
} else {
ExecutionStatus::Done
}
@@ -51,8 +50,10 @@ impl Plugin for KeepNick {
}
fn command(&self, client: &IrcClient, command: PluginCommand) -> Result<(), IrcError> {
- client.send_notice(&command.source,
- "This Plugin does not implement any commands.")
+ client.send_notice(
+ &command.source,
+ "This Plugin does not implement any commands.",
+ )
}
fn evaluate(&self, _: &IrcClient, _: PluginCommand) -> Result<String, String> {
diff --git a/src/plugins/url.rs b/src/plugins/url.rs
index 9ce5a6a..455aa4e 100644
--- a/src/plugins/url.rs
+++ b/src/plugins/url.rs
@@ -29,7 +29,7 @@ pub struct Url {
impl Url {
/// If a file is larger than `max_kib` KiB the download is stopped
pub fn new(max_kib: usize) -> Url {
- Url {max_kib: max_kib}
+ Url { max_kib: max_kib }
}
fn grep_url(&self, msg: &str) -> Option<String> {
@@ -44,10 +44,7 @@ impl Url {
}
fn download(&self, url: &str) -> Option<String> {
- let response = Client::new()
- .get(url)
- .header(Connection::close())
- .send();
+ let response = Client::new().get(url).header(Connection::close()).send();
match response {
Ok(mut response) => {
@@ -81,10 +78,12 @@ impl Url {
// Check if the file is too large to download
if written > self.max_kib * 1024 {
- debug!("Stopping download - File from {:?} is larger than {} KiB", url, self.max_kib);
+ debug!(
+ "Stopping download - File from {:?} is larger than {} KiB",
+ url, self.max_kib
+ );
return None;
}
-
}
Some(body) // once told me
}
@@ -98,15 +97,11 @@ impl Url {
fn url(&self, text: &str) -> Result<String, &str> {
let url = match self.grep_url(text) {
Some(url) => url,
- None => {
- return Err("No Url was found.")
- }
+ None => return Err("No Url was found."),
};
-
match self.download(&url) {
Some(body) => {
-
let doc = Document::from(body.as_ref());
if let Some(title) = doc.find(Name("title")).next() {
let title = title.children().next().unwrap();
@@ -115,12 +110,11 @@ impl Url {
debug!("Text: {:?}", title_text);
Ok(title_text)
-
} else {
Err("No title was found.")
}
}
- None => Err("Failed to download document.")
+ None => Err("Failed to download document."),
}
}
}
@@ -139,19 +133,19 @@ impl Plugin for Url {
fn execute_threaded(&self, client: &IrcClient, message: &Message) -> Result<(), IrcError> {
match message.command {
- Command::PRIVMSG(_, ref content) => {
- match self.url(content) {
- Ok(title) => client.send_privmsg(message.response_target().unwrap(), &title),
- Err(_) => Ok(()),
- }
- }
+ Command::PRIVMSG(_, ref content) => match self.url(content) {
+ Ok(title) => client.send_privmsg(message.response_target().unwrap(), &title),
+ Err(_) => Ok(()),
+ },
_ => Ok(()),
}
}
fn command(&self, client: &IrcClient, command: PluginCommand) -> Result<(), IrcError> {
- client.send_notice(&command.source,
- "This Plugin does not implement any commands.")
+ client.send_notice(
+ &command.source,
+ "This Plugin does not implement any commands.",
+ )
}
fn evaluate(&self, _: &IrcClient, command: PluginCommand) -> Result<String, String> {