Browse Source

Added ping time on the ping command

Penta 5 years ago
parent
commit
70eff52b88
2 changed files with 9 additions and 5 deletions
  1. 1 1
      myanimebot.py
  2. 8 4
      myanimebot/commands.py

+ 1 - 1
myanimebot.py

@@ -193,7 +193,7 @@ async def on_message(message):
 	if words[0] == globals.prefix:
 		if len(words) > 1:
 			if words[1] == "ping":
-				await commands.ping_cmd(channel)
+				await commands.ping_cmd(message, channel)
 			
 			elif words[1] == "here":
 				if in_allowed_role(message.author, message.guild):

+ 8 - 4
myanimebot/commands.py

@@ -1,12 +1,12 @@
 import discord
 import urllib
+import datetime
 
 from typing import List, Tuple
 
 import myanimebot.utils as utils
 import myanimebot.globals as globals
 
-
 def build_info_cmd_message(users, server, channels, filters : List[utils.Service]) -> str:
 	''' Build the corresponding message for the info command '''
 
@@ -182,9 +182,13 @@ async def info_cmd(message, words):
 			await message.channel.send(build_info_cmd_message(users, server, channels, filters))
 
 
-async def ping_cmd(channel):
-    ''' Responds to ping command '''
-    await channel.send("pong")
+async def ping_cmd(message, channel):
+	''' Responds to ping command '''
+	messageTimestamp = message.created_at
+	currentTimestamp = datetime.datetime.utcnow()
+	delta = round((currentTimestamp - messageTimestamp).total_seconds() * 1000)
+	
+	await channel.send("pong (" + str(delta) + "ms)")
 
 
 async def about_cmd(channel):