From a14e362054c6c96ff840c7297e8b575e83f60029 Mon Sep 17 00:00:00 2001 From: seth Date: Fri, 17 Nov 2023 20:29:32 -0500 Subject: feat: put random teawie/shiggy in embed --- src/utils.rs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'src/utils.rs') diff --git a/src/utils.rs b/src/utils.rs index 780ecc9..f7f78de 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,8 +1,10 @@ -use crate::{consts, Error}; +use crate::{colors, consts, Context, Error}; +use log::*; use once_cell::sync::Lazy; use poise::serenity_prelude::GuildId; use rand::seq::SliceRandom; +use url::Url; pub fn parse_snowflake_from_env T>(key: &str, f: F) -> Option { std::env::var(key).ok().and_then(|v| v.parse().map(&f).ok()) @@ -50,3 +52,32 @@ pub fn is_guild_allowed(gid: GuildId) -> bool { ALLOWED_GUILDS.contains(&gid) } + +pub async fn send_url_as_embed(ctx: Context<'_>, url: String) -> Result<(), Error> { + match Url::parse(&url) { + Ok(parsed) => { + let title = parsed + .path_segments() + .unwrap() + .last() + .unwrap_or_else(|| "wie") + .replace("%20", " "); + + ctx.send(|c| { + c.embed(|e| { + e.title(title) + .image(&url) + .url(url) + .color(colors::Colors::Blue) + }) + }) + .await?; + } + Err(why) => { + error!("failed to parse url {}! {}", url, why); + ctx.say("i can't get that for you right now :(").await?; + } + } + + Ok(()) +} -- cgit v1.2.3