1+ use std:: collections:: HashMap ;
12use crate :: bot:: ShardManagerKey ;
23use crate :: commands:: { BoxFuture , CommunityRegistrable , RegistrableCommand } ;
34use crate :: config:: Config ;
4- use crate :: errors:: ModmailResult ;
5+ use crate :: errors:: { DiscordError , ModmailError , ModmailResult } ;
56use crate :: handlers:: InteractionHandler ;
67use crate :: i18n:: get_translated_message;
78use serenity:: FutureExt ;
89use serenity:: all:: { CommandInteraction , Context , CreateCommand , ResolvedOption } ;
910use std:: sync:: Arc ;
11+ use std:: time:: Duration ;
12+ use crate :: utils:: { defer_response, MessageBuilder } ;
1013
1114pub struct PingCommand ;
1215
@@ -56,6 +59,8 @@ impl RegistrableCommand for PingCommand {
5659 let config = config. clone ( ) ;
5760
5861 Box :: pin ( async move {
62+ defer_response ( & ctx, & command) . await ?;
63+
5964 let shard_manager = ctx
6065 . data
6166 . read ( )
@@ -69,7 +74,16 @@ impl RegistrableCommand for PingCommand {
6974 runners. get ( & ctx. shard_id ) . and_then ( |runner| runner. latency )
7075 } ;
7176
72- println ! ( "Latency for shard {}: {:?}" , ctx. shard_id, latency) ;
77+ let mut params = HashMap :: new ( ) ;
78+ params. insert ( "latency" . to_string ( ) , format ! ( "{:?}" , latency. unwrap_or( Duration :: default ( ) ) . as_millis( ) ) ) ;
79+
80+ let response = MessageBuilder :: system_message ( & ctx, & config)
81+ . translated_content ( "slash_command.ping_command" , Some ( & params) , None , None ) . await
82+ . to_channel ( command. channel_id )
83+ . build_interaction_message_followup ( ) . await ;
84+
85+ command. create_followup ( & ctx. http , response) . await
86+ . map_err ( |e| ModmailError :: Discord ( DiscordError :: ApiError ( e. to_string ( ) ) ) ) ?;
7387
7488 Ok ( ( ) )
7589 } )
0 commit comments