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
+45
View File
@@ -0,0 +1,45 @@
use std::sync::Arc;
use async_trait::async_trait;
use twilight_model::gateway::payload::incoming::MessageCreate;
use crate::framework::{
commands::{context::CommandContext, get_command_parts},
events::traits::{EventResult, OnMessageHandler},
runtime::Runtime,
};
#[derive(Debug)]
pub struct CommandRunner;
#[async_trait]
impl<T: Send + Sync + 'static> OnMessageHandler<T> for CommandRunner {
async fn on_message(&self, event: &MessageCreate, rt: Arc<Runtime<T>>) -> EventResult {
if event.author.bot || event.author.system.unwrap_or(false) {
return Ok(());
}
let prefixes = rt
.get_prefixes(event.guild_id.map(|i| i.get()), Some(event.author.id.get()))
.await;
for prefix in prefixes {
if let Some(parts) = get_command_parts(&prefix, &event.content) {
let command = rt.commands.iter().find(|cmd| {
cmd.identifiers()
.contains(&parts.name.to_ascii_lowercase().as_str())
});
if let Some(command) = command {
command
.execute(CommandContext::new(event, rt.clone(), &prefix), parts.args)
.await?;
break;
}
}
}
Ok(())
}
}