Use struct for passing module arguments: matrix
This commit is contained in:
parent
ee3a9c41ba
commit
bace7ef138
3 changed files with 21 additions and 8 deletions
|
@ -12,6 +12,12 @@ use matrix_sdk::{
|
|||
Client,
|
||||
};
|
||||
|
||||
pub struct MatrixArgs {
|
||||
pub username: String,
|
||||
pub password: String,
|
||||
pub device_id: Option<String>,
|
||||
}
|
||||
|
||||
fn open(param: String) {
|
||||
use std::io::{self, Write};
|
||||
use std::process::Command;
|
||||
|
@ -80,8 +86,8 @@ async fn client_login(username: String, password: String, device_id: Option<Stri
|
|||
}
|
||||
|
||||
#[tokio::main]
|
||||
pub async fn matrix(username: String, password: String, device_id: Option<String>) {
|
||||
let client = client_login(username, password, device_id).await;
|
||||
pub async fn matrix(args: MatrixArgs) {
|
||||
let client = client_login(args.username, args.password, args.device_id).await;
|
||||
client.sync_once(SyncSettings::default()).await.unwrap();
|
||||
client.add_event_handler(on_room_message);
|
||||
client.add_event_handler(on_room_invite);
|
||||
|
|
|
@ -18,12 +18,8 @@ fn main() {
|
|||
}
|
||||
#[cfg(feature = "matrix")]
|
||||
cli::Command::Matrix(_) => {
|
||||
let matrix = config.get::<cli::Matrix>("matrix").unwrap();
|
||||
labadoor_matrix::matrix(
|
||||
matrix.username.unwrap(),
|
||||
matrix.password.unwrap(),
|
||||
matrix.device_id,
|
||||
);
|
||||
let matrix = config.get::<cli::Matrix>("matrix").unwrap().to_config();
|
||||
labadoor_matrix::matrix(matrix);
|
||||
}
|
||||
#[cfg(feature = "csv")]
|
||||
cli::Command::CSV(_) => {
|
||||
|
|
|
@ -12,3 +12,14 @@ impl ToConfig<labadoor_telegram::TelegramArgs> for Telegram {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "matrix")]
|
||||
impl ToConfig<labadoor_matrix::MatrixArgs> for Matrix {
|
||||
fn to_config(&self) -> labadoor_matrix::MatrixArgs {
|
||||
labadoor_matrix::MatrixArgs {
|
||||
username: self.username.clone().unwrap(),
|
||||
password: self.password.clone().unwrap(),
|
||||
device_id: self.device_id.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue