main: add better error reporting for /bandcamp
This commit is contained in:
+15
-13
@@ -386,10 +386,13 @@ impl App {
|
||||
let arg = parts.next().unwrap_or("");
|
||||
match command {
|
||||
"/bandcamp" => {
|
||||
self.add_bandcamp_artifact(arg).await;
|
||||
self.sys_message_sink.send(format!("Added Bandcamp artifact from {}", arg)).await.unwrap();
|
||||
self.next_actions.push(ConversationEntry::ShipComputer(format!("Incoming transmission from {}", arg)));
|
||||
self.regenerate_responses();
|
||||
if let Err(err) = self.add_bandcamp_artifact(arg).await {
|
||||
self.sys_message_sink.send(format!("Failed to fetch artifact: {:?}", err)).await.unwrap();
|
||||
} else {
|
||||
self.sys_message_sink.send(format!("Added Bandcamp artifact from {}", arg)).await.unwrap();
|
||||
self.next_actions.push(ConversationEntry::ShipComputer(format!("Incoming transmission from {}", arg)));
|
||||
self.regenerate_responses();
|
||||
}
|
||||
},
|
||||
"/episode" => {
|
||||
if let Ok(episode_number) = arg.trim().parse::<u32>() {
|
||||
@@ -507,15 +510,14 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
async fn add_bandcamp_artifact(&mut self, url: &str) {
|
||||
if let Ok(album) = bandcamp::album_from_url(url).await {
|
||||
let result: BandcampResult = album.into();
|
||||
let json = serde_json::to_string(&result).unwrap();
|
||||
self.direction.artifacts.push(json);
|
||||
self.sys_message_sink.send("Added bandcamp album".into()).await.unwrap();
|
||||
} else {
|
||||
self.sys_message_sink.send("Could not fetch bandcamp data! Is that a proper URL?".into()).await.unwrap();
|
||||
}
|
||||
async fn add_bandcamp_artifact(&mut self, url: &str) -> Result<(), BandcampError> {
|
||||
let album = bandcamp::album_from_url(url).await?;
|
||||
let result: BandcampResult = album.into();
|
||||
let json = serde_json::to_string(&result)?;
|
||||
self.direction.artifacts.push(json);
|
||||
self.sys_message_sink.send("Added bandcamp album".into()).await.unwrap();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn speak(&mut self, text: String) {
|
||||
|
||||
Reference in New Issue
Block a user