From d4822d0f28b6dbded8e72a0aea87129b14afa6b7 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Fri, 23 Oct 2020 22:07:02 -0400 Subject: [PATCH] Can't call HTTP-only endpoint anymore; add error messages --- src/main.rs | 33 +++++++++++++++++++++++---------- src/vocodes_api.rs | 2 +- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1ccd561..bd65c60 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,6 +40,7 @@ use serenity::http::AttachmentType; use std::borrow::Cow; use std::env; use std::sync::Arc; +use anyhow::Error; #[group] struct General; @@ -114,17 +115,27 @@ impl EventHandler for Handler { info!("Replaced message: {}", replaced_message); - if let Ok(response) = fetch(&replaced_message, speaker).await { - let msg = new_message.channel_id.send_message(&ctx.http, |m| { - m.content(replaced_message); - m.add_file(AttachmentType::Bytes { data: Cow::from(&response), filename: filename.to_string() }); - m - }).await; - - if let Err(reason) = msg { - warn!("Error sending message: {:?}", reason); - } + match fetch(&replaced_message, speaker).await { + Err(err) => { + warn!("Error fetching from vocodes TTS: {:?}", err); + }, + Ok(response) => { + let discord_result = new_message.channel_id.send_message(&ctx.http, |m| { + m.content(replaced_message); + m.add_file(AttachmentType::Bytes { data: Cow::from(&response), filename: filename.to_string() }); + m + }).await; + match discord_result { + Err(reason) => { + warn!("Error sending message: {:?}", reason); + }, + Ok(_) => { + info!("Message posted to discord successfully!"); + }, + } + }, } + } } @@ -142,6 +153,7 @@ async fn main() { .configure(|c| c.prefix("~")) // set the bot prefix to "~" .group(&GENERAL_GROUP); + info!("Initializing app..."); let secret_token = env::var("DISCORD_TOKEN").expect("token"); let mut client = Client::new(secret_token) @@ -155,6 +167,7 @@ async fn main() { data.insert::(client.shard_manager.clone()); } + info!("Starting Discord client..."); if let Err(reason) = client.start().await { error!("An error occurred while running the client: {:?}", reason); } diff --git a/src/vocodes_api.rs b/src/vocodes_api.rs index 442d670..dd00f83 100644 --- a/src/vocodes_api.rs +++ b/src/vocodes_api.rs @@ -6,7 +6,7 @@ use hyper::Request; use hyper_tls::HttpsConnector; use log::{error, debug, info, warn}; -const VOCODES_SPEAK_ENDPOINT : &'static str = "http://mumble.stream/speak"; +const VOCODES_SPEAK_ENDPOINT : &'static str = "https://mumble.stream/speak"; pub async fn fetch(text: &str, speaker: &str) -> AnyhowResult> { let mut request = format!("{{\"speaker\": \"{}\", \"text\": \"{}\"}}", speaker, text);