2020-11-22 21:30:24 +00:00
|
|
|
use super::{Command, Execution};
|
|
|
|
use crate::context::Context;
|
|
|
|
use crate::db::errors::DataError;
|
|
|
|
use async_trait::async_trait;
|
2020-11-29 21:03:45 +00:00
|
|
|
use matrix_sdk::identifiers::UserId;
|
2020-11-22 21:30:24 +00:00
|
|
|
|
|
|
|
pub struct ResyncCommand;
|
|
|
|
|
|
|
|
type ResyncResult = Result<(), DataError>;
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
impl Command for ResyncCommand {
|
|
|
|
fn name(&self) -> &'static str {
|
|
|
|
"resync room information"
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn execute(&self, ctx: &Context<'_>) -> Execution {
|
2020-11-23 19:54:16 +00:00
|
|
|
let our_username: Option<UserId> = ctx.matrix_client.user_id().await;
|
|
|
|
let our_username: &str = our_username.as_ref().map_or("", UserId::as_str);
|
2020-11-22 22:13:11 +00:00
|
|
|
|
2020-11-29 21:18:41 +00:00
|
|
|
let result: ResyncResult = crate::bot::event_handlers::record_room_information(
|
|
|
|
ctx.matrix_client,
|
|
|
|
&ctx.db,
|
|
|
|
&ctx.room,
|
|
|
|
our_username,
|
|
|
|
)
|
|
|
|
.await;
|
2020-11-22 21:30:24 +00:00
|
|
|
|
|
|
|
let (plain, html) = match result {
|
|
|
|
Ok(()) => {
|
|
|
|
let plain = "Room information resynced".to_string();
|
|
|
|
let html = "<p>Room information resynced.</p>".to_string();
|
|
|
|
(plain, html)
|
|
|
|
}
|
|
|
|
Err(e) => {
|
|
|
|
let plain = format!("Error: {}", e);
|
|
|
|
let html = format!("<p><strong>Error:</strong> {}</p>", e);
|
|
|
|
(plain, html)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Execution { plain, html }
|
|
|
|
}
|
|
|
|
}
|