aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2018-02-10 15:25:01 +0100
committerJokler <jokler.contact@gmail.com>2018-02-10 15:25:01 +0100
commit2c10ee57bbefde948b401c36fc50209bc34a99ad (patch)
treea7482e39e3fcfd8efa32460d670503c90de7a3aa /src
parent2ba26a37d27a637b7c0e02970419342a6f83462b (diff)
downloadfrippy-2c10ee57bbefde948b401c36fc50209bc34a99ad.tar.gz
frippy-2c10ee57bbefde948b401c36fc50209bc34a99ad.zip
Upgrade dependencies
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs74
-rw-r--r--src/plugin.rs10
-rw-r--r--src/plugins/currency.rs16
-rw-r--r--src/plugins/emoji.rs10
-rw-r--r--src/plugins/help.rs10
-rw-r--r--src/plugins/keepnick.rs12
-rw-r--r--src/plugins/url.rs10
7 files changed, 64 insertions, 78 deletions
diff --git a/src/lib.rs b/src/lib.rs
index d769075..3e47c8c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -6,24 +6,22 @@
//!
//! ## Examples
//! ```no_run
-//! # extern crate tokio_core;
-//! # extern crate futures;
+//! # extern crate irc;
//! # extern crate frippy;
//! # fn main() {
//! use frippy::{plugins, Config, Bot};
-//! use tokio_core::reactor::Core;
-//! use futures::future;
+//! use irc::client::reactor::IrcReactor;
//!
//! let config = Config::load("config.toml").unwrap();
-//! let mut reactor = Core::new().unwrap();
+//! let mut reactor = IrcReactor::new().unwrap();
//! let mut bot = Bot::new();
//!
//! bot.add_plugin(plugins::Help::new());
//! bot.add_plugin(plugins::Emoji::new());
//! bot.add_plugin(plugins::Currency::new());
//!
-//! bot.connect(&mut reactor, &config);
-//! reactor.run(future::empty::<(), ()>()).unwrap();
+//! bot.connect(&mut reactor, &config).unwrap();
+//! reactor.run().unwrap();
//! # }
//! ```
//!
@@ -39,8 +37,6 @@ extern crate lazy_static;
extern crate frippy_derive;
extern crate irc;
-extern crate futures;
-extern crate tokio_core;
pub mod plugin;
pub mod plugins;
@@ -50,9 +46,8 @@ use std::collections::HashMap;
use std::thread::spawn;
use std::sync::Arc;
-use tokio_core::reactor::Core;
pub use irc::client::prelude::*;
-pub use irc::error::Error as IrcError;
+pub use irc::error::IrcError;
use plugin::*;
@@ -108,66 +103,57 @@ impl Bot {
self.plugins.remove(name)
}
- /// This connects the `Bot` to IRC and returns a `Future`
- /// which represents the bots work.
- /// This `Future` will run forever unless it returns an error.
+ /// This connects the `Bot` to IRC and creates a task on the `IrcReactor`
+ /// which returns an Ok if the connection was cleanly closed and an Err
+ /// if the connection was lostwhich returns an Ok if the connection was cleanly closed and an Err
+ /// if the connection was lost.
///
- /// You need to run the `Future`, so that the `Bot`
+ /// You need to run the `IrcReactor`, so that the `Bot`
/// can actually do its work.
///
/// # Examples
/// ```no_run
- /// # extern crate tokio_core;
- /// # extern crate futures;
+ /// # extern crate irc;
/// # extern crate frippy;
/// # fn main() {
/// use frippy::{Config, Bot};
- /// use tokio_core::reactor::Core;
- /// use futures::future;
+ /// use irc::client::reactor::IrcReactor;
///
/// let config = Config::load("config.toml").unwrap();
- /// let mut reactor = Core::new().unwrap();
+ /// let mut reactor = IrcReactor::new().unwrap();
/// let mut bot = Bot::new();
///
- /// let future = bot.connect(&mut reactor, &config);
- /// reactor.run(future).unwrap();
+ /// bot.connect(&mut reactor, &config).unwrap();
+ /// reactor.run().unwrap();
/// # }
/// ```
- pub fn connect(&self, reactor: &mut Core, config: &Config) -> Option<Box<futures::Future<Item = (), Error = ()>>> {
+ pub fn connect(&self, reactor: &mut IrcReactor, config: &Config) -> Result<(), String> {
info!("Plugins loaded: {}", self.plugins);
- let server =
- match IrcServer::new_future(reactor.handle(), config).and_then(|f| {reactor.run(f)}) {
- Ok(v) => v,
- Err(e) => {
- error!("Failed to connect: {}", e);
- return None;
- }
- };
+ let client = match reactor.prepare_client_and_connect(config) {
+ Ok(v) => v,
+ Err(e) => return Err(format!("Failed to connect: {}", e)),
+ };
info!("Connected to server");
- match server.identify() {
+ match client.identify() {
Ok(_) => info!("Identified"),
- Err(e) => {
- error!("Failed to identify: {}", e);
- return None;
- }
+ Err(e) => return Err(format!("Failed to identify: {}", e)),
};
// TODO Verify if we actually need to clone plugins twice
let plugins = self.plugins.clone();
- let future = server
- .stream()
- .for_each(move |message| process_msg(&server, plugins.clone(), message))
- .map_err(|e| error!("Failed to process message: {}", e));
+ reactor.register_client_with_handler(client, move |client, message| {
+ process_msg(&client, plugins.clone(), message)
+ });
- Some(Box::new(future))
+ Ok(())
}
}
-fn process_msg(server: &IrcServer,
+fn process_msg(server: &IrcClient,
mut plugins: ThreadedPlugins,
message: Message)
-> Result<(), IrcError> {
@@ -215,7 +201,7 @@ impl ThreadedPlugins {
self.plugins.remove(&name.to_lowercase()).map(|_| ())
}
- pub fn execute_plugins(&mut self, server: &IrcServer, message: Message) {
+ pub fn execute_plugins(&mut self, server: &IrcClient, message: Message) {
let message = Arc::new(message);
for (name, plugin) in self.plugins.clone() {
@@ -242,7 +228,7 @@ impl ThreadedPlugins {
}
pub fn handle_command(&mut self,
- server: &IrcServer,
+ server: &IrcClient,
mut command: PluginCommand)
-> Result<(), IrcError> {
diff --git a/src/plugin.rs b/src/plugin.rs
index 63d3530..8785708 100644
--- a/src/plugin.rs
+++ b/src/plugin.rs
@@ -2,19 +2,19 @@
use std::fmt;
use irc::client::prelude::*;
-use irc::error::Error as IrcError;
+use irc::error::IrcError;
/// `Plugin` has to be implemented for any struct that should be usable
/// as a plugin in frippy.
pub trait Plugin: PluginName + Send + Sync + fmt::Debug {
/// This should return true if the `Plugin` wants to do work on the message.
- fn is_allowed(&self, server: &IrcServer, message: &Message) -> bool;
+ fn is_allowed(&self, server: &IrcClient, message: &Message) -> bool;
/// Handles messages which are not commands but still necessary.
- fn execute(&self, server: &IrcServer, message: &Message) -> Result<(), IrcError>;
+ fn execute(&self, server: &IrcClient, message: &Message) -> Result<(), IrcError>;
/// Handles any command directed at this plugin.
- fn command(&self, server: &IrcServer, command: PluginCommand) -> Result<(), IrcError>;
+ fn command(&self, server: &IrcClient, command: PluginCommand) -> Result<(), IrcError>;
/// Should work like command but return a String instead of sending messages to IRC.
- fn evaluate(&self, server: &IrcServer, command: PluginCommand) -> Result<String, String>;
+ fn evaluate(&self, server: &IrcClient, command: PluginCommand) -> Result<String, String>;
}
/// `PluginName` is required by `Plugin`.
diff --git a/src/plugins/currency.rs b/src/plugins/currency.rs
index 4d44d9a..32a2506 100644
--- a/src/plugins/currency.rs
+++ b/src/plugins/currency.rs
@@ -6,7 +6,7 @@ use std::io::Read;
use std::num::ParseFloatError;
use irc::client::prelude::*;
-use irc::error::Error as IrcError;
+use irc::error::IrcError;
use self::reqwest::Client;
use self::reqwest::header::Connection;
@@ -78,7 +78,7 @@ impl Currency {
})
}
- fn convert(&self, server: &IrcServer, command: &mut PluginCommand) -> Result<String, String> {
+ fn convert(&self, server: &IrcClient, command: &mut PluginCommand) -> Result<String, String> {
if command.tokens.len() < 3 {
return Err(self.invalid_command(server));
@@ -105,7 +105,7 @@ impl Currency {
}
}
- fn help(&self, server: &IrcServer) -> String {
+ fn help(&self, server: &IrcClient) -> String {
format!("usage: {} currency value from_currency to_currency\r\n\
example: 1.5 eur usd\r\n\
available currencies: AUD, BGN, BRL, CAD, \
@@ -116,7 +116,7 @@ impl Currency {
server.current_nickname())
}
- fn invalid_command(&self, server: &IrcServer) -> String {
+ fn invalid_command(&self, server: &IrcClient) -> String {
format!("Incorrect Command. \
Send \"{} currency help\" for help.",
server.current_nickname())
@@ -124,15 +124,15 @@ impl Currency {
}
impl Plugin for Currency {
- fn is_allowed(&self, _: &IrcServer, _: &Message) -> bool {
+ fn is_allowed(&self, _: &IrcClient, _: &Message) -> bool {
false
}
- fn execute(&self, _: &IrcServer, _: &Message) -> Result<(), IrcError> {
+ fn execute(&self, _: &IrcClient, _: &Message) -> Result<(), IrcError> {
panic!("Currency does not implement the execute function!")
}
- fn command(&self, server: &IrcServer, mut command: PluginCommand) -> Result<(), IrcError> {
+ fn command(&self, server: &IrcClient, mut command: PluginCommand) -> Result<(), IrcError> {
if command.tokens.is_empty() {
return server.send_notice(&command.source, &self.invalid_command(server));
@@ -147,7 +147,7 @@ impl Plugin for Currency {
}
}
- fn evaluate(&self, server: &IrcServer, mut command: PluginCommand) -> Result<String, String>{
+ fn evaluate(&self, server: &IrcClient, mut command: PluginCommand) -> Result<String, String>{
if command.tokens.is_empty() {
return Err(self.invalid_command(server));
}
diff --git a/src/plugins/emoji.rs b/src/plugins/emoji.rs
index 512a62e..c19593d 100644
--- a/src/plugins/emoji.rs
+++ b/src/plugins/emoji.rs
@@ -3,7 +3,7 @@ extern crate unicode_names;
use std::fmt;
use irc::client::prelude::*;
-use irc::error::Error as IrcError;
+use irc::error::IrcError;
use plugin::*;
@@ -97,14 +97,14 @@ impl Emoji {
}
impl Plugin for Emoji {
- fn is_allowed(&self, _: &IrcServer, message: &Message) -> bool {
+ fn is_allowed(&self, _: &IrcClient, message: &Message) -> bool {
match message.command {
Command::PRIVMSG(_, _) => true,
_ => false,
}
}
- fn execute(&self, server: &IrcServer, message: &Message) -> Result<(), IrcError> {
+ fn execute(&self, server: &IrcClient, message: &Message) -> Result<(), IrcError> {
match message.command {
Command::PRIVMSG(_, ref content) => {
server.send_privmsg(message.response_target().unwrap(),
@@ -114,12 +114,12 @@ impl Plugin for Emoji {
}
}
- fn command(&self, server: &IrcServer, command: PluginCommand) -> Result<(), IrcError> {
+ fn command(&self, server: &IrcClient, command: PluginCommand) -> Result<(), IrcError> {
server.send_notice(&command.source,
"This Plugin does not implement any commands.")
}
- fn evaluate(&self, _: &IrcServer, command: PluginCommand) -> Result<String, String> {
+ fn evaluate(&self, _: &IrcClient, command: PluginCommand) -> Result<String, String> {
let emojis = self.emoji(&command.tokens[0]);
if emojis.is_empty() {
Ok(emojis)
diff --git a/src/plugins/help.rs b/src/plugins/help.rs
index cea325f..1bb15e1 100644
--- a/src/plugins/help.rs
+++ b/src/plugins/help.rs
@@ -1,5 +1,5 @@
use irc::client::prelude::*;
-use irc::error::Error as IrcError;
+use irc::error::IrcError;
use plugin::*;
@@ -13,19 +13,19 @@ impl Help {
}
impl Plugin for Help {
- fn is_allowed(&self, _: &IrcServer, _: &Message) -> bool {
+ fn is_allowed(&self, _: &IrcClient, _: &Message) -> bool {
false
}
- fn execute(&self, _: &IrcServer, _: &Message) -> Result<(), IrcError> {
+ fn execute(&self, _: &IrcClient, _: &Message) -> Result<(), IrcError> {
panic!("Help does not implement the execute function!")
}
- fn command(&self, server: &IrcServer, command: PluginCommand) -> Result<(), IrcError> {
+ fn command(&self, server: &IrcClient, command: PluginCommand) -> Result<(), IrcError> {
server.send_notice(&command.source, "Help has not been added yet.")
}
- fn evaluate(&self, _: &IrcServer, _: PluginCommand) -> Result<String, String> {
+ fn evaluate(&self, _: &IrcClient, _: PluginCommand) -> Result<String, String> {
Err(String::from("Help has not been added yet."))
}
}
diff --git a/src/plugins/keepnick.rs b/src/plugins/keepnick.rs
index 2970857..4a40e8f 100644
--- a/src/plugins/keepnick.rs
+++ b/src/plugins/keepnick.rs
@@ -1,5 +1,5 @@
use irc::client::prelude::*;
-use irc::error::Error as IrcError;
+use irc::error::IrcError;
use plugin::*;
@@ -11,7 +11,7 @@ impl KeepNick {
KeepNick {}
}
- fn check_nick(&self, server: &IrcServer, leaver: &str) -> Result<(), IrcError> {
+ fn check_nick(&self, server: &IrcClient, leaver: &str) -> Result<(), IrcError> {
let cfg_nick = match server.config().nickname {
Some(ref nick) => nick.clone(),
None => return Ok(()),
@@ -34,14 +34,14 @@ impl KeepNick {
}
impl Plugin for KeepNick {
- fn is_allowed(&self, _: &IrcServer, message: &Message) -> bool {
+ fn is_allowed(&self, _: &IrcClient, message: &Message) -> bool {
match message.command {
Command::QUIT(_) => true,
_ => false,
}
}
- fn execute(&self, server: &IrcServer, message: &Message) -> Result<(), IrcError> {
+ fn execute(&self, server: &IrcClient, message: &Message) -> Result<(), IrcError> {
match message.command {
Command::QUIT(ref nick) => {
self.check_nick(server, &nick.clone().unwrap_or_else(|| String::new()))
@@ -50,12 +50,12 @@ impl Plugin for KeepNick {
}
}
- fn command(&self, server: &IrcServer, command: PluginCommand) -> Result<(), IrcError> {
+ fn command(&self, server: &IrcClient, command: PluginCommand) -> Result<(), IrcError> {
server.send_notice(&command.source,
"This Plugin does not implement any commands.")
}
- fn evaluate(&self, _: &IrcServer, _: PluginCommand) -> Result<String, String> {
+ fn evaluate(&self, _: &IrcClient, _: PluginCommand) -> Result<String, String> {
Err(String::from("This Plugin does not implement any commands."))
}
}
diff --git a/src/plugins/url.rs b/src/plugins/url.rs
index ab36833..b980d3e 100644
--- a/src/plugins/url.rs
+++ b/src/plugins/url.rs
@@ -3,7 +3,7 @@ extern crate reqwest;
extern crate select;
use irc::client::prelude::*;
-use irc::error::Error as IrcError;
+use irc::error::IrcError;
use self::regex::Regex;
@@ -126,14 +126,14 @@ impl Url {
}
impl Plugin for Url {
- fn is_allowed(&self, _: &IrcServer, message: &Message) -> bool {
+ fn is_allowed(&self, _: &IrcClient, message: &Message) -> bool {
match message.command {
Command::PRIVMSG(_, ref msg) => RE.is_match(msg),
_ => false,
}
}
- fn execute(&self, server: &IrcServer, message: &Message) -> Result<(), IrcError> {
+ fn execute(&self, server: &IrcClient, message: &Message) -> Result<(), IrcError> {
match message.command {
Command::PRIVMSG(_, ref content) => {
match self.url(content) {
@@ -145,12 +145,12 @@ impl Plugin for Url {
}
}
- fn command(&self, server: &IrcServer, command: PluginCommand) -> Result<(), IrcError> {
+ fn command(&self, server: &IrcClient, command: PluginCommand) -> Result<(), IrcError> {
server.send_notice(&command.source,
"This Plugin does not implement any commands.")
}
- fn evaluate(&self, _: &IrcServer, command: PluginCommand) -> Result<String, String> {
+ fn evaluate(&self, _: &IrcClient, command: PluginCommand) -> Result<String, String> {
self.url(&command.tokens[0]).map_err(|e| String::from(e))
}
}