protocol: fix panic in chat formatting, closes #505 (#506)

* remove panic on chat thing

* fmt
This commit is contained in:
Kezi 2021-03-04 04:28:43 +01:00 committed by GitHub
parent d7b7216315
commit e3845a0dbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 5 deletions

View File

@ -43,8 +43,8 @@ impl Component {
})
} else if v.get("text").is_some() {
Component::Text(TextComponent::from_value(v, modifier))
} else if v.get("translate").is_some() {
let translate_key = v.get("translate").unwrap().as_str().unwrap();
} else if let Some(translate) = v.get("translate") {
let translate_key = translate.as_str().unwrap_or_default();
if let Some(serde_json::Value::Array(args)) = v.get("with") {
// TODO: recursively build components, avoid throwing away all but "text"
let text_args: Vec<&str> = args
@ -56,14 +56,18 @@ impl Component {
if let Some(serde_json::Value::Array(extra)) = obj.get("extra") {
if let Some(item) = extra.get(0) {
if let Some(text) = item.get("text") {
return text.as_str().unwrap();
return text.as_str().unwrap_or_default();
}
}
}
obj.get("text").unwrap().as_str().unwrap()
if let Some(text) = obj.get("text") {
text.as_str().unwrap_or_default()
} else {
Default::default()
}
} else {
v.as_str().unwrap()
v.as_str().unwrap_or_default()
}
})
.collect();