Skip to content

Commit

Permalink
swap out chrono for time
Browse files Browse the repository at this point in the history
  • Loading branch information
washbin committed Oct 16, 2022
1 parent b5fde2d commit e72f9ce
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 193 deletions.
176 changes: 4 additions & 172 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 7 additions & 6 deletions src/commands/info.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,19 +14,20 @@ pub async fn run(ctx: Context, command: ApplicationCommandInteraction) {
let uptime = data.get::<UptimeData>();

// 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);
Expand All @@ -39,11 +40,11 @@ pub async fn run(ctx: Context, command: ApplicationCommandInteraction) {

fn generate_embed(
latency: String,
uptime: Option<&DateTime<Utc>>,
uptime: Option<&OffsetDateTime>,
version: &VersionInfo,
) -> CreateEmbed {
let uptime = match uptime {
Some(data) => format!("<t:{}:R>", data.timestamp()),
Some(data) => format!("<t:{}:R>", data.unix_timestamp()),
None => "Not Availible".to_string(),
};

Expand Down
4 changes: 2 additions & 2 deletions src/data.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -10,7 +10,7 @@ pub struct UptimeData;
pub struct PaginationMap;

impl TypeMapKey for UptimeData {
type Value = DateTime<Utc>;
type Value = OffsetDateTime;
}

impl TypeMapKey for Configuration {
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down Expand Up @@ -35,7 +35,7 @@ async fn main() {

data.insert::<Configuration>(config);
data.insert::<Database>(db);
data.insert::<UptimeData>(Utc::now());
data.insert::<UptimeData>(OffsetDateTime::now_utc());
data.insert::<PaginationMap>(Arc::new(Mutex::new(HashMap::new())))
}

Expand Down
Loading

0 comments on commit e72f9ce

Please sign in to comment.