reverted previous changes. dependency upgrade

This commit is contained in:
2021-01-13 19:19:55 +00:00
parent e866171ea7
commit 702743c108
6 changed files with 301 additions and 411 deletions

View File

@ -16,8 +16,9 @@ use serenity::{
use crate::{
check_subscription_on_message, command_help,
consts::{
CHARACTERS, DAY, HOUR, LOCAL_TIMEZONE, MAX_TIME, MINUTE, MIN_INTERVAL, REGEX_CHANNEL,
REGEX_CHANNEL_USER, REGEX_CONTENT_SUBSTITUTION, REGEX_REMIND_COMMAND, THEME_COLOR,
CHARACTERS, DAY, HOUR, LOCAL_TIMEZONE, MAX_TIME, MINUTE, MIN_INTERVAL, PYTHON_LOCATION,
REGEX_CHANNEL, REGEX_CHANNEL_USER, REGEX_CONTENT_SUBSTITUTION, REGEX_REMIND_COMMAND,
THEME_COLOR,
},
framework::SendIterator,
get_ctx_data,
@ -25,7 +26,7 @@ use crate::{
time_parser::TimeParser,
};
use chrono::{offset::TimeZone, NaiveDateTime, Utc};
use chrono::{offset::TimeZone, NaiveDateTime};
use rand::{rngs::OsRng, seq::IteratorRandom};
@ -44,10 +45,10 @@ use std::{
time::{SystemTime, UNIX_EPOCH},
};
use chrono_english::{parse_date_string, Dialect};
use regex::{Captures, RegexBuilder};
use serenity::cache::Cache;
use serenity::model::guild::Guild;
use tokio::process::Command;
fn shorthand_displacement(seconds: u64) -> String {
let (days, seconds) = seconds.div_rem(&DAY);
@ -1232,15 +1233,26 @@ async fn natural(ctx: &Context, msg: &Message, args: String) {
let (time_crop_opt, msg_crop_opt) = (args_iter.next(), args_iter.next().map(|m| m.trim()));
if let (Some(time_crop), Some(msg_crop)) = (time_crop_opt, msg_crop_opt) {
let res = parse_date_string(
time_crop,
Utc::now().with_timezone(&user_data.timezone()),
Dialect::Uk,
);
if let Ok(datetime) = res {
let timestamp = datetime.timestamp();
let python_call = Command::new(&*PYTHON_LOCATION)
.arg("-c")
.arg(include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/dp.py")))
.arg(time_crop)
.arg(&user_data.timezone)
.arg(&*LOCAL_TIMEZONE)
.output()
.await;
if let Some(timestamp) = python_call
.ok()
.map(|inner| {
if inner.status.success() {
Some(from_utf8(&*inner.stdout).unwrap().parse::<i64>().unwrap())
} else {
None
}
})
.flatten()
{
let mut location_ids = vec![ReminderScope::Channel(msg.channel_id.as_u64().to_owned())];
let mut content = msg_crop;
let mut interval = None;
@ -1274,7 +1286,28 @@ async fn natural(ctx: &Context, msg: &Message, args: String) {
let interval_str = captures.name("interval").unwrap().as_str();
// todo
let python_call = Command::new(&*PYTHON_LOCATION)
.arg("-c")
.arg(include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/dp.py")))
.arg(&format!("1 {}", interval_str))
.arg(&*LOCAL_TIMEZONE)
.arg(&*LOCAL_TIMEZONE)
.output()
.await;
interval = python_call
.ok()
.map(|inner| {
if inner.status.success() {
Some(
from_utf8(&*inner.stdout).unwrap().parse::<i64>().unwrap()
- since_epoch.as_secs() as i64,
)
} else {
None
}
})
.flatten();
}
}