chore: redo the ping command
This commit is contained in:
parent
53212d8b11
commit
301feb415b
@ -139,9 +139,13 @@ pub async fn write_card(mut card: Card) -> Result<(), String> {
|
||||
pub async fn write_cards(cards: Vec<Card>) -> Result<(), String> {
|
||||
let mut new_cards: Vec<Card> = Vec::new();
|
||||
let mut handles: Vec<task::JoinHandle<Result<Option<Card>, String>>> = Vec::new();
|
||||
let start = SystemTime::now();
|
||||
let current_time_ts = start
|
||||
.duration_since(UNIX_EPOCH).unwrap();
|
||||
for mut card in cards {
|
||||
let current_time_ts_clone = current_time_ts.clone();
|
||||
trace!("Writing card: {:?}", card);
|
||||
handles.push(task::spawn(async {
|
||||
handles.push(task::spawn(async move {
|
||||
let old_card = KATANA
|
||||
.get()
|
||||
.unwrap()
|
||||
@ -154,11 +158,7 @@ pub async fn write_cards(cards: Vec<Card>) -> Result<(), String> {
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
let start = SystemTime::now();
|
||||
let current_time_ts = start
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.expect("Time went backwards");
|
||||
card.last_update_ts = current_time_ts.as_secs() as i64;
|
||||
card.last_update_ts = current_time_ts_clone.as_secs() as i64;
|
||||
if old_card.is_some() {
|
||||
match KATANA
|
||||
.get()
|
||||
|
@ -9,6 +9,8 @@ use serenity::prelude::*;
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
use std::sync::OnceLock;
|
||||
use std::thread::current;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use swordfish_common::*;
|
||||
|
||||
use crate::config::Config;
|
||||
@ -274,7 +276,20 @@ async fn main() {
|
||||
|
||||
#[command]
|
||||
async fn ping(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
msg.reply(ctx, "Pong!").await?;
|
||||
let start = SystemTime::now();
|
||||
let current_time_ts = start.duration_since(UNIX_EPOCH).unwrap().as_micros() as f64;
|
||||
let msg_ts = msg.timestamp.timestamp_micros() as f64;
|
||||
helper::info_message(
|
||||
ctx,
|
||||
msg,
|
||||
format!(
|
||||
"Time taken to receive message: `{}ms`\n\n\
|
||||
This only reflects the time taken for the bot to receive the message from Discord server.",
|
||||
(current_time_ts - msg_ts) / 1000.0 // Message timestamp can't be negative
|
||||
),
|
||||
Some("Ping".to_string()),
|
||||
)
|
||||
.await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user