aboutsummaryrefslogtreecommitdiff
path: root/src/ext/framework
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-05-04 17:12:02 -0700
committerZeyla Hellyer <[email protected]>2017-05-04 17:14:51 -0700
commit970d726910992890aafd42086feec3f900523cd0 (patch)
tree4d147d4f2cf5cb41ad3337f25b08a9fde1d4fa03 /src/ext/framework
parentAccept references on Into<Id> (diff)
downloadserenity-970d726910992890aafd42086feec3f900523cd0.tar.xz
serenity-970d726910992890aafd42086feec3f900523cd0.zip
Add framework dynamic_prefix example
Diffstat (limited to 'src/ext/framework')
-rw-r--r--src/ext/framework/configuration.rs26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/ext/framework/configuration.rs b/src/ext/framework/configuration.rs
index 46174b4..4f73359 100644
--- a/src/ext/framework/configuration.rs
+++ b/src/ext/framework/configuration.rs
@@ -144,8 +144,30 @@ impl Configuration {
self
}
- /// Sets the prefix to respond to. This can either be a single- or
- /// multi-char string.
+ /// Sets the prefix to respond to dynamically based on conditions.
+ ///
+ /// Return `None` to not have a special prefix for the dispatch, and to
+ /// instead use the inherited prefix.
+ ///
+ /// # Examples
+ ///
+ /// If the Id of the channel is divisible by 5, return a prefix of `"!"`,
+ /// otherwise return a prefix of `"~"`.
+ ///
+ /// ```rust,no_run
+ /// # use serenity::Client;
+ /// #
+ /// # let mut client = Client::login("token");
+ /// client.with_framework(|f| f
+ /// .command("ping", |c| c.exec_str("Pong!"))
+ /// .configure(|c| c.dynamic_prefix(|ctx| {
+ /// Some(if ctx.channel_id.unwrap().0 % 5 == 0 {
+ /// "!"
+ /// } else {
+ /// "~"
+ /// }.to_owned())
+ /// })));
+ /// ```
pub fn dynamic_prefix<F>(mut self, dynamic_prefix: F) -> Self
where F: Fn(&mut Context) -> Option<String> + Send + Sync + 'static {
self.dynamic_prefix = Some(Box::new(dynamic_prefix));