refactor: ok_or_else()
-> ok_or_eyre()
This commit is contained in:
parent
fafa0bf689
commit
f4fa737124
10 changed files with 23 additions and 29 deletions
|
@ -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<String> {
|
|||
let data = resp
|
||||
.json::<MinecraftPackageJson>()
|
||||
.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 {
|
||||
|
|
|
@ -21,13 +21,13 @@ pub async fn get(id: Option<u64>) -> Result<Response> {
|
|||
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<u64>) -> Result<Response> {
|
|||
let data = resp
|
||||
.json::<Response>()
|
||||
.await
|
||||
.wrap_err_with(|| "Couldn't parse the rory response!")?;
|
||||
.wrap_err("Couldn't parse the rory response!")?;
|
||||
|
||||
Ok(data)
|
||||
} else {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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()));
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<Option<String>> {
|
|||
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");
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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! {} {}",
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue