Finish refactoring

This commit is contained in:
2025-08-10 21:15:53 -03:00
parent f123282699
commit a004fe2308
50 changed files with 2639 additions and 587 deletions
-13
View File
@@ -1,13 +0,0 @@
use twilight_model::gateway::payload::incoming::Ready;
pub async fn handle_on_ready(event: Ready) {
log::info!(
"Ready! Logged in as {}#{:>04}",
event.user.name,
event.user.discriminator
);
}
pub async fn handle_on_reconnect() {
log::info!("The gateway asked for a reconnection");
}
-11
View File
@@ -1,11 +0,0 @@
use std::sync::Arc;
use twilight_model::gateway::payload::incoming::InteractionCreate;
use crate::framework::handlers::Handlers;
pub async fn handle_on_interaction_create(event: InteractionCreate, handlers: Arc<Handlers>) {
if let Err(e) = handlers.registry.execute(event, handlers.clone()).await {
log::error!("An error occurred while processing the interaction! {e:?}");
}
}
-12
View File
@@ -1,12 +0,0 @@
use std::sync::Arc;
use twilight_model::{gateway::payload::incoming::MessageCreate};
use crate::{commands, framework::{handlers::Handlers}};
pub fn handle_on_message_create(
event: MessageCreate,
handlers: Arc<Handlers>
) -> impl Future<Output = ()> {
commands::execute_command(event, handlers)
}
-25
View File
@@ -1,25 +0,0 @@
use std::sync::Arc;
use twilight_gateway::Event;
use crate::framework::handlers::Handlers;
mod core;
mod interactions;
mod messages;
pub async fn handle_event(event: Event, handlers: Arc<Handlers>) {
log::trace!("{event:?}");
match event {
Event::Ready(event) => core::handle_on_ready(*event).await,
Event::GatewayReconnect => core::handle_on_reconnect().await,
Event::MessageCreate(event) => {
messages::handle_on_message_create(*event, handlers).await
}
Event::InteractionCreate(event) => {
interactions::handle_on_interaction_create(*event, handlers).await
}
_ => {}
}
}
+15
View File
@@ -0,0 +1,15 @@
use twilight_model::util::ImageHash;
pub fn get_avatar_url(hash: Option<ImageHash>, user_id: u64, discriminator: u64) -> String {
if let Some(hash) = hash {
format!("https://cdn.discordapp.com/avatars/{user_id}/{hash}.webp?size=256")
} else {
format!(
"https://cdn.discordapp.com/embed/avatars/{}.png?size=256",
match discriminator.to_string().as_str() {
"0" => (user_id >> 22) % 6,
_ => discriminator % 6,
}
)
}
}
+2 -1
View File
@@ -1 +1,2 @@
pub mod events;
pub mod images;
pub mod sanitizing;
+38
View File
@@ -0,0 +1,38 @@
pub trait SanitizeDiscordMarkdown {
fn sanitize(&self, hard: bool) -> String;
}
impl<T> SanitizeDiscordMarkdown for T
where
T: ToString,
{
fn sanitize(&self, hard: bool) -> String {
let input = self.to_string();
let escaped = if hard {
let mut escaped = String::with_capacity(input.len());
for ch in input.chars() {
match ch {
'\\' | '*' | '_' | '~' | '`' | '>' | '<' | '|' | '#' => {
escaped.push('\\');
escaped.push(ch);
}
_ => escaped.push(ch),
}
}
escaped
} else {
input
};
// Now block ping attempts — break mentions
escaped
.replace("@everyone", "@\u{200B}everyone")
.replace("@here", "@\u{200B}here")
.replace("<@", "<@\u{200B}") // user mentions
.replace("<@&", "<@&\u{200B}") // role mentions
.replace("<#", "<#\u{200B}") // channel mentions
}
}