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,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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue