fix plugin command execution
This commit is contained in:
@@ -12,10 +12,7 @@ use deltachat::{
|
|||||||
message::Message,
|
message::Message,
|
||||||
};
|
};
|
||||||
use eui48::MacAddress;
|
use eui48::MacAddress;
|
||||||
use russh::{
|
use russh::{client::AuthResult, keys::PrivateKeyWithHashAlg};
|
||||||
client::AuthResult,
|
|
||||||
keys::PrivateKeyWithHashAlg,
|
|
||||||
};
|
|
||||||
use tokio::{
|
use tokio::{
|
||||||
sync::Mutex,
|
sync::Mutex,
|
||||||
time::{Instant, timeout, timeout_at},
|
time::{Instant, timeout, timeout_at},
|
||||||
|
|||||||
14
src/main.rs
14
src/main.rs
@@ -23,7 +23,7 @@ use deltachat::{
|
|||||||
EventType, Events,
|
EventType, Events,
|
||||||
chat::{self, ChatId},
|
chat::{self, ChatId},
|
||||||
config::Config,
|
config::Config,
|
||||||
contact::ContactId,
|
contact::{Contact, ContactId},
|
||||||
context::Context,
|
context::Context,
|
||||||
message::{Message, MsgId},
|
message::{Message, MsgId},
|
||||||
securejoin,
|
securejoin,
|
||||||
@@ -225,7 +225,13 @@ async fn handle_message(
|
|||||||
);
|
);
|
||||||
(conn, plugin_name)
|
(conn, plugin_name)
|
||||||
};
|
};
|
||||||
let issuer_id = msg.get_from_id().to_string();
|
let contact_id = msg.get_from_id();
|
||||||
|
let dchat_ctx_lock = dchat_ctx.lock().await;
|
||||||
|
let issuer_id = Contact::get_by_id(&dchat_ctx_lock, contact_id)
|
||||||
|
.await
|
||||||
|
.map(|contact| contact.get_addr().to_string())
|
||||||
|
.unwrap_or_else(|_| contact_id.to_string());
|
||||||
|
drop(dchat_ctx_lock);
|
||||||
let cmd_name = cmd.name.clone();
|
let cmd_name = cmd.name.clone();
|
||||||
let chat_id = msg.get_chat_id();
|
let chat_id = msg.get_chat_id();
|
||||||
let dchat_ctx = Arc::clone(&dchat_ctx);
|
let dchat_ctx = Arc::clone(&dchat_ctx);
|
||||||
@@ -397,6 +403,10 @@ async fn main() {
|
|||||||
log::error!("Failed to load plugin \"{}\": {e}", &plugin.name);
|
log::error!("Failed to load plugin \"{}\": {e}", &plugin.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let ctx_lock = bot_context.lock().await;
|
||||||
|
log::debug!("Plugins: {:?}", &ctx_lock.plugins);
|
||||||
|
log::debug!("Plugin commands: {:?}", &ctx_lock.plugin_commands);
|
||||||
|
log::debug!("Plugin command aliases: {:?}", &ctx_lock.plugin_cmd_aliases);
|
||||||
}
|
}
|
||||||
|
|
||||||
run_bot(bot_context).await.expect("error");
|
run_bot(bot_context).await.expect("error");
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ use tokio::sync::{Mutex, mpsc};
|
|||||||
|
|
||||||
use crate::{BotContext, paths::plugins_path, proto};
|
use crate::{BotContext, paths::plugins_path, proto};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub(crate) struct PluginCommand {
|
pub(crate) struct PluginCommand {
|
||||||
pub plugin_id: String,
|
pub plugin_id: String,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
@@ -22,7 +23,7 @@ pub(crate) struct PluginCommand {
|
|||||||
pub description: String,
|
pub description: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default, Debug)]
|
||||||
pub(crate) struct LoadedPlugin {
|
pub(crate) struct LoadedPlugin {
|
||||||
pub plugin_id: String,
|
pub plugin_id: String,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
@@ -56,7 +57,7 @@ impl Display for PluginRequestType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub(crate) trait PluginConnection: Send + Sync {
|
pub(crate) trait PluginConnection: Send + Sync + Debug {
|
||||||
async fn initialize_plugin(
|
async fn initialize_plugin(
|
||||||
&self,
|
&self,
|
||||||
config: String,
|
config: String,
|
||||||
@@ -164,8 +165,8 @@ pub(crate) async fn try_load_plugin(
|
|||||||
.insert(alias.to_owned(), Arc::clone(&cmd));
|
.insert(alias.to_owned(), Arc::clone(&cmd));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
drop(ctx_lock);
|
|
||||||
|
|
||||||
ctx.lock().await.plugins.insert(unique_name, plugin);
|
let real_plugin_id = plugin.lock().await.plugin_id.clone();
|
||||||
|
ctx_lock.plugins.insert(real_plugin_id, plugin);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ pub(super) async fn initialize_stdio_plugin(
|
|||||||
) -> AnyhowResult<Arc<Mutex<LoadedPlugin>>> {
|
) -> AnyhowResult<Arc<Mutex<LoadedPlugin>>> {
|
||||||
let plugin = Arc::new(Mutex::new(LoadedPlugin::default()));
|
let plugin = Arc::new(Mutex::new(LoadedPlugin::default()));
|
||||||
log::info!("Connecting to plugin {} using standard I/O", &unique_name);
|
log::info!("Connecting to plugin {} using standard I/O", &unique_name);
|
||||||
plugin.lock().await.plugin_id = unique_name;
|
|
||||||
let connection = Arc::new(StdioPluginConnection::new(Arc::clone(&plugin), process));
|
let connection = Arc::new(StdioPluginConnection::new(Arc::clone(&plugin), process));
|
||||||
Arc::clone(&connection).run_stdio_loops();
|
Arc::clone(&connection).run_stdio_loops();
|
||||||
|
|
||||||
@@ -58,6 +57,7 @@ pub(super) async fn initialize_stdio_plugin(
|
|||||||
Ok(plugin)
|
Ok(plugin)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
struct StdioPluginConnection {
|
struct StdioPluginConnection {
|
||||||
plugin: Arc<Mutex<LoadedPlugin>>,
|
plugin: Arc<Mutex<LoadedPlugin>>,
|
||||||
process: Mutex<Child>,
|
process: Mutex<Child>,
|
||||||
|
|||||||
Reference in New Issue
Block a user