ping command

This commit is contained in:
jude
2020-09-01 18:48:40 +01:00
parent e395886f6c
commit bb4c96a628
4 changed files with 29 additions and 2 deletions

View File

@ -10,9 +10,8 @@ use serenity::{
framework::standard::CommandResult,
};
use chrono_tz::Tz;
use chrono::offset::Utc;
use chrono_tz::Tz;
use crate::{
THEME_COLOR,
@ -20,6 +19,25 @@ use crate::{
models::UserData,
};
use std::time::{
SystemTime,
UNIX_EPOCH
};
#[command]
#[can_blacklist(false)]
async fn ping(ctx: &Context, msg: &Message, _args: String) -> CommandResult {
let now = SystemTime::now();
let since_epoch = now
.duration_since(UNIX_EPOCH)
.expect("Time calculated as going backwards. Very bad");
let delta = since_epoch.as_millis() as i64 - msg.timestamp.timestamp_millis();
let _ = msg.channel_id.say(&ctx, format!("Time taken to receive message: {}ms", delta)).await;
Ok(())
}
#[command]
#[can_blacklist(false)]

View File

@ -118,6 +118,8 @@ SELECT code FROM languages WHERE code = ? OR name = ?
}
#[command]
#[supports_dm(false)]
#[permission_level(Restricted)]
async fn prefix(ctx: &Context, msg: &Message, args: String) -> CommandResult {
let pool = ctx.data.read().await
.get::<SQLPool>().cloned().expect("Could not get SQLPool from data");

View File

@ -24,6 +24,8 @@ use chrono::NaiveDateTime;
#[command]
#[supports_dm(false)]
#[permission_level(Restricted)]
async fn pause(ctx: &Context, msg: &Message, args: String) -> CommandResult {
let pool = ctx.data.read().await
.get::<SQLPool>().cloned().expect("Could not get SQLPool from data");
@ -68,6 +70,7 @@ async fn pause(ctx: &Context, msg: &Message, args: String) -> CommandResult {
}
#[command]
#[permission_level(Restricted)]
async fn offset(ctx: &Context, msg: &Message, args: String) -> CommandResult {
let pool = ctx.data.read().await
.get::<SQLPool>().cloned().expect("Could not get SQLPool from data");
@ -118,6 +121,7 @@ UPDATE reminders SET `time` = `time` + ? WHERE reminders.channel_id = ?
}
#[command]
#[permission_level(Restricted)]
async fn nudge(ctx: &Context, msg: &Message, args: String) -> CommandResult {
let pool = ctx.data.read().await
.get::<SQLPool>().cloned().expect("Could not get SQLPool from data");