2024-07-27 00:11:41 +00:00
|
|
|
use clap::Subcommand;
|
|
|
|
|
use conduit::Result;
|
2024-04-20 14:44:31 -04:00
|
|
|
use ruma::events::room::message::RoomMessageEventContent;
|
|
|
|
|
|
2024-07-27 00:11:41 +00:00
|
|
|
use crate::Command;
|
2024-04-20 14:44:31 -04:00
|
|
|
|
2024-07-27 00:11:41 +00:00
|
|
|
#[derive(Debug, Subcommand)]
|
2024-04-20 17:02:24 -04:00
|
|
|
/// All the getters and iterators from src/database/key_value/appservice.rs
|
2024-07-27 00:11:41 +00:00
|
|
|
pub(crate) enum AppserviceCommand {
|
|
|
|
|
/// - Gets the appservice registration info/details from the ID as a string
|
|
|
|
|
GetRegistration {
|
|
|
|
|
/// Appservice registration ID
|
|
|
|
|
appservice_id: Box<str>,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/// - Gets all appservice registrations with their ID and registration info
|
|
|
|
|
All,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// All the getters and iterators from src/database/key_value/appservice.rs
|
|
|
|
|
pub(super) async fn process(subcommand: AppserviceCommand, context: &Command<'_>) -> Result<RoomMessageEventContent> {
|
|
|
|
|
let services = context.services;
|
|
|
|
|
|
2024-04-20 14:44:31 -04:00
|
|
|
match subcommand {
|
2024-07-27 00:11:41 +00:00
|
|
|
AppserviceCommand::GetRegistration {
|
2024-04-20 14:44:31 -04:00
|
|
|
appservice_id,
|
|
|
|
|
} => {
|
|
|
|
|
let timer = tokio::time::Instant::now();
|
2024-07-27 00:11:41 +00:00
|
|
|
let results = services
|
2024-04-20 14:44:31 -04:00
|
|
|
.appservice
|
|
|
|
|
.db
|
2024-08-08 17:18:30 +00:00
|
|
|
.get_registration(appservice_id.as_ref())
|
|
|
|
|
.await;
|
|
|
|
|
|
2024-04-22 18:53:40 -04:00
|
|
|
let query_time = timer.elapsed();
|
|
|
|
|
|
2024-06-17 10:12:44 +00:00
|
|
|
Ok(RoomMessageEventContent::notice_markdown(format!(
|
|
|
|
|
"Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```"
|
|
|
|
|
)))
|
2024-04-22 18:53:40 -04:00
|
|
|
},
|
2024-07-27 00:11:41 +00:00
|
|
|
AppserviceCommand::All => {
|
2024-04-22 18:53:40 -04:00
|
|
|
let timer = tokio::time::Instant::now();
|
2024-08-08 17:18:30 +00:00
|
|
|
let results = services.appservice.all().await;
|
2024-04-20 14:44:31 -04:00
|
|
|
let query_time = timer.elapsed();
|
|
|
|
|
|
2024-06-17 10:12:44 +00:00
|
|
|
Ok(RoomMessageEventContent::notice_markdown(format!(
|
|
|
|
|
"Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```"
|
|
|
|
|
)))
|
2024-04-20 14:44:31 -04:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|