use super::context::CommandContext;
use super::result::CommandResult;
use super::traits::SlashCommand;
pub struct CustomCommand {
name: String,
description: String,
handler: Box<dyn Fn(&str, &mut CommandContext) -> CommandResult + Send + Sync>,
}
impl CustomCommand {
pub fn new<F>(name: impl Into<String>, description: impl Into<String>, handler: F) -> Self
where
F: Fn(&str, &mut CommandContext) -> CommandResult + Send + Sync + 'static,
{
Self {
name: name.into(),
description: description.into(),
handler: Box::new(handler),
}
}
}
impl SlashCommand for CustomCommand {
fn name(&self) -> &str {
&self.name
}
fn description(&self) -> &str {
&self.description
}
fn execute(&self, args: &str, ctx: &mut CommandContext) -> CommandResult {
(self.handler)(args, ctx)
}
}