aboutsummaryrefslogtreecommitdiff
path: root/src/framework
diff options
context:
space:
mode:
authorLakelezz <[email protected]>2018-10-15 20:48:49 +0200
committerGitHub <[email protected]>2018-10-15 20:48:49 +0200
commit6a68f68e6cb95af38666a4f5d9a6ad4b39fa88c6 (patch)
treec21576ee8bf06c0e2f208a499a6aa900907e186f /src/framework
parentAdd Option to disable bypassing Checks for Owners (#419) (diff)
downloadserenity-6a68f68e6cb95af38666a4f5d9a6ad4b39fa88c6.tar.xz
serenity-6a68f68e6cb95af38666a4f5d9a6ad4b39fa88c6.zip
Prefix only Command (#416)
Diffstat (limited to 'src/framework')
-rw-r--r--src/framework/standard/command.rs3
-rw-r--r--src/framework/standard/configuration.rs16
-rw-r--r--src/framework/standard/mod.rs30
3 files changed, 46 insertions, 3 deletions
diff --git a/src/framework/standard/command.rs b/src/framework/standard/command.rs
index 3a787ae..7757f91 100644
--- a/src/framework/standard/command.rs
+++ b/src/framework/standard/command.rs
@@ -379,7 +379,8 @@ pub fn positions(ctx: &mut Context, msg: &Message, conf: &Configuration) -> Opti
// 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_dm_prefix && private && positions.is_empty() {
+ if conf.no_dm_prefix && private && positions.is_empty() &&
+ !(conf.ignore_bots && msg.author.bot) {
positions.push(0);
}
}
diff --git a/src/framework/standard/configuration.rs b/src/framework/standard/configuration.rs
index c19b1dd..a8ef075 100644
--- a/src/framework/standard/configuration.rs
+++ b/src/framework/standard/configuration.rs
@@ -6,9 +6,10 @@ use model::{
};
use std::{
collections::HashSet,
- default::Default
+ default::Default,
+ sync::Arc,
};
-use super::command::PrefixCheck;
+use super::command::{Command, InternalCommand, PrefixCheck};
/// The configuration to use for a [`StandardFramework`] associated with a [`Client`]
/// instance.
@@ -59,6 +60,7 @@ pub struct Configuration {
#[doc(hidden)] pub no_dm_prefix: bool,
#[doc(hidden)] pub delimiters: Vec<String>,
#[doc(hidden)] pub case_insensitive: bool,
+ #[doc(hidden)] pub prefix_only_cmd: Option<InternalCommand>,
}
impl Configuration {
@@ -511,6 +513,15 @@ impl Configuration {
self
}
+
+ /// Sets a command to dispatch if user's input is a prefix only.
+ ///
+ /// **Note**: Defaults to no command and ignores prefix only.
+ pub fn prefix_only_cmd<C: Command + 'static>(mut self, c: C) -> Self {
+ self.prefix_only_cmd = Some(Arc::new(c));
+
+ self
+ }
}
impl Default for Configuration {
@@ -550,6 +561,7 @@ impl Default for Configuration {
on_mention: None,
owners: HashSet::default(),
prefixes: vec![],
+ prefix_only_cmd: None,
}
}
}
diff --git a/src/framework/standard/mod.rs b/src/framework/standard/mod.rs
index a32b3ca..5f8c8e0 100644
--- a/src/framework/standard/mod.rs
+++ b/src/framework/standard/mod.rs
@@ -1004,6 +1004,36 @@ impl Framework for StandardFramework {
// Ensure that there is _at least one_ position remaining. There
// is no point in continuing if there is not.
if positions.is_empty() {
+
+ if let Some(ref prefix_only_cmd) =
+ self.configuration.prefix_only_cmd {
+ let prefix_only_cmd = Arc::clone(prefix_only_cmd);
+ let before = self.before.clone();
+ let after = self.after.clone();
+
+ threadpool.execute(move || {
+ if let Some(before) = before {
+ if !(before)(&mut context, &message, "") {
+ return;
+ }
+ }
+
+ if !prefix_only_cmd.before(&mut context, &message) {
+ return;
+ }
+
+ let result = prefix_only_cmd.execute(&mut context,
+ &message, Args::new("", &Vec::new()));
+
+ prefix_only_cmd.after(&mut context, &message,
+ &result);
+
+ if let Some(after) = after {
+ (after)(&mut context, &message, "", result);
+ }
+ });
+ }
+
return;
}