aboutsummaryrefslogtreecommitdiff
path: root/src/framework
diff options
context:
space:
mode:
authoracdenisSK <[email protected]>2017-11-24 15:35:47 +0100
committeracdenisSK <[email protected]>2017-11-24 15:37:11 +0100
commit85f5b1385f9b8a8cea8be19a3271b57c535b7a14 (patch)
tree5ba8cbaeeda1eaacf0285e50e13569fa6832839f /src/framework
parentConvert from macro to ? (#226) (diff)
downloadserenity-85f5b1385f9b8a8cea8be19a3271b57c535b7a14.tar.xz
serenity-85f5b1385f9b8a8cea8be19a3271b57c535b7a14.zip
Do a temporary fix for options for commands created in the `command!` macro
Diffstat (limited to 'src/framework')
-rw-r--r--src/framework/standard/create_command.rs25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/framework/standard/create_command.rs b/src/framework/standard/create_command.rs
index 4137b91..44e9988 100644
--- a/src/framework/standard/create_command.rs
+++ b/src/framework/standard/create_command.rs
@@ -7,6 +7,7 @@ use std::sync::Arc;
pub enum FnOrCommand {
Fn(fn(&mut Context, &Message, Args) -> Result<(), CommandError>),
Command(Arc<Command>),
+ CommandWithOptions(Arc<Command>),
}
pub struct CreateCommand(pub CommandOptions, pub FnOrCommand);
@@ -122,6 +123,15 @@ impl CreateCommand {
self
}
+
+ /// Like [`cmd`] but says to the builder to use this command's options instead of its own.
+ ///
+ /// [`cmd`]: #method.cmd
+ pub fn cmd_with_options<C: Command + 'static>(mut self, c: C) -> Self {
+ self.1 = FnOrCommand::CommandWithOptions(Arc::new(c));
+
+ self
+ }
/// Whether command can be used only in guilds or not.
pub fn guild_only(mut self, guild_only: bool) -> Self {
@@ -212,7 +222,20 @@ impl CreateCommand {
Arc::new(A(Arc::new(options), func))
},
- FnOrCommand::Command(cmd) => cmd,
+ FnOrCommand::Command(cmd) => {
+ struct A(Arc<CommandOptions>, Arc<Command>);
+
+ impl Command for A {
+ fn execute(&self, c: &mut Context, m: &Message, a: Args) -> Result<(), CommandError> {
+ self.1.execute(c, m, a)
+ }
+
+ fn options(&self) -> Arc<CommandOptions> { Arc::clone(&self.0) }
+ }
+
+ Arc::new(A(Arc::new(options), cmd))
+ },
+ FnOrCommand::CommandWithOptions(cmd) => cmd,
}
}
}