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

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

45
Cargo.lock generated
View File

@ -401,9 +401,9 @@ checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7"
[[package]]
name = "futures"
version = "0.3.10"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "309f13e3f4be6d5917178c84db67c0b9a09177ac16d4f9a7313a767a68adaa77"
checksum = "90fa4cc29d25b0687b8570b0da86eac698dcb525110ad8b938fe6712baa711ec"
dependencies = [
"futures-channel",
"futures-core",
@ -416,9 +416,9 @@ dependencies = [
[[package]]
name = "futures-channel"
version = "0.3.10"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a3b03bd32f6ec7885edeb99acd1e47e20e34fd4dfd3c6deed6fcac8a9d28f6a"
checksum = "31ebc390c6913de330e418add60e1a7e5af4cb5ec600d19111b339cafcdcc027"
dependencies = [
"futures-core",
"futures-sink",
@ -426,15 +426,15 @@ dependencies = [
[[package]]
name = "futures-core"
version = "0.3.10"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed8aeae2b6ab243ebabe6f54cd4cf53054d98883d5d326128af7d57a9ca5cd3d"
checksum = "089bd0baf024d3216916546338fffe4fc8dfffdd901e33c278abb091e0d52111"
[[package]]
name = "futures-executor"
version = "0.3.10"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f7836b36b7533d16fd5937311d98ba8965ab81030de8b0024c299dd5d51fb9b"
checksum = "d0cb59f15119671c94cd9cc543dc9a50b8d5edc468b4ff5f0bb8567f66c6b48a"
dependencies = [
"futures-core",
"futures-task",
@ -443,15 +443,15 @@ dependencies = [
[[package]]
name = "futures-io"
version = "0.3.10"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d41234e71d5e8ca73d01563974ef6f50e516d71e18f1a2f1184742e31f5d469f"
checksum = "3868967e4e5ab86614e2176c99949eeef6cbcacaee737765f6ae693988273997"
[[package]]
name = "futures-macro"
version = "0.3.10"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3520e0eb4e704e88d771b92d51273ee212997f0d8282f17f5d8ff1cb39104e42"
checksum = "95778720c3ee3c179cd0d8fd5a0f9b40aa7d745c080f86a8f8bed33c4fd89758"
dependencies = [
"proc-macro-hack",
"proc-macro2",
@ -461,24 +461,24 @@ dependencies = [
[[package]]
name = "futures-sink"
version = "0.3.10"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c72d188479368953c6c8c7140e40d7a4401674ab3b98a41e60e515d6cbdbe5de"
checksum = "d4e0f6be0ec0357772fd58fb751958dd600bd0b3edfd429e77793e4282831360"
[[package]]
name = "futures-task"
version = "0.3.10"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08944cea9021170d383287169859c0ca8147d9ec285978393109954448f33cc7"
checksum = "868090f28a925db6cb7462938c51d807546e298fb314088239f0e52fb4338b96"
dependencies = [
"once_cell",
]
[[package]]
name = "futures-util"
version = "0.3.10"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3dd206efbe2ca683b2ce138ccdf61e1b0a63f5816dcedc9d8654c500ba0cea6"
checksum = "cad5e82786df758d407932aded1235e24d8e2eb438b6adafd37930c2462fb5d1"
dependencies = [
"futures-channel",
"futures-core",
@ -623,9 +623,9 @@ checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47"
[[package]]
name = "humantime"
version = "2.0.1"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c1ad908cc71012b7bea4d0c53ba96a8cba9962f048fa68d143376143d863b7a"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
name = "hyper"
@ -1161,9 +1161,9 @@ checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
[[package]]
name = "proc-macro-nested"
version = "0.1.6"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a"
checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086"
[[package]]
name = "proc-macro2"
@ -1321,6 +1321,7 @@ dependencies = [
"chrono-tz",
"dotenv",
"env_logger",
"humantime",
"lazy_static",
"levenshtein",
"log",

View File

@ -6,7 +6,7 @@ edition = "2018"
[dependencies]
dotenv = "0.15"
# chrono-english = "0.1.4"
humantime = "2.1"
tokio = { version = "1.0", features = ["process"] }
reqwest = { version = "0.11", features = ["rustls-tls"] }
regex = "1.4"

View File

@ -42,3 +42,4 @@ __Other Variables__
* `CASE_INSENSITIVE` - default `1`, if `1`, commands will be treated with case insensitivity (so both `$help` and `$HELP` will work)
* `SHARD_COUNT` - default `None`, accepts the number of shards that are being ran
* `SHARD_RANGE` - default `None`, if `SHARD_COUNT` is specified, specifies what range of shards to start on this process
* `DM_ENABLED` - default `1`, if `1`, Reminder Bot will respond to direct messages

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)