dependency upd

This commit is contained in:
jellywx 2021-01-09 18:25:50 +00:00
parent 769cb78141
commit e866171ea7
4 changed files with 389 additions and 254 deletions

568
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,8 @@ edition = "2018"
[dependencies] [dependencies]
dotenv = "0.15" dotenv = "0.15"
tokio = { version = "0.2", features = ["process"] } chrono-english = "0.1.4"
tokio = "0.2"
reqwest = { version = "0.10", features = ["rustls-tls"] } reqwest = { version = "0.10", features = ["rustls-tls"] }
sqlx = { version = "0.4", default-features = false, features = ["runtime-tokio-rustls", "macros", "mysql", "bigdecimal", "chrono"] } sqlx = { version = "0.4", default-features = false, features = ["runtime-tokio-rustls", "macros", "mysql", "bigdecimal", "chrono"] }
regex = "1.4" regex = "1.4"
@ -24,10 +25,9 @@ Inflector = "0.11"
levenshtein = "1.0" levenshtein = "1.0"
[dependencies.serenity] [dependencies.serenity]
git = "https://github.com/serenity-rs/serenity" version = "0.10.2"
branch = "current"
default-features = false default-features = false
features = ["builder", "client", "framework", "cache", "gateway", "http", "model", "utils", "rustls_backend", "collector"] features = ["builder", "client", "framework", "cache", "gateway", "http", "model", "utils", "collector", "default_tokio_0_2"]
[dependencies.regex_command_attr] [dependencies.regex_command_attr]
path = "./regex_command_attr" path = "./regex_command_attr"

View File

@ -13,14 +13,11 @@ use serenity::{
Result as SerenityResult, Result as SerenityResult,
}; };
use tokio::process::Command;
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, PYTHON_LOCATION, CHARACTERS, DAY, HOUR, LOCAL_TIMEZONE, MAX_TIME, MINUTE, MIN_INTERVAL, REGEX_CHANNEL,
REGEX_CHANNEL, REGEX_CHANNEL_USER, REGEX_CONTENT_SUBSTITUTION, REGEX_REMIND_COMMAND, REGEX_CHANNEL_USER, REGEX_CONTENT_SUBSTITUTION, REGEX_REMIND_COMMAND, THEME_COLOR,
THEME_COLOR,
}, },
framework::SendIterator, framework::SendIterator,
get_ctx_data, get_ctx_data,
@ -28,7 +25,7 @@ use crate::{
time_parser::TimeParser, time_parser::TimeParser,
}; };
use chrono::{offset::TimeZone, NaiveDateTime}; use chrono::{offset::TimeZone, NaiveDateTime, Utc};
use rand::{rngs::OsRng, seq::IteratorRandom}; use rand::{rngs::OsRng, seq::IteratorRandom};
@ -47,6 +44,7 @@ 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;
@ -800,7 +798,7 @@ enum ReminderScope {
Channel(u64), Channel(u64),
} }
impl Mentionable for ReminderScope { impl ReminderScope {
fn mention(&self) -> String { fn mention(&self) -> String {
match self { match self {
Self::User(id) => format!("<@{}>", id), Self::User(id) => format!("<@{}>", id),
@ -967,7 +965,7 @@ impl Content {
format!("<@{}>", user.as_str()) format!("<@{}>", user.as_str())
} else if let Some(role_name) = caps.name("role") { } else if let Some(role_name) = caps.name("role") {
if let Some(role) = guild.role_by_name(role_name.as_str()) { if let Some(role) = guild.role_by_name(role_name.as_str()) {
role.mention() role.mention().to_string()
} else { } else {
format!("<<{}>>", role_name.as_str().to_string()) format!("<<{}>>", role_name.as_str().to_string())
} }
@ -1234,26 +1232,15 @@ 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 python_call = Command::new(&*PYTHON_LOCATION) let res = parse_date_string(
.arg("-c") time_crop,
.arg(include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/dp.py"))) Utc::now().with_timezone(&user_data.timezone()),
.arg(time_crop) Dialect::Uk,
.arg(&user_data.timezone) );
.arg(&*LOCAL_TIMEZONE)
.output() if let Ok(datetime) = res {
.await; let timestamp = datetime.timestamp();
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;
@ -1287,28 +1274,7 @@ 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();
let python_call = Command::new(&*PYTHON_LOCATION) // todo
.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

@ -85,9 +85,6 @@ lazy_static! {
pub static ref LOCAL_LANGUAGE: String = pub static ref LOCAL_LANGUAGE: String =
env::var("LOCAL_LANGUAGE").unwrap_or_else(|_| "EN".to_string()); env::var("LOCAL_LANGUAGE").unwrap_or_else(|_| "EN".to_string());
pub static ref PYTHON_LOCATION: String =
env::var("PYTHON_LOCATION").unwrap_or_else(|_| "venv/bin/python3".to_string());
pub static ref DEFAULT_PREFIX: String = pub static ref DEFAULT_PREFIX: String =
env::var("DEFAULT_PREFIX").unwrap_or_else(|_| "$".to_string()); env::var("DEFAULT_PREFIX").unwrap_or_else(|_| "$".to_string());