diff --git a/Cargo.lock b/Cargo.lock index 020b5eb..a303538 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1522,7 +1522,7 @@ dependencies = [ [[package]] name = "shibe-bot" -version = "0.2.3" +version = "0.2.4" dependencies = [ "build-time", "dotenv", diff --git a/Cargo.toml b/Cargo.toml index 1b5c455..aabd1fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "shibe-bot" -version = "0.2.3" +version = "0.2.4" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/README.md b/README.md index 6d9c9bd..1eedd53 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Shibe Bot 0.2.3 +# Shibe Bot 0.2.4 [![Rust](https://github.com/shibedrill/shibe-bot/actions/workflows/rust.yml/badge.svg)](https://github.com/shibedrill/shibe-bot/actions/workflows/rust.yml) [![GitHub License](https://img.shields.io/github/license/shibedrill/shibe-bot)](LICENSE.txt) ## About Shibe Bot diff --git a/src/command/fun.rs b/src/command/fun.rs index dc31234..b8521fe 100644 --- a/src/command/fun.rs +++ b/src/command/fun.rs @@ -101,7 +101,10 @@ pub async fn eightball(ctx: Context<'_>) -> Result<(), Error> { let mut rng = rand::thread_rng(); responses .choose(&mut rng) - .expect("`responses` array is empty") + .ok_or("Response array is empty".to_string()) + .inspect_err(|e| { + error!("Executing command `eightball` failed: {}", e) + })? }; ctx.say(format!("Magic 8-ball says: '{}'", *response)) .await?; @@ -141,7 +144,10 @@ pub async fn deer(ctx: Context<'_>) -> Result<(), Error> { hot.data .children .choose(&mut rng) - .ok_or("Unable to get any hot posts.")? + .ok_or("Unable to get any hot posts") + .inspect_err(|e| { + error!("Executing command `deer` failed: {}", e) + })? }; ctx.say(format!("https://reddit.com{}", &chosen_post.data.permalink)) .await?; diff --git a/src/command/util.rs b/src/command/util.rs index b398069..f93ae32 100644 --- a/src/command/util.rs +++ b/src/command/util.rs @@ -48,7 +48,7 @@ pub async fn info(ctx: Context<'_>) -> Result<(), Error> { Source code: \n\ Poise: \n\ Rust: ", - env!("CARGO_PKG_VERSION"), + env!("CARGO_PKG_VERSION"), rustc_version_runtime::version(), build_time_local!() )) diff --git a/src/main.rs b/src/main.rs index 5cee0d6..e027066 100644 --- a/src/main.rs +++ b/src/main.rs @@ -59,9 +59,10 @@ async fn event_handler( data: &Data, ) -> Result<(), Error> { if let FullEvent::ChannelDelete { - channel, - messages: _, - } = event { + channel, + messages: _, + } = event + { info!("Handling event type: ChannelDelete({})", channel.id); data.config_manager .lock() @@ -150,7 +151,10 @@ async fn main() { let mut client = serenity::ClientBuilder::new(token, intents) .framework(framework) .await - .expect("Unable to build client"); + .unwrap_or_else(|e| { + error!("Building client failed: {}", e); + std::process::exit(-1); + }); info!("Built client successfully"); // List the owner @@ -160,14 +164,23 @@ async fn main() { .http .get_current_application_info() .await - .expect("Could not get current application info") + .unwrap_or_else(|e| { + error!("Getting application info failed: {}", e); + std::process::exit(-1); + }) .owner - .expect("Could not get owner info") + .unwrap_or_else(|| { + error!("Getting owner info failed: `.owner` is `None`"); + std::process::exit(-1); + }) .name ); // Finally start everything. Nothing after this should be reachable normally. info!("Starting client"); - client.start().await.expect("Could not start client"); + client.start().await.unwrap_or_else(|e| { + error!("Starting client failed: {}", e); + std::process::exit(-1); + }); info!("All tasks finished, shutting down"); }