removed forward check bc it doesnt work. added an environment variable to configure if dm responses should be enabled

This commit is contained in:
2021-01-17 00:39:48 +00:00
parent f80c8cba50
commit 43ba899c7a
7 changed files with 52 additions and 39 deletions

View File

@ -1243,9 +1243,9 @@ async fn natural(ctx: &Context, msg: &Message, args: String) {
let interval = if let Some(interval_crop) = captures.name("interval") {
if subscribed {
natural_parser(interval_crop.as_str(), &user_data.timezone)
.await
.map(|i| i - since_epoch.as_secs() as i64)
humantime::parse_duration(interval_crop.as_str())
.map(|duration| duration.as_secs() as i64)
.ok()
} else {
None
}

View File

@ -55,7 +55,7 @@ lazy_static! {
.unwrap();
pub static ref REGEX_NATURAL_COMMAND: Regex = Regex::new(
r#"(?P<time>.*?) (?:send|say) (?P<msg>.*?)(?: every(?!.*every) (?P<interval>.*?)(?: (?:until|for) (?P<expires>.*?))?)?(?: to (?P<mentions>((?:<@\d+>)|(?:<@!\d+>)|(?:<#\d+>)|(?:\s+))+))?$"#
r#"(?P<time>.*?) (?:send|say) (?P<msg>.*?)(?: every (?P<interval>.*?)(?: (?:until|for) (?P<expires>.*?))?)?(?: to (?P<mentions>((?:<@\d+>)|(?:<@!\d+>)|(?:<#\d+>)|(?:\s+))+))?$"#
)
.unwrap();

View File

@ -183,6 +183,7 @@ pub struct RegexFramework {
client_id: u64,
ignore_bots: bool,
case_insensitive: bool,
dm_enabled: bool,
}
impl RegexFramework {
@ -195,6 +196,7 @@ impl RegexFramework {
client_id: client_id.into(),
ignore_bots: true,
case_insensitive: true,
dm_enabled: true,
}
}
@ -216,6 +218,12 @@ impl RegexFramework {
self
}
pub fn dm_enabled(mut self, dm_enabled: bool) -> Self {
self.dm_enabled = dm_enabled;
self
}
pub fn add_command<S: ToString>(mut self, name: S, command: &'static Command) -> Self {
self.commands.insert(name.to_string(), command);
@ -465,20 +473,22 @@ impl Framework for RegexFramework {
}
}
// DM Command
else if let Some(full_match) = self.dm_regex_matcher.captures(&msg.content[..]) {
let command = self
.commands
.get(&full_match.name("cmd").unwrap().as_str().to_lowercase())
.unwrap();
let args = full_match
.name("args")
.map(|m| m.as_str())
.unwrap_or("")
.to_string();
else if self.dm_enabled {
if let Some(full_match) = self.dm_regex_matcher.captures(&msg.content[..]) {
let command = self
.commands
.get(&full_match.name("cmd").unwrap().as_str().to_lowercase())
.unwrap();
let args = full_match
.name("args")
.map(|m| m.as_str())
.unwrap_or("")
.to_string();
dbg!(command.name);
dbg!(command.name);
(command.func)(&ctx, &msg, args).await;
(command.func)(&ctx, &msg, args).await;
}
}
}
}

View File

@ -171,6 +171,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
.default_prefix(DEFAULT_PREFIX.clone())
.case_insensitive(env::var("CASE_INSENSITIVE").map_or(true, |var| var == "1"))
.ignore_bots(env::var("IGNORE_BOTS").map_or(true, |var| var == "1"))
.dm_enabled(env::var("DM_ENABLED").map_or(true, |var| var == "1"))
// info commands
.add_command("ping", &info_cmds::PING_COMMAND)
.add_command("help", &info_cmds::HELP_COMMAND)