Change get_about_message to parse json

This commit is contained in:
notplants 2021-11-16 16:06:31 +01:00
parent c3d00837cb
commit 4fbc22967b
1 changed files with 10 additions and 4 deletions

View File

@ -80,7 +80,6 @@ pub struct PeerRelationship {
blocking: bool
}
/// SBOT METHODS
/// An `sbotcli` instance with associated methods for querying a Go sbot server.
@ -338,14 +337,21 @@ impl Sbot {
let output = Command::new(&self.sbotcli_path)
.arg("bytype")
.arg("--limit")
.arg("10")
.arg("1")
.arg("--reverse")
.arg("about")
.output()?;
if output.status.success() {
// TODO: figure out how to take a stream of messages, and filter down to just ones with the value we are looking for
let stdout = String::from_utf8(output.stdout)?;
let regex_string = format!(r#""{}": "(.*)""#, key);
let value = utils::regex_finder(&regex_string, &stdout)?;
let ssb_message : SsbMessageValue = serde_json::from_str(&stdout).map_err(|err| {
SbotCliError::GetAboutMsgs(format!("error deserializing ssb message while getting about message: {}", err))
})?;
let value = ssb_message.content.get(key);
match value {
Some(val) => Ok(val),
None => SbotCliError::GetAboutMsgs(format!("error parsing {} from about message: {}", key, err))
}
Ok(value)
} else {
let stderr = std::str::from_utf8(&output.stderr)?;