From b728eafd4bcdc7077d823a84eacb7f66e13335e0 Mon Sep 17 00:00:00 2001 From: doryan Date: Tue, 8 Oct 2024 23:32:58 +0400 Subject: [PATCH] feat(macro): rename macro_rule and move to separate module --- src/main.rs | 13 ++----------- src/utils/macro_rules/create_handler.rs | 16 ++++++++++++++++ src/utils/macro_rules/mod.rs | 1 + 3 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 src/utils/macro_rules/create_handler.rs create mode 100644 src/utils/macro_rules/mod.rs diff --git a/src/main.rs b/src/main.rs index 3cacd3c..a602177 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,15 +41,6 @@ fn logs() { ); } -macro_rules! append_command { - ($branch:expr, $($command:expr), *) => { - $($branch - .message - .register($command) - .filter(Command::one(stringify!($command))); - )* - } -} #[tokio::main] async fn main() { @@ -75,8 +66,8 @@ async fn main() { let mut admin_commands = Router::new("admin_commands"); let mut default_commands = Router::new("default_commands"); - append_command!(default_commands, help, privacy); - append_command!(admin_commands, unmute, mute, ban); + create_handler!(default_commands, info_commands_endpoint, help, privacy); + create_handler!(admin_commands, admin_command_endpoint, mute, unmute, ban); admin_commands .message diff --git a/src/utils/macro_rules/create_handler.rs b/src/utils/macro_rules/create_handler.rs new file mode 100644 index 0000000..4f5109c --- /dev/null +++ b/src/utils/macro_rules/create_handler.rs @@ -0,0 +1,16 @@ +#[macro_export] +macro_rules! create_handler { + ($branch:expr, $command:expr) => { + $($branch + .message + .register($command) + .filter(Command::one(stringify!($command))); + )* + }; + ($branch:expr, $command:expr, $($endpoint:expr), *) => { + $branch + .message + .register($command) + .filter(Command::many([$(stringify!($endpoint)),*])); + }; +} diff --git a/src/utils/macro_rules/mod.rs b/src/utils/macro_rules/mod.rs new file mode 100644 index 0000000..5935e9e --- /dev/null +++ b/src/utils/macro_rules/mod.rs @@ -0,0 +1 @@ +pub mod create_handler;