-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(welcome-banner): refactor welcome event * feat(welcome-banner): send dm with information * feat(welcome-banner): added information message * feat(welcome-banner): added information
- Loading branch information
1 parent
34e15bc
commit e0e2f3f
Showing
6 changed files
with
107 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ mod router; | |
mod state; | ||
mod utils; | ||
mod wallet; | ||
mod welcome; | ||
|
||
use std::sync::Arc; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use std::path::Path; | ||
|
||
use chrono::Utc; | ||
use serenity::all::{Context, GuildId, Member}; | ||
use tracing::log::error as log_error; | ||
|
||
use crate::{consts, utils}; | ||
|
||
pub async fn send_welcome_banner(guild_id: &GuildId, ctx: &Context, member: &Member) { | ||
let response = reqwest::get(member.face()).await.unwrap(); | ||
let avatar = response.bytes().await.unwrap(); | ||
|
||
let position_number = guild_id | ||
.to_guild_cached(&ctx) | ||
.map(|g| g.member_count as usize) | ||
.unwrap_or(1); | ||
|
||
let output_path = format!("/tmp/{}_welcome.png", member.user.name); | ||
|
||
let dt = Utc::now(); | ||
let timestamp: String = dt.timestamp().to_string(); | ||
|
||
let digits: Vec<_> = timestamp | ||
.chars() | ||
.map(|d| d.to_digit(10).unwrap_or(5)) | ||
.collect(); | ||
|
||
let random_number = *digits.last().unwrap_or(&5); | ||
|
||
let banner = if random_number > 3 { | ||
"./assets/banner.png" | ||
} else { | ||
"./assets/pride_banner.png" | ||
}; | ||
|
||
if let Err(err) = gen_image::generate( | ||
&avatar, | ||
banner, | ||
member.distinct(), | ||
position_number, | ||
&output_path, | ||
include_bytes!("../../assets/fonts/Roboto-Bold.ttf"), | ||
include_bytes!("../../assets/fonts/Roboto-Regular.ttf"), | ||
) { | ||
log_error!("{err:?}"); | ||
} | ||
|
||
let send_result = utils::send_file_message_to_channel( | ||
&ctx.http, | ||
consts::WELCOME_CHANNEL_ID, | ||
&format!("Bienvenido a este humilde servidor: <@{}>", member.user.id), | ||
Path::new(&output_path), | ||
) | ||
.await; | ||
|
||
if let Err(err) = send_result { | ||
log_error!("{err:?}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use serenity::all::{Context, User, UserId}; | ||
use tracing::error; | ||
|
||
use crate::consts; | ||
|
||
pub async fn send_dm_welcome_information(ctx: &Context, user: &User) { | ||
match user.create_dm_channel(&ctx.http).await { | ||
Ok(channel) => { | ||
channel | ||
.say(&ctx.http, generate_welcome_information(user.id)) | ||
.await | ||
.unwrap(); | ||
} | ||
Err(err) => { | ||
error!("{err:?}"); | ||
} | ||
} | ||
} | ||
|
||
fn generate_welcome_information(user_id: UserId) -> String { | ||
let github_information = format!( | ||
"🌟 **Proyectos de la comunidad** 🌟\n\ | ||
Tu participación es clave para el éxito de nuestra comunidad. Si quieres colaborar y formar parte de nuestros proyectos, puedes colaborar en nuestros [repositorios]({}).\n\ | ||
Aquí podrás contribuir con tus habilidades, ideas y participar activamente en el crecimiento de nuestra comunidad, así podrás desbloquear el badge de `colaborador`.\n", consts::GITHUB_ORGANIZATION | ||
); | ||
|
||
let wallet_information = String::from( | ||
"🔗 **Wallet**:\n\ | ||
Aquí te dejamos información importante sobre cómo interactuar con la wallet interna del servidor a través de comandos.\n\n\ | ||
* `/register_wallet`: ¡Registra tu wallet personal!\n\ | ||
* `/donate_coins`: Si alguien del servidor te ha ayudado en algo, puedes donarle **chad-coins** para mostrarle tu gratitud. ¡Cada contribución es muy apreciada!\n\ | ||
* `/wallet_info`: Para ver el estado de tu wallet\n\ | ||
* `/wallet_leaderboard`: ¡Descubre quién lidera la lista de wallets con más dinero! ¿Serás tú el próximo en llegar a la cima?\n\n\ | ||
Recuerda registrarte primero en la wallet y cada semana se te acreditarán **chad-coins** (solo válido dentro del servidor) ¡Estamos emocionados de que formes parte!" | ||
); | ||
|
||
format!( | ||
"🎉 **Bienvenido/a: ** <@{}> 🎉\nTe dejamos presente la siguiente información: \n\n{github_information}\n\n{wallet_information}", | ||
user_id | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod banner; | ||
pub mod info; |