reverted previous changes. dependency upgrade

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

623
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,15 +1,14 @@
[package] [package]
name = "reminder_rs" name = "reminder_rs"
version = "1.4.0" version = "1.4.0-alpha"
authors = ["jellywx <judesouthworth@pm.me>"] authors = ["jellywx <judesouthworth@pm.me>"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
dotenv = "0.15" dotenv = "0.15"
chrono-english = "0.1.4" # chrono-english = "0.1.4"
tokio = "0.2" tokio = { version = "1.0", features = ["process"] }
reqwest = { version = "0.10", features = ["rustls-tls"] } reqwest = { version = "0.11", features = ["rustls-tls"] }
sqlx = { version = "0.4", default-features = false, features = ["runtime-tokio-rustls", "macros", "mysql", "bigdecimal", "chrono"] }
regex = "1.4" regex = "1.4"
log = "0.4" log = "0.4"
env_logger = "0.8" env_logger = "0.8"
@ -24,10 +23,15 @@ rand = "0.7"
Inflector = "0.11" Inflector = "0.11"
levenshtein = "1.0" levenshtein = "1.0"
[dependencies.serenity] [dependencies.sqlx]
version = "0.10.2" git = "https://github.com/ant32/sqlx"
default-features = false default-features = false
features = ["builder", "client", "framework", "cache", "gateway", "http", "model", "utils", "collector", "default_tokio_0_2"] features = ["runtime-tokio-rustls", "macros", "mysql", "bigdecimal", "chrono"]
[dependencies.serenity]
version = "0.10"
default-features = false
features = ["builder", "client", "framework", "cache", "gateway", "http", "model", "utils", "collector", "rustls_backend"]
[dependencies.regex_command_attr] [dependencies.regex_command_attr]
path = "./regex_command_attr" path = "./regex_command_attr"

View File

@ -16,8 +16,9 @@ use serenity::{
use crate::{ use crate::{
check_subscription_on_message, command_help, check_subscription_on_message, command_help,
consts::{ consts::{
CHARACTERS, DAY, HOUR, LOCAL_TIMEZONE, MAX_TIME, MINUTE, MIN_INTERVAL, REGEX_CHANNEL, CHARACTERS, DAY, HOUR, LOCAL_TIMEZONE, MAX_TIME, MINUTE, MIN_INTERVAL, PYTHON_LOCATION,
REGEX_CHANNEL_USER, REGEX_CONTENT_SUBSTITUTION, REGEX_REMIND_COMMAND, THEME_COLOR, REGEX_CHANNEL, REGEX_CHANNEL_USER, REGEX_CONTENT_SUBSTITUTION, REGEX_REMIND_COMMAND,
THEME_COLOR,
}, },
framework::SendIterator, framework::SendIterator,
get_ctx_data, get_ctx_data,
@ -25,7 +26,7 @@ use crate::{
time_parser::TimeParser, time_parser::TimeParser,
}; };
use chrono::{offset::TimeZone, NaiveDateTime, Utc}; use chrono::{offset::TimeZone, NaiveDateTime};
use rand::{rngs::OsRng, seq::IteratorRandom}; use rand::{rngs::OsRng, seq::IteratorRandom};
@ -44,10 +45,10 @@ use std::{
time::{SystemTime, UNIX_EPOCH}, time::{SystemTime, UNIX_EPOCH},
}; };
use chrono_english::{parse_date_string, Dialect};
use regex::{Captures, RegexBuilder}; use regex::{Captures, RegexBuilder};
use serenity::cache::Cache; use serenity::cache::Cache;
use serenity::model::guild::Guild; use serenity::model::guild::Guild;
use tokio::process::Command;
fn shorthand_displacement(seconds: u64) -> String { fn shorthand_displacement(seconds: u64) -> String {
let (days, seconds) = seconds.div_rem(&DAY); 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())); 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) { if let (Some(time_crop), Some(msg_crop)) = (time_crop_opt, msg_crop_opt) {
let res = parse_date_string( let python_call = Command::new(&*PYTHON_LOCATION)
time_crop, .arg("-c")
Utc::now().with_timezone(&user_data.timezone()), .arg(include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/dp.py")))
Dialect::Uk, .arg(time_crop)
); .arg(&user_data.timezone)
.arg(&*LOCAL_TIMEZONE)
if let Ok(datetime) = res { .output()
let timestamp = datetime.timestamp(); .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 location_ids = vec![ReminderScope::Channel(msg.channel_id.as_u64().to_owned())];
let mut content = msg_crop; let mut content = msg_crop;
let mut interval = None; 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(); 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();
} }
} }

View File

@ -92,4 +92,7 @@ lazy_static! {
THEME_COLOR_FALLBACK, THEME_COLOR_FALLBACK,
|inner| u32::from_str_radix(&inner, 16).unwrap_or(THEME_COLOR_FALLBACK) |inner| u32::from_str_radix(&inner, 16).unwrap_or(THEME_COLOR_FALLBACK)
); );
pub static ref PYTHON_LOCATION: String =
env::var("PYTHON_LOCATION").unwrap_or_else(|_| "venv/bin/python3".to_string());
} }

View File

@ -399,6 +399,8 @@ impl Framework for RegexFramework {
let member = guild.member(&ctx, &msg.author).await.unwrap(); let member = guild.member(&ctx, &msg.author).await.unwrap();
if command.check_permissions(&ctx, &guild, &member).await { if command.check_permissions(&ctx, &guild, &member).await {
dbg!(command.name);
(command.func)(&ctx, &msg, args).await; (command.func)(&ctx, &msg, args).await;
} else if command.required_perms == PermissionLevel::Restricted } else if command.required_perms == PermissionLevel::Restricted
{ {
@ -474,6 +476,8 @@ impl Framework for RegexFramework {
.unwrap_or("") .unwrap_or("")
.to_string(); .to_string();
dbg!(command.name);
(command.func)(&ctx, &msg, args).await; (command.func)(&ctx, &msg, args).await;
} }
} }

View File

@ -239,7 +239,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
env!("CARGO_MANIFEST_DIR"), env!("CARGO_MANIFEST_DIR"),
"/assets/", "/assets/",
env!("STRINGS_FILE") env!("STRINGS_FILE")
)))?; )))
.unwrap();
let mut data = client.data.write().await; let mut data = client.data.write().await;