minor fixes

This commit is contained in:
shibedrill 2024-05-16 17:22:29 -04:00
parent 2e8a833909
commit bbca218708
5 changed files with 18 additions and 14 deletions

2
Cargo.lock generated
View File

@ -1490,7 +1490,7 @@ dependencies = [
[[package]] [[package]]
name = "shibe-bot" name = "shibe-bot"
version = "0.2.0" version = "0.2.1"
dependencies = [ dependencies = [
"dotenv", "dotenv",
"log", "log",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "shibe-bot" name = "shibe-bot"
version = "0.2.0" version = "0.2.1"
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

@ -24,14 +24,18 @@ pub async fn meow(ctx: Context<'_>) -> Result<(), Error> {
"IM GONNA MROWWWWW!!11!11!", "IM GONNA MROWWWWW!!11!11!",
"meow meow bitchass", "meow meow bitchass",
"mrrghh???", "mrrghh???",
"meow meow meow meow meow",
"mrow,,,,,",
"meow??",
"bwrrrr,,,",
]; ];
let response = { let response = {
let mut rng = rand::thread_rng(); let mut rng = rand::thread_rng();
match rng.gen_bool(0.05) { match rng.gen_bool(0.05) {
true => "woof", true => "woof",
// Will never return None. The source is staticaly defined. // Will never return None. The source is statically defined.
// We know it will always have items in it. // We know it will always have items in it.
false => meows.choose(&mut rng).unwrap(), false => meows.choose(&mut rng).expect("`meows` array is empty"),
} }
}; };
ctx.say(response).await?; ctx.say(response).await?;
@ -92,7 +96,7 @@ pub async fn eightball(ctx: Context<'_>) -> Result<(), Error> {
]; ];
let response = { let response = {
let mut rng = rand::thread_rng(); let mut rng = rand::thread_rng();
responses.choose(&mut rng).unwrap() responses.choose(&mut rng).expect("`responses` array is empty")
}; };
ctx.say(format!("Magic 8-ball says: '{}'", *response)) ctx.say(format!("Magic 8-ball says: '{}'", *response))
.await?; .await?;
@ -126,7 +130,7 @@ pub async fn deer(ctx: Context<'_>) -> Result<(), Error> {
let hot = subreddit.hot(50, Some(options)).await?; let hot = subreddit.hot(50, Some(options)).await?;
let chosen_post = { let chosen_post = {
let mut rng = rand::thread_rng(); let mut rng = rand::thread_rng();
hot.data.children.choose(&mut rng).unwrap() hot.data.children.choose(&mut rng).expect("Hot posts does not have any items")
}; };
ctx.say(format!("https://reddit.com{}", &chosen_post.data.permalink)) ctx.say(format!("https://reddit.com{}", &chosen_post.data.permalink))
.await?; .await?;

View File

@ -39,8 +39,8 @@ pub async fn age(
pub async fn info(ctx: Context<'_>) -> Result<(), Error> { pub async fn info(ctx: Context<'_>) -> Result<(), Error> {
ctx.say(format!( ctx.say(format!(
"Shibe Bot v{} was created by Shibe Drill (@shibedrill) using Rust and \ "Shibe Bot v{} was created by Shibe Drill (@shibedrill) using Rust and \
Poise.\nVisit her website: <https://riverdev.carrd.co>\nCheck out her \ Poise.\nWebsite: <https://riverdev.carrd.co>\n\
Github: <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")
@ -59,7 +59,7 @@ pub async fn add_channel(
let config = &mut ctx.data().config_manager.lock().await; let config = &mut ctx.data().config_manager.lock().await;
let channel_id = { u64::from(channel.id()) }; let channel_id = { u64::from(channel.id()) };
config.channels.push(channel); config.channels.push(channel);
config.store().unwrap(); config.store().expect("Unable to store config");
ctx.say(format!( ctx.say(format!(
"Successfully added <#{}> to the channel registry.", "Successfully added <#{}> to the channel registry.",
channel_id channel_id
@ -79,7 +79,7 @@ pub async fn remove_channel(
let config = &mut ctx.data().config_manager.lock().await; let config = &mut ctx.data().config_manager.lock().await;
let channel_id = { u64::from(channel.id()) }; let channel_id = { u64::from(channel.id()) };
config.channels.retain(|c| c.id() != channel.id()); config.channels.retain(|c| c.id() != channel.id());
config.store().unwrap(); config.store().expect("Unable to store config");
ctx.say(format!( ctx.say(format!(
"Successfully removed <#{}> from the channel registry.", "Successfully removed <#{}> from the channel registry.",
channel_id channel_id

View File

@ -125,7 +125,7 @@ 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
.unwrap(); .expect("Unable to build client");
info!("Built client successfully"); info!("Built client successfully");
// List the owner // List the owner
@ -135,14 +135,14 @@ async fn main() {
.http .http
.get_current_application_info() .get_current_application_info()
.await .await
.unwrap() .expect("Could not get current application info")
.owner .owner
.unwrap() .expect("Could not get owner info")
.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.unwrap(); client.start().await.expect("Could not start client");
info!("All tasks finished, shutting down"); info!("All tasks finished, shutting down");
} }