2024-10-06 14:53:12 +00:00
|
|
|
use anyhow::anyhow;
|
|
|
|
use serenity::all::{Colour, CreateEmbed, CreateMessage};
|
|
|
|
use tenorv2::tenor_builder::Tenor;
|
|
|
|
|
2025-01-24 20:52:13 +00:00
|
|
|
use crate::{types::Context, utils::{gifs::get_random_tenor_gif, utilities}};
|
2024-10-06 14:53:12 +00:00
|
|
|
|
2024-12-09 14:39:54 +00:00
|
|
|
/// Sends embed with random tenor gif from searched query
|
|
|
|
/// title and desc are used in the embed
|
2024-10-06 14:53:12 +00:00
|
|
|
pub(super) async fn send_with_embed(ctx: Context<'_>, query: &str, title: &str, desc: &str) -> anyhow::Result<()> {
|
|
|
|
let tenor_response = Tenor::new()?
|
|
|
|
.random(true)
|
|
|
|
.search(query).await?;
|
|
|
|
|
|
|
|
const LIMIT: u8 = 20;
|
|
|
|
let url = get_random_tenor_gif(tenor_response, LIMIT).await?;
|
|
|
|
|
|
|
|
let embed = CreateEmbed::new()
|
|
|
|
.color(Colour::new(rand::random::<u32>() % 0xFFFFFF))
|
|
|
|
.title(title)
|
|
|
|
.description(desc)
|
|
|
|
.image(url.as_str());
|
|
|
|
|
|
|
|
if ctx.guild_id().is_none() {
|
|
|
|
return Err(anyhow!("Guild id not available in context"));
|
|
|
|
}
|
|
|
|
|
|
|
|
utilities::get_system_channel(
|
|
|
|
ctx.guild_id().unwrap(), ctx.http()
|
|
|
|
).await?
|
|
|
|
.send_message(
|
|
|
|
ctx.http(),
|
|
|
|
CreateMessage::new().add_embed(embed)
|
|
|
|
).await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|