aboutsummaryrefslogtreecommitdiff
path: root/src/framework
diff options
context:
space:
mode:
authoracdenisSK <[email protected]>2018-07-14 11:02:43 +0200
committeracdenisSK <[email protected]>2018-07-14 11:04:39 +0200
commit10bbffe9332edf8b8835d98cfffb8ec411162145 (patch)
tree6339c47029989f408f9dd1a92629d5e132065875 /src/framework
parentAdd docs for `Args::new` (diff)
downloadserenity-10bbffe9332edf8b8835d98cfffb8ec411162145.tar.xz
serenity-10bbffe9332edf8b8835d98cfffb8ec411162145.zip
Allow for nil prefixes in DMs
Fixes #339
Diffstat (limited to 'src/framework')
-rw-r--r--src/framework/standard/command.rs19
-rw-r--r--src/framework/standard/configuration.rs13
2 files changed, 31 insertions, 1 deletions
diff --git a/src/framework/standard/command.rs b/src/framework/standard/command.rs
index 0fa51f9..f164141 100644
--- a/src/framework/standard/command.rs
+++ b/src/framework/standard/command.rs
@@ -1,6 +1,9 @@
use client::Context;
use model::{
- channel::Message,
+ channel::{
+ Message,
+ Channel,
+ },
Permissions
};
use std::{
@@ -353,6 +356,20 @@ pub fn positions(ctx: &mut Context, msg: &Message, conf: &Configuration) -> Opti
}
}
+ #[cfg(feature = "cache")]
+ {
+ let private = match msg.channel() {
+ Some(Channel::Private(_)) => true,
+ _ => false,
+ };
+
+ // If the above do not fill `positions`, then that means no kind of prefix was present.
+ // Check if a no-prefix-execution is applicable.
+ if conf.no_prefix && private && positions.is_empty() {
+ positions.push(0);
+ }
+ }
+
if positions.is_empty() {
return None;
}
diff --git a/src/framework/standard/configuration.rs b/src/framework/standard/configuration.rs
index 01d3b01..7b2caf5 100644
--- a/src/framework/standard/configuration.rs
+++ b/src/framework/standard/configuration.rs
@@ -53,6 +53,7 @@ pub struct Configuration {
#[doc(hidden)] pub on_mention: Option<Vec<String>>,
#[doc(hidden)] pub owners: HashSet<UserId>,
#[doc(hidden)] pub prefixes: Vec<String>,
+ #[doc(hidden)] pub no_prefix: bool,
#[doc(hidden)] pub delimiters: Vec<String>,
#[doc(hidden)] pub case_insensitive: bool,
}
@@ -398,6 +399,16 @@ impl Configuration {
self
}
+ /// Sets whether command execution can done without a prefix. Works only in private channels.
+ ///
+ /// # Note
+ /// Needs the `cache` feature to be enabled. Otherwise this does nothing.
+ pub fn no_prefix(mut self, b: bool) -> Self {
+ self.no_prefix = b;
+
+ self
+ }
+
/// Sets a delimiter to be used when splitting the content after a command.
///
/// # Examples
@@ -466,6 +477,7 @@ impl Default for Configuration {
/// - **depth** to `5`
/// - **on_mention** to `false` (basically)
/// - **prefix** to `None`
+ /// - **no_prefix** to `false`
/// - **delimiters** to vec![" "]
/// - **case_insensitive** to `false`
fn default() -> Configuration {
@@ -475,6 +487,7 @@ impl Default for Configuration {
dynamic_prefix: None,
allow_whitespace: false,
prefixes: vec![],
+ no_prefix: false,
ignore_bots: true,
owners: HashSet::default(),
blocked_users: HashSet::default(),