changed mut
This commit is contained in:
+11
-17
@@ -76,8 +76,9 @@ pub struct Bot<T: Send + Sync + Debug = ()> {
|
|||||||
intents: Intents,
|
intents: Intents,
|
||||||
commands: Vec<Arc<dyn Command<T>>>,
|
commands: Vec<Arc<dyn Command<T>>>,
|
||||||
components: Vec<Arc<dyn Component<T>>>,
|
components: Vec<Arc<dyn Component<T>>>,
|
||||||
message_commands: Vec<Arc<dyn MessageCommand<T>>>,
|
|
||||||
on_ready_handlers: Vec<Arc<dyn OnReadyHandler<T>>>,
|
on_ready_handlers: Vec<Arc<dyn OnReadyHandler<T>>>,
|
||||||
|
message_commands: Vec<Arc<dyn MessageCommand<T>>>,
|
||||||
|
message_command_registry: Arc<MessageCommandRegistry<T>>,
|
||||||
on_reconnect_handlers: Vec<Arc<dyn OnReconnectHandler<T>>>,
|
on_reconnect_handlers: Vec<Arc<dyn OnReconnectHandler<T>>>,
|
||||||
on_interaction_handlers: Vec<Arc<dyn OnInteractionHandler<T>>>,
|
on_interaction_handlers: Vec<Arc<dyn OnInteractionHandler<T>>>,
|
||||||
on_message_handlers: Vec<Arc<dyn OnMessageHandler<T>>>,
|
on_message_handlers: Vec<Arc<dyn OnMessageHandler<T>>>,
|
||||||
@@ -90,6 +91,7 @@ pub struct Bot<T: Send + Sync + Debug = ()> {
|
|||||||
|
|
||||||
impl<T: 'static + Send + Sync + Debug> Bot<T> {
|
impl<T: 'static + Send + Sync + Debug> Bot<T> {
|
||||||
pub fn new(state: T, prefixes: impl IntoPrefixes<T> + Send + Sync + 'static) -> Self {
|
pub fn new(state: T, prefixes: impl IntoPrefixes<T> + Send + Sync + 'static) -> Self {
|
||||||
|
let message_command_registry = Arc::new(MessageCommandRegistry::new());
|
||||||
Self {
|
Self {
|
||||||
state: Arc::new(state),
|
state: Arc::new(state),
|
||||||
prefixes: Arc::new(prefixes),
|
prefixes: Arc::new(prefixes),
|
||||||
@@ -97,9 +99,12 @@ impl<T: 'static + Send + Sync + Debug> Bot<T> {
|
|||||||
commands: Vec::new(),
|
commands: Vec::new(),
|
||||||
components: Vec::new(),
|
components: Vec::new(),
|
||||||
message_commands: Vec::new(),
|
message_commands: Vec::new(),
|
||||||
|
message_command_registry: message_command_registry.clone(),
|
||||||
on_ready_handlers: Vec::new(),
|
on_ready_handlers: Vec::new(),
|
||||||
on_reconnect_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_handlers: vec![Arc::new(CommandRunner)],
|
||||||
on_message_edit_handlers: Vec::new(),
|
on_message_edit_handlers: Vec::new(),
|
||||||
on_message_delete_handlers: Vec::new(),
|
on_message_delete_handlers: Vec::new(),
|
||||||
@@ -110,7 +115,9 @@ impl<T: 'static + Send + Sync + Debug> Bot<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn message_command(mut self, command: impl MessageCommand<T> + 'static) -> Self {
|
pub fn message_command(mut self, command: impl MessageCommand<T> + '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
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,20 +202,7 @@ impl<T: 'static + Send + Sync + Debug> Bot<T> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let message_command_registry = std::sync::Arc::new(MessageCommandRegistry::new());
|
let bot = Arc::new(self);
|
||||||
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 runtime = Arc::new(Runtime {
|
let runtime = Arc::new(Runtime {
|
||||||
http,
|
http,
|
||||||
|
|||||||
Reference in New Issue
Block a user