Skip to content

Commit

Permalink
Merge pull request #16 from HackSquadDev/chore/chrono-to-time
Browse files Browse the repository at this point in the history
swap out chrono for time
  • Loading branch information
kymppi authored Oct 17, 2022
2 parents e05aab0 + 92b2185 commit 60cebae
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 195 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
15 changes: 7 additions & 8 deletions src/commands/info.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use chrono::{DateTime, Utc};
use serenity::builder::{CreateApplicationCommand, CreateEmbed};
use serenity::model::prelude::interaction::application_command::ApplicationCommandInteraction;
use serenity::prelude::Context;
use serenity::utils::Colour;
use time::OffsetDateTime;

use crate::data::UptimeData;
use crate::utils::calculate_latency::calculate_latency;
Expand All @@ -14,19 +14,18 @@ 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))
})
response.interaction_response_data(|message| 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 +38,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,7 +1,7 @@
use std::{collections::HashMap, sync::Arc};

use chrono::{DateTime, Utc};
use serenity::{model::prelude::UserId, prelude::TypeMapKey};
use time::OffsetDateTime;
use tokio::sync::Mutex;

use crate::{database::Database, environment::Configuration, pagination::Pagination};
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,10 +1,10 @@
use std::collections::HashMap;
use std::sync::Arc;

use chrono::Utc;
use data::{PaginationMap, UptimeData};
use database::Database;
use serenity::prelude::*;
use time::OffsetDateTime;

mod api;
mod commands;
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 60cebae

Please sign in to comment.