From b58b03c22d637fe8f7200edb6953325bf359544d Mon Sep 17 00:00:00 2001 From: Nathan Perry Date: Wed, 7 Aug 2024 07:39:16 -0400 Subject: split calc into separate subcrate --- src/util/mod.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/util/mod.rs') diff --git a/src/util/mod.rs b/src/util/mod.rs index f362ff7..f959a37 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -32,7 +32,6 @@ use url::Url; use crate::{ commands::playback::songbird, PoiseContext, - Result, CONFIG, }; @@ -47,7 +46,7 @@ pub async fn currently_playing(ctx: PoiseContext<'_>) -> bool { call.queue().current().is_some() } -pub async fn users_listening(ctx: &Context) -> Result { +pub async fn users_listening(ctx: &Context) -> anyhow::Result { let channel = CONFIG.discord.voice_channel().to_channel(&ctx).await?; let res = channel @@ -100,12 +99,12 @@ pub fn err_msg<'a, U, E>(err: &'a FrameworkError) -> Option<&'a Message> { } #[inline] -pub fn tts(ctx: PoiseContext<'_>) -> Option { +pub fn tts(ctx: poise::Context<'_, U, E>) -> Option { msg(ctx).map(|msg| msg.tts) } #[inline] -pub fn unwrap_tts(ctx: PoiseContext<'_>) -> bool { +pub fn unwrap_tts(ctx: poise::Context<'_, U, E>) -> bool { tts(ctx).unwrap_or(false) } @@ -115,12 +114,15 @@ pub async fn send( channel: ChannelId, text: impl AsRef, tts: bool, -) -> Result<()> { +) -> anyhow::Result<()> { send_result(ctx, channel, text, tts).await.map(|_| ()) } #[inline] -pub async fn reply(ctx: PoiseContext<'_>, text: impl AsRef) -> Result { +pub async fn reply( + ctx: poise::Context<'_, U, E>, + text: impl AsRef, +) -> Result { let handle = poise::send_reply(ctx, CreateReply::default().tts(unwrap_tts(ctx)).content(text.as_ref())) .await?; @@ -129,7 +131,7 @@ pub async fn reply(ctx: PoiseContext<'_>, text: impl AsRef) -> Result, react: ReactionType) -> Result { +pub async fn react(ctx: PoiseContext<'_>, react: ReactionType) -> anyhow::Result { let react = msg(ctx).ok_or_else(|| anyhow::anyhow!("elp"))?.react(ctx, react).await?; Ok(react) } @@ -139,7 +141,7 @@ pub async fn send_result( channel: ChannelId, text: impl AsRef, tts: bool, -) -> Result { +) -> anyhow::Result { let text = text.as_ref(); debug!("sending message {:?} to channel {:?} (tts: {})", text, channel, tts); @@ -170,7 +172,7 @@ lazy_static! { .unwrap(); } -pub async fn ytdl_url(uri: &str) -> Result { +pub async fn ytdl_url(uri: &str) -> anyhow::Result { use serde_json::Value; use tokio::process::Command; -- cgit v1.3.1