aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2018-02-12 19:16:59 +0100
committerJokler <jokler.contact@gmail.com>2018-02-12 19:16:59 +0100
commitda5c2c8e4893bfb095a8e2122b943c4dca61c41d (patch)
tree3bf1e64c4a128e6b0cb5d5172daf1e3398406715 /src/lib.rs
parentddf42bc0292b0befe2b2f47f3284d9ffeaf6f4b4 (diff)
downloadfrippy-da5c2c8e4893bfb095a8e2122b943c4dca61c41d.tar.gz
frippy-da5c2c8e4893bfb095a8e2122b943c4dca61c41d.zip
Replace is_allowed with a single-threaded execute function
The old execute got renamed to exeute_threaded.
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs40
1 files changed, 22 insertions, 18 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 3e47c8c..8a3a0d1 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -146,7 +146,7 @@ impl Bot {
let plugins = self.plugins.clone();
reactor.register_client_with_handler(client, move |client, message| {
- process_msg(&client, plugins.clone(), message)
+ process_msg(client, plugins.clone(), message)
});
Ok(())
@@ -206,23 +206,27 @@ impl ThreadedPlugins {
for (name, plugin) in self.plugins.clone() {
// Send the message to the plugin if the plugin needs it
- if plugin.is_allowed(server, &message) {
-
- debug!("Executing {} with {}",
- name,
- message.to_string().replace("\r\n", ""));
-
- // Clone everything before the move - the server uses an Arc internally too
- let plugin = Arc::clone(&plugin);
- let message = Arc::clone(&message);
- let server = server.clone();
-
- // Execute the plugin in another thread
- spawn(move || {
- if let Err(e) = plugin.execute(&server, &message) {
- error!("Error in {} - {}", name, e);
- };
- });
+ match plugin.execute(server, &message) {
+ ExecutionStatus::Done => (),
+ ExecutionStatus::Err(e) => error!("Error in {} - {}", name, e),
+ ExecutionStatus::RequiresThread => {
+
+ debug!("Spawning thread to execute {} with {}",
+ name,
+ message.to_string().replace("\r\n", ""));
+
+ // Clone everything before the move - the server uses an Arc internally too
+ let plugin = Arc::clone(&plugin);
+ let message = Arc::clone(&message);
+ let server = server.clone();
+
+ // Execute the plugin in another thread
+ spawn(move || {
+ if let Err(e) = plugin.execute_threaded(&server, &message) {
+ error!("Error in {} - {}", name, e);
+ };
+ });
+ }
}
}
}