add custom display name and avatar support

This commit is contained in:
2026-04-08 12:44:12 +03:00
parent 39b51da956
commit 0aaa0ac76a
3 changed files with 23 additions and 4 deletions

View File

@@ -15,3 +15,4 @@ machines:
deltaChat:
email: "0000000000000000@email.com"
password: "kek-a-kek"
avatar: "avatar.png"

View File

@@ -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<PathBuf>,
}
#[derive(Debug)]

View File

@@ -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:#}");