fix plugin command execution
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user