implement plugin command execution
- change .proto file for plugins - add global usage guide for all commands - handle commands not included in the built-in set
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
pub(crate) mod args;
|
||||
|
||||
use std::{fmt::Debug, fs::File, io::Read, ops::Add, path::PathBuf, sync::Arc, time::Duration};
|
||||
use std::{fs::File, io::Read, ops::Add, path::PathBuf, sync::Arc, time::Duration};
|
||||
|
||||
use crate::{commands::args::append_port_if_needed, ssh};
|
||||
use anyhow::{Context as _, Result as AnyhowResult};
|
||||
@@ -13,15 +13,15 @@ use deltachat::{
|
||||
};
|
||||
use eui48::MacAddress;
|
||||
use russh::{
|
||||
client::{AuthResult, Handle},
|
||||
client::AuthResult,
|
||||
keys::PrivateKeyWithHashAlg,
|
||||
};
|
||||
use tokio::{
|
||||
sync::Mutex,
|
||||
time::{Instant, error::Elapsed, timeout, timeout_at},
|
||||
time::{Instant, timeout, timeout_at},
|
||||
};
|
||||
|
||||
use crate::{AUTH_REQUIRED, BotContext, config::BotConfig, data_path, ssh::ClientHandler};
|
||||
use crate::{AUTH_REQUIRED, BotContext, config::BotConfig, data_path};
|
||||
|
||||
pub async fn echo(dchat_ctx: Arc<Mutex<Context>>, msg: Message) -> AnyhowResult<()> {
|
||||
let chat_id = msg.get_chat_id();
|
||||
@@ -30,6 +30,31 @@ pub async fn echo(dchat_ctx: Arc<Mutex<Context>>, msg: Message) -> AnyhowResult<
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn global_usage(ctx: Arc<Mutex<BotContext>>) -> String {
|
||||
let ctx_lock = ctx.lock().await;
|
||||
let config = &ctx_lock.config;
|
||||
let mut usage = String::from("DeltaChat Remote Control Bot\n\nCommands:\n");
|
||||
usage += "/auth <password> - Authenticate (prove you are the bot owner or a trusted person)\n";
|
||||
usage += &wol_usage(config);
|
||||
usage += " - send Wake-on-LAN magic packet to a pre-configured (or an arbitrary) machine in the local network\n";
|
||||
usage += &ssh_unlock_disk_usage(config);
|
||||
usage += " - log into a pre-configured machine via SSH (as root) and send the password to unlock a LUKS-encrypted root partition\n";
|
||||
usage += &ssh_exec_usage(config);
|
||||
usage += " - log into a machine via SSH and execute one command. Waits until the process finishes or forcefully exits after 20 seconds\n";
|
||||
|
||||
usage += "\nCommands from plugins:\n";
|
||||
for cmd in ctx_lock.plugin_commands.values() {
|
||||
usage += &format!(
|
||||
"{} (from {}) - {}\n",
|
||||
&cmd.usage, &cmd.plugin_id, &cmd.description
|
||||
);
|
||||
}
|
||||
|
||||
usage += "\nDeltaChat Remote Control Bot by slavasil, 2026\n";
|
||||
|
||||
usage
|
||||
}
|
||||
|
||||
pub async fn auth_command(
|
||||
dchat_ctx: Arc<Mutex<Context>>,
|
||||
ctx: Arc<Mutex<BotContext>>,
|
||||
|
||||
Reference in New Issue
Block a user