diff --git a/src/api/prism_meta.rs b/src/api/prism_meta.rs index de6c04b..f59e126 100644 --- a/src/api/prism_meta.rs +++ b/src/api/prism_meta.rs @@ -1,6 +1,6 @@ use crate::api::REQWEST_CLIENT; -use eyre::{eyre, Context, Result}; +use eyre::{eyre, Context, OptionExt, Result}; use log::debug; use reqwest::StatusCode; use serde::{Deserialize, Serialize}; @@ -30,12 +30,12 @@ pub async fn get_latest_minecraft_version() -> Result { let data = resp .json::() .await - .wrap_err_with(|| "Couldn't parse Minecraft versions!")?; + .wrap_err("Couldn't parse Minecraft versions!")?; let version = data .recommended .first() - .ok_or_else(|| eyre!("Couldn't find latest version of Minecraft!"))?; + .ok_or_eyre("Couldn't find latest version of Minecraft!")?; Ok(version.clone()) } else { diff --git a/src/api/rory.rs b/src/api/rory.rs index 7e2a1a6..e6ae45d 100644 --- a/src/api/rory.rs +++ b/src/api/rory.rs @@ -21,13 +21,13 @@ pub async fn get(id: Option) -> Result { let req = REQWEST_CLIENT .get(format!("{RORY}{ENDPOINT}/{target}")) .build() - .wrap_err_with(|| "Couldn't build reqwest client!")?; + .wrap_err("Couldn't build reqwest client!")?; debug!("Making request to {}", req.url()); let resp = REQWEST_CLIENT .execute(req) .await - .wrap_err_with(|| "Couldn't make request for rory!")?; + .wrap_err("Couldn't make request for rory!")?; let status = resp.status(); @@ -35,7 +35,7 @@ pub async fn get(id: Option) -> Result { let data = resp .json::() .await - .wrap_err_with(|| "Couldn't parse the rory response!")?; + .wrap_err("Couldn't parse the rory response!")?; Ok(data) } else { diff --git a/src/commands/general/members.rs b/src/commands/general/members.rs index adbd5c2..5387681 100644 --- a/src/commands/general/members.rs +++ b/src/commands/general/members.rs @@ -1,16 +1,13 @@ use crate::{consts, Context}; -use eyre::{eyre, Result}; +use eyre::{OptionExt, Result}; use poise::serenity_prelude::CreateEmbed; use poise::CreateReply; /// Returns the number of members in the server #[poise::command(slash_command, prefix_command)] pub async fn members(ctx: Context<'_>) -> Result<()> { - let guild = ctx - .guild() - .ok_or_else(|| eyre!("Couldn't fetch guild!"))? - .to_owned(); + let guild = ctx.guild().ok_or_eyre("Couldn't fetch guild!")?.to_owned(); let count = guild.member_count; let online = if let Some(count) = guild.approximate_presence_count { diff --git a/src/commands/general/say.rs b/src/commands/general/say.rs index 645cf4e..1413b60 100644 --- a/src/commands/general/say.rs +++ b/src/commands/general/say.rs @@ -1,6 +1,6 @@ use crate::Context; -use eyre::{eyre, Result}; +use eyre::{OptionExt, Result}; use poise::serenity_prelude::{CreateEmbed, CreateEmbedAuthor, CreateMessage}; /// Say something through the bot @@ -12,14 +12,11 @@ use poise::serenity_prelude::{CreateEmbed, CreateEmbedAuthor, CreateMessage}; required_permissions = "MODERATE_MEMBERS" )] pub async fn say(ctx: Context<'_>, #[description = "Just content?"] content: String) -> Result<()> { - let guild = ctx - .guild() - .ok_or_else(|| eyre!("Couldn't get guild!"))? - .to_owned(); + let guild = ctx.guild().ok_or_eyre("Couldn't get guild!")?.to_owned(); let channel = ctx .guild_channel() .await - .ok_or_else(|| eyre!("Couldn't get channel!"))?; + .ok_or_eyre("Couldn't get channel!")?; ctx.defer_ephemeral().await?; channel.say(ctx, &content).await?; @@ -30,7 +27,7 @@ pub async fn say(ctx: Context<'_>, #[description = "Just content?"] content: Str .channels .iter() .find(|c| c.0 == &channel_id) - .ok_or_else(|| eyre!("Couldn't get log channel from guild!"))?; + .ok_or_eyre("Couldn't get log channel from guild!")?; let author = CreateEmbedAuthor::new(ctx.author().tag()) .icon_url(ctx.author().avatar_url().unwrap_or("Undefined".to_string())); diff --git a/src/commands/general/stars.rs b/src/commands/general/stars.rs index 2cd9013..ecb4051 100644 --- a/src/commands/general/stars.rs +++ b/src/commands/general/stars.rs @@ -13,7 +13,7 @@ pub async fn stars(ctx: Context<'_>) -> Result<()> { .repos("PrismLauncher", "PrismLauncher") .get() .await - .wrap_err_with(|| "Couldn't get PrismLauncher/PrismLauncher from GitHub!")?; + .wrap_err("Couldn't get PrismLauncher/PrismLauncher from GitHub!")?; let count = if let Some(count) = prismlauncher.stargazers_count { count.to_string() diff --git a/src/commands/general/tag.rs b/src/commands/general/tag.rs index a636ad5..ccf1325 100644 --- a/src/commands/general/tag.rs +++ b/src/commands/general/tag.rs @@ -3,7 +3,7 @@ use crate::tags::Tag; use crate::{consts, Context}; use std::env; -use eyre::{eyre, Result}; +use eyre::{OptionExt, Result}; use once_cell::sync::Lazy; use poise::serenity_prelude::{Color, CreateEmbed, User}; use poise::CreateReply; @@ -22,7 +22,7 @@ pub async fn tag( let tag = TAGS .iter() .find(|t| t.file_name == tag_file) - .ok_or_else(|| eyre!("Tried to get non-existent tag: {tag_file}"))?; + .ok_or_eyre("Tried to get non-existent tag: {tag_file}")?; let frontmatter = &tag.frontmatter; diff --git a/src/handlers/event/analyze_logs/providers/paste_gg.rs b/src/handlers/event/analyze_logs/providers/paste_gg.rs index 92063b9..de7cd04 100644 --- a/src/handlers/event/analyze_logs/providers/paste_gg.rs +++ b/src/handlers/event/analyze_logs/providers/paste_gg.rs @@ -1,6 +1,6 @@ use crate::api::REQWEST_CLIENT; -use eyre::{eyre, Result}; +use eyre::{eyre, OptionExt, Result}; use once_cell::sync::Lazy; use regex::Regex; use reqwest::StatusCode; @@ -48,7 +48,7 @@ pub async fn find(content: &str) -> Result> { let paste_files: PasteResponse = resp.json().await?; let file_id = &paste_files .result - .ok_or_else(|| eyre!("Couldn't find any files associated with paste {paste_id}!"))?[0] + .ok_or_eyre("Couldn't find any files associated with paste {paste_id}!")?[0] .id; let raw_url = format!("{PASTE_GG}{PASTES_ENDPOINT}/{paste_id}/files/{file_id}/raw"); diff --git a/src/handlers/event/delete_on_reaction.rs b/src/handlers/event/delete_on_reaction.rs index a15e113..671a608 100644 --- a/src/handlers/event/delete_on_reaction.rs +++ b/src/handlers/event/delete_on_reaction.rs @@ -5,12 +5,12 @@ pub async fn handle(ctx: &Context, reaction: &Reaction) -> Result<()> { let user = reaction .user(ctx) .await - .wrap_err_with(|| "Couldn't fetch user from reaction!")?; + .wrap_err("Couldn't fetch user from reaction!")?; let message = reaction .message(ctx) .await - .wrap_err_with(|| "Couldn't fetch message from reaction!")?; + .wrap_err("Couldn't fetch message from reaction!")?; if let Some(interaction) = &message.interaction { if interaction.kind == InteractionType::Command diff --git a/src/handlers/event/support_onboard.rs b/src/handlers/event/support_onboard.rs index 4308de6..2d9fc52 100644 --- a/src/handlers/event/support_onboard.rs +++ b/src/handlers/event/support_onboard.rs @@ -1,4 +1,4 @@ -use eyre::{eyre, Result}; +use eyre::{eyre, OptionExt, Result}; use log::debug; use poise::serenity_prelude::{ ChannelType, Context, CreateAllowedMentions, CreateMessage, GuildChannel, @@ -24,7 +24,7 @@ pub async fn handle(ctx: &Context, thread: &GuildChannel) -> Result<()> { let owner = thread .owner_id - .ok_or_else(|| eyre!("Couldn't get owner of thread!"))?; + .ok_or_eyre("Couldn't get owner of thread!")?; let msg = format!( "<@{}> We've received your support ticket! {} {}", diff --git a/src/main.rs b/src/main.rs index 6a8825f..6c60d49 100644 --- a/src/main.rs +++ b/src/main.rs @@ -90,8 +90,8 @@ async fn main() -> Result<()> { color_eyre::install()?; env_logger::init(); - let token = std::env::var("DISCORD_BOT_TOKEN") - .wrap_err_with(|| "Couldn't find bot token in environment!")?; + let token = + std::env::var("DISCORD_BOT_TOKEN").wrap_err("Couldn't find bot token in environment!")?; let intents = serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT;