feat(macro): rename macro_rule and move to separate module

This commit is contained in:
doryan 2024-10-08 23:32:58 +04:00
parent 7214caeed5
commit b728eafd4b
3 changed files with 19 additions and 11 deletions

View File

@ -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] #[tokio::main]
async fn main() { async fn main() {
@ -75,8 +66,8 @@ async fn main() {
let mut admin_commands = Router::new("admin_commands"); let mut admin_commands = Router::new("admin_commands");
let mut default_commands = Router::new("default_commands"); let mut default_commands = Router::new("default_commands");
append_command!(default_commands, help, privacy); create_handler!(default_commands, info_commands_endpoint, help, privacy);
append_command!(admin_commands, unmute, mute, ban); create_handler!(admin_commands, admin_command_endpoint, mute, unmute, ban);
admin_commands admin_commands
.message .message

View File

@ -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)),*]));
};
}

View File

@ -0,0 +1 @@
pub mod create_handler;