aboutsummaryrefslogtreecommitdiff
path: root/src/framework
diff options
context:
space:
mode:
authoracdenisSK <[email protected]>2017-08-12 19:30:35 +0200
committeracdenisSK <[email protected]>2017-08-12 19:30:35 +0200
commitfdfb1846083165629feca81b5169ceaf331289c5 (patch)
tree7dcdabb33703006edb00e326c968fb44a7a888b6 /src/framework
parentAdd support for custom delimeters (diff)
downloadserenity-fdfb1846083165629feca81b5169ceaf331289c5.tar.xz
serenity-fdfb1846083165629feca81b5169ceaf331289c5.zip
Rewamp the custom delimeter functionality to support more
Diffstat (limited to 'src/framework')
-rw-r--r--src/framework/configuration.rs32
-rw-r--r--src/framework/mod.rs7
2 files changed, 34 insertions, 5 deletions
diff --git a/src/framework/configuration.rs b/src/framework/configuration.rs
index 2acf6b3..a6d0440 100644
--- a/src/framework/configuration.rs
+++ b/src/framework/configuration.rs
@@ -58,7 +58,7 @@ pub struct Configuration {
#[doc(hidden)]
pub prefixes: Vec<String>,
#[doc(hidden)]
- pub delimeter: String,
+ pub delimeters: Vec<String>,
}
impl Configuration {
@@ -389,7 +389,31 @@ impl Configuration {
/// .delimeter(", ")));
/// ```
pub fn delimeter(mut self, delimeter: &str) -> Self {
- self.delimeter = delimeter.to_string();
+ self.delimeters.push(delimeter.to_string());
+
+ self
+ }
+
+ /// Sets multiple delimeters to be used when splitting the content after a command.
+ ///
+ /// # Examples
+ ///
+ /// Have the args be seperated by a comma and a space; and a regular space:
+ ///
+ /// ```rust
+ /// # use serenity::prelude::*;
+ /// # struct Handler;
+ /// #
+ /// # impl EventHandler for Handler {}
+ /// # let mut client = Client::new("token", Handler);
+ /// #
+ /// use serenity::framework::BuiltinFramework;
+ ///
+ /// client.with_framework(BuiltinFramework::new().configure(|c| c
+ /// .delimeters(vec![", ", " "])));
+ /// ```
+ pub fn delimeters(mut self, delimeters: Vec<&str>) -> Self {
+ self.delimeters.extend(delimeters.into_iter().map(|s| s.to_string()));
self
}
@@ -402,7 +426,7 @@ impl Default for Configuration {
/// - **depth** to `5`
/// - **on_mention** to `false` (basically)
/// - **prefix** to `None`
- /// - **delimeter** to " "
+ /// - **delimeters** to vec![" "]
fn default() -> Configuration {
Configuration {
depth: 5,
@@ -417,7 +441,7 @@ impl Default for Configuration {
disabled_commands: HashSet::default(),
allow_dm: true,
ignore_webhooks: true,
- delimeter: " ".to_string(),
+ delimeters: vec![" ".to_string()],
}
}
}
diff --git a/src/framework/mod.rs b/src/framework/mod.rs
index ce484e4..d55c26d 100644
--- a/src/framework/mod.rs
+++ b/src/framework/mod.rs
@@ -936,8 +936,13 @@ impl ::Framework for BuiltinFramework {
if command.use_quotes {
utils::parse_quotes(&content[command_length..])
} else {
+ let delimeter = {
+ let delimeter = self.configuration.delimeters.iter().find(|d| content[command_length..].contains(d.as_str()));
+ delimeter.map(|s| s.as_str()).unwrap_or(" ")
+ };
+
content[command_length..]
- .split(&self.configuration.delimeter)
+ .split(delimeter)
.map(|arg| arg.to_owned())
.collect::<Vec<String>>()
}