From 125c1b8feff65ed86136ca0c3b75cdfa073aefc3 Mon Sep 17 00:00:00 2001 From: acdenisSK Date: Sat, 12 Aug 2017 15:26:19 +0200 Subject: Add support for custom delimeters --- src/framework/configuration.rs | 28 ++++++++++++++++++++++++++++ src/framework/mod.rs | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'src/framework') diff --git a/src/framework/configuration.rs b/src/framework/configuration.rs index 28e1af5..2acf6b3 100644 --- a/src/framework/configuration.rs +++ b/src/framework/configuration.rs @@ -57,6 +57,8 @@ pub struct Configuration { pub owners: HashSet, #[doc(hidden)] pub prefixes: Vec, + #[doc(hidden)] + pub delimeter: String, } impl Configuration { @@ -367,6 +369,30 @@ impl Configuration { self } + + /// Sets a delimeter to be used when splitting the content after a command. + /// + /// # Examples + /// + /// Have the args be seperated by a comma and a 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 + /// .delimeter(", "))); + /// ``` + pub fn delimeter(mut self, delimeter: &str) -> Self { + self.delimeter = delimeter.to_string(); + + self + } } impl Default for Configuration { @@ -376,6 +402,7 @@ impl Default for Configuration { /// - **depth** to `5` /// - **on_mention** to `false` (basically) /// - **prefix** to `None` + /// - **delimeter** to " " fn default() -> Configuration { Configuration { depth: 5, @@ -390,6 +417,7 @@ impl Default for Configuration { disabled_commands: HashSet::default(), allow_dm: true, ignore_webhooks: true, + delimeter: " ".to_string(), } } } diff --git a/src/framework/mod.rs b/src/framework/mod.rs index 9206040..ce484e4 100644 --- a/src/framework/mod.rs +++ b/src/framework/mod.rs @@ -937,7 +937,7 @@ impl ::Framework for BuiltinFramework { utils::parse_quotes(&content[command_length..]) } else { content[command_length..] - .split_whitespace() + .split(&self.configuration.delimeter) .map(|arg| arg.to_owned()) .collect::>() } -- cgit v1.2.3