slightly refactor appservice registration command
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
e9fee04eef
commit
6ccfc9ed98
2 changed files with 18 additions and 12 deletions
|
@ -11,19 +11,25 @@ pub(super) async fn register(&self) -> Result<RoomMessageEventContent> {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let appservice_config = self.body[1..self.body.len().checked_sub(1).unwrap()].join("\n");
|
let appservice_config_body = self.body[1..self.body.len().checked_sub(1).unwrap()].join("\n");
|
||||||
let parsed_config = serde_yaml::from_str::<Registration>(&appservice_config);
|
let parsed_config = serde_yaml::from_str::<Registration>(&appservice_config_body);
|
||||||
match parsed_config {
|
match parsed_config {
|
||||||
Ok(yaml) => match self.services.appservice.register_appservice(yaml).await {
|
Ok(registration) => match self
|
||||||
Ok(id) => Ok(RoomMessageEventContent::text_plain(format!(
|
.services
|
||||||
"Appservice registered with ID: {id}."
|
.appservice
|
||||||
|
.register_appservice(®istration, &appservice_config_body)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(()) => Ok(RoomMessageEventContent::text_plain(format!(
|
||||||
|
"Appservice registered with ID: {}",
|
||||||
|
registration.id
|
||||||
))),
|
))),
|
||||||
Err(e) => Ok(RoomMessageEventContent::text_plain(format!(
|
Err(e) => Ok(RoomMessageEventContent::text_plain(format!(
|
||||||
"Failed to register appservice: {e}"
|
"Failed to register appservice: {e}"
|
||||||
))),
|
))),
|
||||||
},
|
},
|
||||||
Err(e) => Ok(RoomMessageEventContent::text_plain(format!(
|
Err(e) => Ok(RoomMessageEventContent::text_plain(format!(
|
||||||
"Could not parse appservice config: {e}"
|
"Could not parse appservice config as YAML: {e}"
|
||||||
))),
|
))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,18 +61,18 @@ impl crate::Service for Service {
|
||||||
|
|
||||||
impl Service {
|
impl Service {
|
||||||
/// Registers an appservice and returns the ID to the caller
|
/// Registers an appservice and returns the ID to the caller
|
||||||
pub async fn register_appservice(&self, yaml: Registration) -> Result<String> {
|
pub async fn register_appservice(&self, registration: &Registration, appservice_config_body: &str) -> Result {
|
||||||
//TODO: Check for collisions between exclusive appservice namespaces
|
//TODO: Check for collisions between exclusive appservice namespaces
|
||||||
self.registration_info
|
self.registration_info
|
||||||
.write()
|
.write()
|
||||||
.await
|
.await
|
||||||
.insert(yaml.id.clone(), yaml.clone().try_into()?);
|
.insert(registration.id.clone(), registration.clone().try_into()?);
|
||||||
|
|
||||||
let id = yaml.id.as_str();
|
self.db
|
||||||
let yaml = serde_yaml::to_string(&yaml)?;
|
.id_appserviceregistrations
|
||||||
self.db.id_appserviceregistrations.insert(id, yaml);
|
.insert(®istration.id, appservice_config_body);
|
||||||
|
|
||||||
Ok(id.to_owned())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove an appservice registration
|
/// Remove an appservice registration
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue