aboutsummaryrefslogtreecommitdiff
path: root/src/ext/framework/configuration.rs
diff options
context:
space:
mode:
authorIllia <[email protected]>2016-12-09 23:30:30 +0200
committerzeyla <[email protected]>2016-12-09 13:30:30 -0800
commit8f24aa391f6b8a9103a9c105138c7610288acb05 (patch)
tree5af9a958502a49d64868c50ef976157c6b71adca /src/ext/framework/configuration.rs
parentImplement From<Embed> for CreateEmbed (diff)
downloadserenity-8f24aa391f6b8a9103a9c105138c7610288acb05.tar.xz
serenity-8f24aa391f6b8a9103a9c105138c7610288acb05.zip
Command builder, quoted args, and multi-prefixes
Add a command builder, which can take arguments such as multiple checks, quoted arguments, and multiple prefix support, as well as dynamic prefixes per context.
Diffstat (limited to 'src/ext/framework/configuration.rs')
-rw-r--r--src/ext/framework/configuration.rs27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/ext/framework/configuration.rs b/src/ext/framework/configuration.rs
index 6a6c5e5..7af38ed 100644
--- a/src/ext/framework/configuration.rs
+++ b/src/ext/framework/configuration.rs
@@ -1,5 +1,6 @@
use std::default::Default;
use ::client::rest;
+use ::client::Context;
/// The configuration to use for a [`Framework`] associated with a [`Client`]
/// instance.
@@ -31,7 +32,9 @@ pub struct Configuration {
#[doc(hidden)]
pub allow_whitespace: bool,
#[doc(hidden)]
- pub prefix: Option<String>,
+ pub prefixes: Vec<String>,
+ #[doc(hidden)]
+ pub dynamic_prefix: Option<Box<Fn(&Context) -> Option<String> + Send + Sync + 'static>>
}
impl Configuration {
@@ -119,7 +122,24 @@ impl Configuration {
/// Sets the prefix to respond to. This can either be a single-char or
/// multi-char string.
pub fn prefix<S: Into<String>>(mut self, prefix: S) -> Self {
- self.prefix = Some(prefix.into());
+ self.prefixes = vec![prefix.into()];
+
+ self
+ }
+
+ /// Sets the prefix to respond to. This can either be a single-char or
+ /// multi-char string.
+ pub fn prefixes(mut self, prefixes: Vec<&str>) -> Self {
+ self.prefixes = prefixes.iter().map(|x| x.to_string()).collect();
+
+ self
+ }
+
+ /// Sets the prefix to respond to. This can either be a single-char or
+ /// multi-char string.
+ pub fn dynamic_prefix<F>(mut self, dynamic_prefix: F) -> Self
+ where F: Fn(&Context) -> Option<String> + Send + Sync + 'static {
+ self.dynamic_prefix = Some(Box::new(dynamic_prefix));
self
}
@@ -137,7 +157,8 @@ impl Default for Configuration {
depth: 5,
on_mention: None,
allow_whitespace: false,
- prefix: None,
+ prefixes: vec![],
+ dynamic_prefix: None
}
}
}