add custom display name and avatar support
This commit is contained in:
@@ -15,3 +15,4 @@ machines:
|
|||||||
deltaChat:
|
deltaChat:
|
||||||
email: "0000000000000000@email.com"
|
email: "0000000000000000@email.com"
|
||||||
password: "kek-a-kek"
|
password: "kek-a-kek"
|
||||||
|
avatar: "avatar.png"
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
use eui48::MacAddress;
|
use eui48::MacAddress;
|
||||||
use serde::Deserialize;
|
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)]
|
#[derive(Deserialize, Debug)]
|
||||||
pub struct BotConfig {
|
pub struct BotConfig {
|
||||||
@@ -39,6 +44,7 @@ pub struct BotSshAccessConfig {
|
|||||||
pub struct BotDeltaChatConfig {
|
pub struct BotDeltaChatConfig {
|
||||||
pub email: String,
|
pub email: String,
|
||||||
pub password: String,
|
pub password: String,
|
||||||
|
pub avatar: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|||||||
18
src/main.rs
18
src/main.rs
@@ -20,6 +20,7 @@ const CONFIG_FILENAME: &str = "bot.yml";
|
|||||||
const APP_NAME: &str = "deltachat-remotecontrol-bot";
|
const APP_NAME: &str = "deltachat-remotecontrol-bot";
|
||||||
const APP_CONFIG_DIR: &str = APP_NAME;
|
const APP_CONFIG_DIR: &str = APP_NAME;
|
||||||
const APP_DATA_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.
|
/// Delta Chat bot for remote control of local network machines.
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
@@ -98,6 +99,20 @@ async fn run_bot(cfg: config::BotConfig) -> AnyhowResult<()> {
|
|||||||
.configure()
|
.configure()
|
||||||
.await
|
.await
|
||||||
.context("Failed to configure Delta Chat client")?;
|
.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;
|
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 {
|
while let Some(ev) = ev_emitter.recv().await {
|
||||||
match ev.typ {
|
match ev.typ {
|
||||||
EventType::IncomingMsg { chat_id: _, msg_id } => {
|
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
|
if let Err(e) = handle_message(dchat_ctx.clone(), bot_context.clone(), msg_id).await
|
||||||
{
|
{
|
||||||
eprintln!("Error in message handler: {e:#}");
|
eprintln!("Error in message handler: {e:#}");
|
||||||
|
|||||||
Reference in New Issue
Block a user