From 6cf299ea0b080a27dc070fc95a22979d50479eb4 Mon Sep 17 00:00:00 2001 From: Anish Nayak Date: Wed, 13 Aug 2025 20:04:42 +0100 Subject: [PATCH] changed mut --- src/framework/bot.rs | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/framework/bot.rs b/src/framework/bot.rs index d7d2e4b..2b7c3e8 100644 --- a/src/framework/bot.rs +++ b/src/framework/bot.rs @@ -76,8 +76,9 @@ pub struct Bot { intents: Intents, commands: Vec>>, components: Vec>>, - message_commands: Vec>>, on_ready_handlers: Vec>>, + message_commands: Vec>>, + message_command_registry: Arc>, on_reconnect_handlers: Vec>>, on_interaction_handlers: Vec>>, on_message_handlers: Vec>>, @@ -90,6 +91,7 @@ pub struct Bot { impl Bot { pub fn new(state: T, prefixes: impl IntoPrefixes + Send + Sync + 'static) -> Self { + let message_command_registry = Arc::new(MessageCommandRegistry::new()); Self { state: Arc::new(state), prefixes: Arc::new(prefixes), @@ -97,9 +99,12 @@ impl Bot { commands: Vec::new(), components: Vec::new(), message_commands: Vec::new(), + message_command_registry: message_command_registry.clone(), on_ready_handlers: Vec::new(), on_reconnect_handlers: Vec::new(), - on_interaction_handlers: Vec::new(), // Will push MessageCommandRunner in run() + on_interaction_handlers: vec![Arc::new(MessageCommandRunner { + registry: message_command_registry, + })], on_message_handlers: vec![Arc::new(CommandRunner)], on_message_edit_handlers: Vec::new(), on_message_delete_handlers: Vec::new(), @@ -110,7 +115,9 @@ impl Bot { } pub fn message_command(mut self, command: impl MessageCommand + 'static) -> Self { - self.message_commands.push(Arc::new(command)); + let arc_command = Arc::new(command); + self.message_command_registry.register(arc_command.name(), arc_command.clone()); + self.message_commands.push(arc_command); self } @@ -195,20 +202,7 @@ impl Bot { ); } - let message_command_registry = std::sync::Arc::new(MessageCommandRegistry::new()); - for command in &self.message_commands { - message_command_registry.register(command.name(), command.clone()); - } - - let mut bot = self; - - bot.on_interaction_handlers.insert( - 0, - Arc::new(MessageCommandRunner { - registry: message_command_registry.clone(), - }), - ); - let bot = Arc::new(bot); + let bot = Arc::new(self); let runtime = Arc::new(Runtime { http,