Properly log all failed commands

This commit is contained in:
August 2024-09-30 15:12:29 -04:00
parent ebf1f08cb2
commit 30232c529e
Signed by: shibedrill
GPG Key ID: 5FE0CB25945EFAA2
6 changed files with 32 additions and 13 deletions

2
Cargo.lock generated
View File

@ -1522,7 +1522,7 @@ dependencies = [
[[package]] [[package]]
name = "shibe-bot" name = "shibe-bot"
version = "0.2.3" version = "0.2.4"
dependencies = [ dependencies = [
"build-time", "build-time",
"dotenv", "dotenv",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "shibe-bot" name = "shibe-bot"
version = "0.2.3" version = "0.2.4"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -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) [![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) [![GitHub License](https://img.shields.io/github/license/shibedrill/shibe-bot)](LICENSE.txt)
## About Shibe Bot ## About Shibe Bot

View File

@ -101,7 +101,10 @@ pub async fn eightball(ctx: Context<'_>) -> Result<(), Error> {
let mut rng = rand::thread_rng(); let mut rng = rand::thread_rng();
responses responses
.choose(&mut rng) .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)) ctx.say(format!("Magic 8-ball says: '{}'", *response))
.await?; .await?;
@ -141,7 +144,10 @@ pub async fn deer(ctx: Context<'_>) -> Result<(), Error> {
hot.data hot.data
.children .children
.choose(&mut rng) .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)) ctx.say(format!("https://reddit.com{}", &chosen_post.data.permalink))
.await?; .await?;

View File

@ -48,7 +48,7 @@ pub async fn info(ctx: Context<'_>) -> Result<(), Error> {
Source code: <https://github.com/shibedrill/shibe-bot>\n\ Source code: <https://github.com/shibedrill/shibe-bot>\n\
Poise: <https://docs.rs/poise/latest/poise/>\n\ Poise: <https://docs.rs/poise/latest/poise/>\n\
Rust: <https://www.rust-lang.org/>", Rust: <https://www.rust-lang.org/>",
env!("CARGO_PKG_VERSION"), env!("CARGO_PKG_VERSION"),
rustc_version_runtime::version(), rustc_version_runtime::version(),
build_time_local!() build_time_local!()
)) ))

View File

@ -59,9 +59,10 @@ async fn event_handler(
data: &Data, data: &Data,
) -> Result<(), Error> { ) -> Result<(), Error> {
if let FullEvent::ChannelDelete { if let FullEvent::ChannelDelete {
channel, channel,
messages: _, messages: _,
} = event { } = event
{
info!("Handling event type: ChannelDelete({})", channel.id); info!("Handling event type: ChannelDelete({})", channel.id);
data.config_manager data.config_manager
.lock() .lock()
@ -150,7 +151,10 @@ async fn main() {
let mut client = serenity::ClientBuilder::new(token, intents) let mut client = serenity::ClientBuilder::new(token, intents)
.framework(framework) .framework(framework)
.await .await
.expect("Unable to build client"); .unwrap_or_else(|e| {
error!("Building client failed: {}", e);
std::process::exit(-1);
});
info!("Built client successfully"); info!("Built client successfully");
// List the owner // List the owner
@ -160,14 +164,23 @@ async fn main() {
.http .http
.get_current_application_info() .get_current_application_info()
.await .await
.expect("Could not get current application info") .unwrap_or_else(|e| {
error!("Getting application info failed: {}", e);
std::process::exit(-1);
})
.owner .owner
.expect("Could not get owner info") .unwrap_or_else(|| {
error!("Getting owner info failed: `.owner` is `None`");
std::process::exit(-1);
})
.name .name
); );
// Finally start everything. Nothing after this should be reachable normally. // Finally start everything. Nothing after this should be reachable normally.
info!("Starting client"); 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"); info!("All tasks finished, shutting down");
} }