From bb4c96a6286bea2a0560b5e6482cefe4f5a14aed Mon Sep 17 00:00:00 2001 From: jude Date: Tue, 1 Sep 2020 18:48:40 +0100 Subject: [PATCH] ping command --- src/commands/info_cmds.rs | 22 ++++++++++++++++++++-- src/commands/moderation_cmds.rs | 2 ++ src/commands/reminder_cmds.rs | 4 ++++ src/main.rs | 3 +++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/commands/info_cmds.rs b/src/commands/info_cmds.rs index a26af4f..15c97aa 100644 --- a/src/commands/info_cmds.rs +++ b/src/commands/info_cmds.rs @@ -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)] diff --git a/src/commands/moderation_cmds.rs b/src/commands/moderation_cmds.rs index 1d9dadf..fb284e5 100644 --- a/src/commands/moderation_cmds.rs +++ b/src/commands/moderation_cmds.rs @@ -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::().cloned().expect("Could not get SQLPool from data"); diff --git a/src/commands/reminder_cmds.rs b/src/commands/reminder_cmds.rs index 55ff6f2..2265da9 100644 --- a/src/commands/reminder_cmds.rs +++ b/src/commands/reminder_cmds.rs @@ -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::().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::().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::().cloned().expect("Could not get SQLPool from data"); diff --git a/src/main.rs b/src/main.rs index 16b19d2..1fc76cb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,6 +58,9 @@ async fn main() -> Result<(), Box> { let framework = RegexFramework::new(env::var("CLIENT_ID").expect("Missing CLIENT_ID from environment").parse()?) .ignore_bots(true) .default_prefix("$") + + .add_command("ping", &info_cmds::PING_COMMAND) + .add_command("help", &info_cmds::HELP_COMMAND) .add_command("info", &info_cmds::INFO_COMMAND) .add_command("donate", &info_cmds::DONATE_COMMAND)