fix plugin command execution

This commit is contained in:
2026-05-10 23:22:22 +03:00
parent b3239823d0
commit cfe8d30e3b
4 changed files with 20 additions and 12 deletions

View File

@@ -12,10 +12,7 @@ use deltachat::{
message::Message,
};
use eui48::MacAddress;
use russh::{
client::AuthResult,
keys::PrivateKeyWithHashAlg,
};
use russh::{client::AuthResult, keys::PrivateKeyWithHashAlg};
use tokio::{
sync::Mutex,
time::{Instant, timeout, timeout_at},

View File

@@ -23,7 +23,7 @@ use deltachat::{
EventType, Events,
chat::{self, ChatId},
config::Config,
contact::ContactId,
contact::{Contact, ContactId},
context::Context,
message::{Message, MsgId},
securejoin,
@@ -225,7 +225,13 @@ async fn handle_message(
);
(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 chat_id = msg.get_chat_id();
let dchat_ctx = Arc::clone(&dchat_ctx);
@@ -397,6 +403,10 @@ async fn main() {
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");

View File

@@ -14,6 +14,7 @@ use tokio::sync::{Mutex, mpsc};
use crate::{BotContext, paths::plugins_path, proto};
#[derive(Debug)]
pub(crate) struct PluginCommand {
pub plugin_id: String,
pub name: String,
@@ -22,7 +23,7 @@ pub(crate) struct PluginCommand {
pub description: String,
}
#[derive(Default)]
#[derive(Default, Debug)]
pub(crate) struct LoadedPlugin {
pub plugin_id: String,
pub name: String,
@@ -56,7 +57,7 @@ impl Display for PluginRequestType {
}
#[async_trait]
pub(crate) trait PluginConnection: Send + Sync {
pub(crate) trait PluginConnection: Send + Sync + Debug {
async fn initialize_plugin(
&self,
config: String,
@@ -164,8 +165,8 @@ pub(crate) async fn try_load_plugin(
.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(())
}

View File

@@ -23,7 +23,6 @@ pub(super) async fn initialize_stdio_plugin(
) -> AnyhowResult<Arc<Mutex<LoadedPlugin>>> {
let plugin = Arc::new(Mutex::new(LoadedPlugin::default()));
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));
Arc::clone(&connection).run_stdio_loops();
@@ -58,6 +57,7 @@ pub(super) async fn initialize_stdio_plugin(
Ok(plugin)
}
#[derive(Debug)]
struct StdioPluginConnection {
plugin: Arc<Mutex<LoadedPlugin>>,
process: Mutex<Child>,
@@ -69,7 +69,7 @@ struct StdioPluginConnection {
impl StdioPluginConnection {
pub fn new(plugin: Arc<Mutex<LoadedPlugin>>, mut process: Child) -> StdioPluginConnection {
let stdout = process.stdout.take().unwrap();
StdioPluginConnection {
plugin,
process: Mutex::new(process),