diff --git a/Cargo.lock b/Cargo.lock index 3aeee07..c0f8632 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,15 +8,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" -[[package]] -name = "android_system_properties" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" -dependencies = [ - "libc", -] - [[package]] name = "async-trait" version = "0.1.57" @@ -104,31 +95,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "chrono" -version = "0.4.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1" -dependencies = [ - "iana-time-zone", - "js-sys", - "num-integer", - "num-traits", - "time 0.1.44", - "wasm-bindgen", - "winapi", -] - -[[package]] -name = "codespan-reporting" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" -dependencies = [ - "termcolor", - "unicode-width", -] - [[package]] name = "combine" version = "4.6.6" @@ -183,50 +149,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "cxx" -version = "1.0.78" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19f39818dcfc97d45b03953c1292efc4e80954e1583c4aa770bac1383e2310a4" -dependencies = [ - "cc", - "cxxbridge-flags", - "cxxbridge-macro", - "link-cplusplus", -] - -[[package]] -name = "cxx-build" -version = "1.0.78" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e580d70777c116df50c390d1211993f62d40302881e54d4b79727acb83d0199" -dependencies = [ - "cc", - "codespan-reporting", - "once_cell", - "proc-macro2", - "quote", - "scratch", - "syn", -] - -[[package]] -name = "cxxbridge-flags" -version = "1.0.78" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56a46460b88d1cec95112c8c363f0e2c39afdb237f60583b0b36343bf627ea9c" - -[[package]] -name = "cxxbridge-macro" -version = "1.0.78" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "747b608fecf06b0d72d440f27acc99288207324b793be2c17991839f3d4995ea" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "digest" version = "0.10.5" @@ -416,7 +338,7 @@ checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" dependencies = [ "cfg-if", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", ] [[package]] @@ -457,7 +379,6 @@ dependencies = [ name = "hacksquad-bot" version = "0.1.0" dependencies = [ - "chrono", "dotenvy", "envy", "git2", @@ -469,6 +390,7 @@ dependencies = [ "serde_json", "serenity", "simsearch", + "time", "tokio", ] @@ -571,30 +493,6 @@ dependencies = [ "tokio-native-tls", ] -[[package]] -name = "iana-time-zone" -version = "0.1.51" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5a6ef98976b22b3b7f2f3a806f858cb862044cfa66805aa3ad84cb3d3b785ed" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "wasm-bindgen", - "winapi", -] - -[[package]] -name = "iana-time-zone-haiku" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fde6edd6cef363e9359ed3c98ba64590ba9eecba2293eb5a723ab32aee8926aa" -dependencies = [ - "cxx", - "cxx-build", -] - [[package]] name = "idna" version = "0.3.0" @@ -706,15 +604,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "link-cplusplus" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369" -dependencies = [ - "cc", -] - [[package]] name = "log" version = "0.4.17" @@ -763,7 +652,7 @@ checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf" dependencies = [ "libc", "log", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", "windows-sys", ] @@ -785,16 +674,6 @@ dependencies = [ "tempfile", ] -[[package]] -name = "num-integer" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" -dependencies = [ - "autocfg", - "num-traits", -] - [[package]] name = "num-traits" version = "0.2.15" @@ -1111,12 +990,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "scratch" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" - [[package]] name = "sct" version = "0.7.0" @@ -1224,7 +1097,7 @@ dependencies = [ "serde", "serde-value", "serde_json", - "time 0.3.15", + "time", "tokio", "tracing", "typemap_rev", @@ -1323,15 +1196,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "termcolor" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" -dependencies = [ - "winapi-util", -] - [[package]] name = "thiserror" version = "1.0.37" @@ -1352,17 +1216,6 @@ dependencies = [ "syn", ] -[[package]] -name = "time" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" -dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", -] - [[package]] name = "time" version = "0.3.15" @@ -1568,12 +1421,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-width" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" - [[package]] name = "untrusted" version = "0.7.1" @@ -1620,12 +1467,6 @@ dependencies = [ "try-lock", ] -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -1743,15 +1584,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index fbe7168..544e77b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,8 +22,8 @@ serde_json = "1.0.85" simsearch = "0.2" redis = "0.21" rand = "0.8.5" -chrono = "0.4.22" git2 = "0.15.0" +time = "0.3.15" [dependencies.openssl-sys] version = "0.9.71" diff --git a/src/commands/info.rs b/src/commands/info.rs index 6b2a0ed..530c812 100644 --- a/src/commands/info.rs +++ b/src/commands/info.rs @@ -1,4 +1,4 @@ -use chrono::{DateTime, Utc}; +use time::OffsetDateTime; use serenity::builder::{CreateApplicationCommand, CreateEmbed}; use serenity::model::prelude::interaction::application_command::ApplicationCommandInteraction; use serenity::prelude::Context; @@ -14,19 +14,20 @@ pub async fn run(ctx: Context, command: ApplicationCommandInteraction) { let uptime = data.get::(); // start measuring latency - let ping_start = Utc::now(); + let ping_start = OffsetDateTime::now_utc(); + let embed = generate_embed("Pinging...".to_string(), uptime, &version); command .create_interaction_response(&ctx.http, |response| { response.interaction_response_data(|message| { - message.set_embed(generate_embed("Pinging...".to_string(), uptime, &version)) + message.set_embed(embed) }) }) .await .unwrap(); // end measuring latency - let end_ping = Utc::now(); + let end_ping = OffsetDateTime::now_utc(); let latency = calculate_latency(ping_start, end_ping); let embed = generate_embed(format!("{} ms", latency), uptime, &version); @@ -39,11 +40,11 @@ pub async fn run(ctx: Context, command: ApplicationCommandInteraction) { fn generate_embed( latency: String, - uptime: Option<&DateTime>, + uptime: Option<&OffsetDateTime>, version: &VersionInfo, ) -> CreateEmbed { let uptime = match uptime { - Some(data) => format!("", data.timestamp()), + Some(data) => format!("", data.unix_timestamp()), None => "Not Availible".to_string(), }; diff --git a/src/data.rs b/src/data.rs index d6f40c0..d0bf93e 100644 --- a/src/data.rs +++ b/src/data.rs @@ -1,6 +1,6 @@ use std::{collections::HashMap, sync::Arc}; -use chrono::{DateTime, Utc}; +use time::OffsetDateTime; use serenity::{model::prelude::UserId, prelude::TypeMapKey}; use tokio::sync::Mutex; @@ -10,7 +10,7 @@ pub struct UptimeData; pub struct PaginationMap; impl TypeMapKey for UptimeData { - type Value = DateTime; + type Value = OffsetDateTime; } impl TypeMapKey for Configuration { diff --git a/src/main.rs b/src/main.rs index be89581..93e38be 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use std::sync::Arc; -use chrono::Utc; +use time::OffsetDateTime; use data::{PaginationMap, UptimeData}; use database::Database; use serenity::prelude::*; @@ -35,7 +35,7 @@ async fn main() { data.insert::(config); data.insert::(db); - data.insert::(Utc::now()); + data.insert::(OffsetDateTime::now_utc()); data.insert::(Arc::new(Mutex::new(HashMap::new()))) } diff --git a/src/utils/calculate_latency.rs b/src/utils/calculate_latency.rs index 23a0e47..2c152dc 100644 --- a/src/utils/calculate_latency.rs +++ b/src/utils/calculate_latency.rs @@ -1,10 +1,10 @@ -use chrono::{offset::Utc, DateTime}; +use time::OffsetDateTime; -pub fn calculate_latency(start: DateTime, end: DateTime) -> i64 { - let start_ts = start.timestamp(); - let start_ts_ss = start.timestamp_subsec_millis() as i64; - let end_ts = end.timestamp(); - let end_ts_ss = end.timestamp_subsec_millis() as i64; +pub fn calculate_latency(start: OffsetDateTime, end: OffsetDateTime) -> i64 { + let start_ts = start.unix_timestamp(); + let start_ts_ss = start.millisecond() as i64; + let end_ts = end.unix_timestamp(); + let end_ts_ss = end.millisecond() as i64; ((end_ts - start_ts) * 1000) + (end_ts_ss - start_ts_ss) } diff --git a/src/utils/git.rs b/src/utils/git.rs index 6b2c568..5b7f6da 100644 --- a/src/utils/git.rs +++ b/src/utils/git.rs @@ -1,13 +1,13 @@ use std::fmt::Display; -use chrono::{DateTime, TimeZone, Utc}; +use time::OffsetDateTime; use git2::{ErrorCode, Repository}; #[derive(Clone)] pub struct VersionInfo { branch: String, revision: String, - time: DateTime, + time: OffsetDateTime, } impl Display for VersionInfo { @@ -38,11 +38,11 @@ pub fn show_head_rev(repo: &Repository) -> String { } // get date from latest revision -pub fn show_head_rev_date(repo: &Repository) -> DateTime { +pub fn show_head_rev_date(repo: &Repository) -> OffsetDateTime { let revspec = repo.revparse("HEAD").unwrap(); let revision = revspec.from().unwrap(); - Utc.timestamp(revision.as_commit().unwrap().time().seconds(), 0) + OffsetDateTime::from_unix_timestamp(revision.as_commit().unwrap().time().seconds()).unwrap() } pub fn get_version() -> VersionInfo {