Skip to content

Commit

Permalink
Allow for nil prefixes in DMs
Browse files Browse the repository at this point in the history
Fixes #339
  • Loading branch information
arqunis committed Jul 14, 2018
1 parent b520ec7 commit 10bbffe
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/framework/standard/command.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use client::Context;
use model::{
channel::Message,
channel::{
Message,
Channel,
},
Permissions
};
use std::{
Expand Down Expand Up @@ -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;
}
Expand Down
13 changes: 13 additions & 0 deletions src/framework/standard/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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(),
Expand Down

0 comments on commit 10bbffe

Please sign in to comment.