Skip to content

Commit

Permalink
Merge pull request #17 from CrawKatt/welcome_feature
Browse files Browse the repository at this point in the history
✨ feat: A new feature has been added to the Bot welcomes.
  • Loading branch information
Phosphorus-M authored Mar 25, 2024
2 parents ca41b98 + 5d69d2b commit c70ac3e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ songbird = { version = "0.3.2", features = ["serenity"] }
shuttle-static-folder = "0.28.0"
reqwest = { version = "0.11.22", features = ["json"] }
scraper = { version = "0.17.1", features = ["indexmap", "deterministic", "atomic"] }
plantita_welcomes = { git = "https://github.com/CrawKatt/plantita_welcomes.git" }
image = "0.24.7"

[dependencies.parking_lot]
version = "0.12"
Expand Down
22 changes: 20 additions & 2 deletions src/events/join.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;
use serenity::{model::prelude::*, prelude::*};
use std::convert::TryFrom;

use plantita_welcomes::create_welcome::combine_images;

pub async fn guild_member_addition(ctx: &Context, guild_id: &GuildId, member: &Member) {
if let Err(e) = _guild_member_addition(ctx, guild_id, member).await {
Expand All @@ -23,7 +23,25 @@ async fn _guild_member_addition(ctx: &Context, guild_id: &GuildId, member: &Memb
&guild_id.name(ctx).unwrap_or_else(|| "".into()),
);

let msg = msg_channel.say(&ctx, join_msg_replaced).await?;
// Download the user's avatar and create a welcome image
let avatar_url = member.user.avatar_url().unwrap_or_else(|| member.user.default_avatar_url());
let response = reqwest::get(avatar_url).await?;
let bytes = response.bytes().await?;

let img = image::load_from_memory(&bytes)?;
img.resize(256, 256, image::imageops::Lanczos3);
let mut background = image::open("./static/background.png")?;

let output_path = format!("/tmp/{}_welcome.png", member.user.name);
combine_images(&mut background, &img, 74, 74, 372)?;
background.save(output_path.as_str())?;

let msg = msg_channel.send_files(&ctx, vec![output_path.as_str()], |m| {
m.content(&join_msg_replaced)
}).await?;

// Remove the file after sending the message
std::fs::remove_file(&output_path)?;

// Convert string emoji to ReactionType to allow custom emojis
let reaction = ReactionType::try_from("👋")?;
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use config::setup::setup;
#[shuttle_runtime::main]
async fn serenity(
#[shuttle_secrets::Secrets] secret_store: SecretStore,
#[shuttle_static_folder::StaticFolder(folder = "static")] public_folder: PathBuf,
) -> shuttle_serenity::ShuttleSerenity {
let Ok(_) = color_eyre::install() else {
panic!("Failed to install color_eyre");
Expand Down
Binary file added static/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c70ac3e

Please sign in to comment.