From f0de19b9b4be4da98d0a7f9c953898afbb82f203 Mon Sep 17 00:00:00 2001 From: Jontze <42588836+jontze@users.noreply.github.com> Date: Fri, 8 Dec 2023 21:33:02 +0100 Subject: [PATCH] refactor(example): Use generated arg getter to get command arg --- .../examples/custom_commands.rs | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/examples/custom_commands/examples/custom_commands.rs b/examples/custom_commands/examples/custom_commands.rs index aeb9409..6915b71 100644 --- a/examples/custom_commands/examples/custom_commands.rs +++ b/examples/custom_commands/examples/custom_commands.rs @@ -6,13 +6,10 @@ extern crate cadency_codegen; use cadency_commands::Fib; use cadency_core::{ response::{Response, ResponseBuilder}, - setup_commands, utils, Cadency, CadencyCommand, CadencyError, + setup_commands, Cadency, CadencyCommand, CadencyError, }; use serenity::{ - all::Mentionable, - async_trait, - client::Context, - model::application::{CommandDataOptionValue, CommandInteraction}, + all::Mentionable, async_trait, client::Context, model::application::CommandInteraction, }; // This is your custom command with the name "hello" @@ -30,18 +27,11 @@ impl CadencyCommand for Hello { command: &'a mut CommandInteraction, response_builder: &'a mut ResponseBuilder, ) -> Result { - let user_arg = utils::get_option_value_at_position(command.data.options.as_ref(), 0) - .and_then(|option_value| { - if let CommandDataOptionValue::User(user_id) = option_value { - Some(user_id) - } else { - error!("Command argument is not a user"); - None - } - }) - .expect("A user as command argument"); Ok(response_builder - .message(Some(format!("**Hello {}!**", user_arg.mention()))) + .message(Some(format!( + "**Hello {}!**", + self.arg_user(command).mention() + ))) .build()?) } }