diff --git a/bot.example.yml b/bot.example.yml index 469a272..16b84f6 100644 --- a/bot.example.yml +++ b/bot.example.yml @@ -15,3 +15,4 @@ machines: deltaChat: email: "0000000000000000@email.com" password: "kek-a-kek" + avatar: "avatar.png" diff --git a/src/config.rs b/src/config.rs index af0b768..fefc177 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,6 +1,11 @@ use eui48::MacAddress; use serde::Deserialize; -use std::{collections::HashMap, fs, io, net::IpAddr, path::Path}; +use std::{ + collections::HashMap, + fs, io, + net::IpAddr, + path::{Path, PathBuf}, +}; #[derive(Deserialize, Debug)] pub struct BotConfig { @@ -39,6 +44,7 @@ pub struct BotSshAccessConfig { pub struct BotDeltaChatConfig { pub email: String, pub password: String, + pub avatar: Option, } #[derive(Debug)] diff --git a/src/main.rs b/src/main.rs index 071f74d..3deecb8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,6 +20,7 @@ const CONFIG_FILENAME: &str = "bot.yml"; const APP_NAME: &str = "deltachat-remotecontrol-bot"; const APP_CONFIG_DIR: &str = APP_NAME; const APP_DATA_DIR: &str = APP_NAME; +const BOT_DISPLAY_NAME: &str = "🤖Remote🖲️"; /// Delta Chat bot for remote control of local network machines. #[derive(Parser)] @@ -98,6 +99,20 @@ async fn run_bot(cfg: config::BotConfig) -> AnyhowResult<()> { .configure() .await .context("Failed to configure Delta Chat client")?; + + dchat_ctx + .set_config(Config::Displayname, Some(BOT_DISPLAY_NAME)) + .await?; + if let Some(mut avatar_path) = cfg.delta_chat.avatar.clone() { + if avatar_path.is_relative() { + avatar_path = data_path().join(&avatar_path); + } + if let Some(avatar_str) = avatar_path.to_str() { + dchat_ctx + .set_config(Config::Selfavatar, Some(avatar_str)) + .await?; + } + } } dchat_ctx.start_io().await; @@ -118,9 +133,6 @@ async fn run_bot(cfg: config::BotConfig) -> AnyhowResult<()> { while let Some(ev) = ev_emitter.recv().await { match ev.typ { EventType::IncomingMsg { chat_id: _, msg_id } => { - // let dchat_ctx = dchat_ctx.clone(); - // let bot_context = Arc::clone(&bot_context); - if let Err(e) = handle_message(dchat_ctx.clone(), bot_context.clone(), msg_id).await { eprintln!("Error in message handler: {e:#}");