Skip to content

Commit

Permalink
refactor(example): Use generated arg getter to get command arg
Browse files Browse the repository at this point in the history
  • Loading branch information
jontze committed Dec 8, 2023
1 parent 66eb92e commit f0de19b
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions examples/custom_commands/examples/custom_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -30,18 +27,11 @@ impl CadencyCommand for Hello {
command: &'a mut CommandInteraction,
response_builder: &'a mut ResponseBuilder,
) -> Result<Response, CadencyError> {
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()?)
}
}
Expand Down

0 comments on commit f0de19b

Please sign in to comment.