Properly log all failed commands
This commit is contained in:
parent
ebf1f08cb2
commit
30232c529e
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1522,7 +1522,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "shibe-bot"
|
||||
version = "0.2.3"
|
||||
version = "0.2.4"
|
||||
dependencies = [
|
||||
"build-time",
|
||||
"dotenv",
|
||||
|
@ -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
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Shibe Bot 0.2.3
|
||||
# Shibe Bot 0.2.4
|
||||
[](https://github.com/shibedrill/shibe-bot/actions/workflows/rust.yml)
|
||||
[](LICENSE.txt)
|
||||
## About Shibe Bot
|
||||
|
@ -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?;
|
||||
|
23
src/main.rs
23
src/main.rs
@ -61,7 +61,8 @@ async fn event_handler(
|
||||
if let FullEvent::ChannelDelete {
|
||||
channel,
|
||||
messages: _,
|
||||
} = event {
|
||||
} = 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");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user