Skip to content

Commit

Permalink
Merge pull request #108 from CrawKatt/dev
Browse files Browse the repository at this point in the history
✨ feat: Se ha añadido un nuevo comando
  • Loading branch information
CrawKatt authored Aug 19, 2024
2 parents 4d26f2d + 3e29c98 commit 223ed06
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
Binary file added assets/dumb_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions src/commands/fun/generate_dumb.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use std::fs::remove_file;

use image::DynamicImage;
use plantita_welcomes::create_welcome::combine_images;
use reqwest::get;
use serenity::all::{CreateMessage, Member, UserId};
use serenity::builder::CreateAttachment;

use crate::commands::fun::get_target_info;
use crate::utils::{CommandResult, Context};
use crate::utils::debug::UnwrapResult;

#[poise::command(
prefix_command,
category = "Fun",
guild_only,
user_cooldown = 10,
track_edits
)]
pub async fn dumb(ctx: Context<'_>, target: Option<Member>) -> CommandResult {
let (target_id, target_avatar) = get_target_info(&ctx, target).await?;
let channel_id = ctx.channel_id();
let mut background = image::open("./assets/dumb_background.png")?;
let file = generate_dumb(&mut background, target_avatar, &target_id, 800, 80, 512).await?;
let attachment = CreateAttachment::path(&file).await?;

channel_id.send_files(&ctx.http(), vec![attachment], CreateMessage::default()).await?;
remove_file(&file)?;

Ok(())
}

async fn generate_dumb(
background: &mut DynamicImage,
target_avatar_url: String,
target_id: &UserId,
x: u32,
y: u32,
avatar_size: u32
) -> UnwrapResult<String> {
// Descarga la imagen del avatar
let response = get(target_avatar_url).await?;
let bytes= response.bytes().await?;

// Carga la imagen del avatar en memoria y redimensiona a 256x256
let img = image::load_from_memory(&bytes)?;
img.resize(512, 512, image::imageops::Lanczos3);

// Guarda la imagen del avatar en un archivo temporal
let output_path = format!("/tmp/{target_id}_dumb.png");
combine_images(background, &img, x, y, avatar_size)?;
background.save(&output_path)?;

Ok(output_path)
}
1 change: 1 addition & 0 deletions src/commands/fun/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::utils::debug::{IntoUnwrapResult, UnwrapResult};
pub mod generate_furry;
pub mod screenshot_this;
pub mod generate_pride;
pub mod generate_dumb;

pub async fn get_target_info(ctx: &Context<'_>, target: Option<Member>) -> UnwrapResult<(UserId, String)> {
let guild_id = ctx.guild_id().into_result()?; // SAFETY: Si el mensaje no es de un servidor, no se ejecutará el comando
Expand Down
2 changes: 2 additions & 0 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::commands::audio::queue::queue;
use crate::commands::audio::resume::resume;
use crate::commands::audio::skip::skip;
use crate::commands::audio::stop::stop;
use crate::commands::fun::generate_dumb::dumb;
use crate::commands::fun::generate_furry::furry;
use crate::commands::fun::generate_pride::pride;
use crate::commands::fun::screenshot_this::screenshot_this;
Expand Down Expand Up @@ -212,5 +213,6 @@ pub fn load_commands() -> Vec<Command<Data, Error>> {
help(),
rust(),
ask(),
dumb(),
]
}

0 comments on commit 223ed06

Please sign in to comment.