Finish refactoring
This commit is contained in:
@@ -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");
|
||||
}
|
||||
@@ -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:?}");
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@@ -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
@@ -1 +1,2 @@
|
||||
pub mod events;
|
||||
pub mod images;
|
||||
pub mod sanitizing;
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user