Add ping command to the bot

This commit is contained in:
louis chauvet 2018-09-19 23:12:35 +02:00
parent 203be35c7d
commit 6cc4f8fcdc
2 changed files with 45 additions and 0 deletions

30
modules/tools.py Normal file
View File

@ -0,0 +1,30 @@
import time
import discord
import traductions as tr
class MainClass:
name = "tools"
def __init__(self, guild):
self.guild = guild
async def ping(self, msg, command, args):
embed = discord.Embed(title=tr.tr[self.guild.config["lang"]]["modules"]["tools"]["ping"]["title"])
t1 = time.time()
reponse = await msg.channel.send(embed=embed)
for i in range(1, 5):
embed = discord.Embed(title=tr.tr[self.guild.config["lang"]]["modules"]["tools"]["ping"]["title"])
embed.add_field(name="Temps de réponse", value=str((time.time() - t1) / i) + "s ")
embed.add_field(name="Latence", value=str(self.guild.bot.latency))
await reponse.edit(embed=embed)
async def on_message(self, msg):
if msg.content.startswith(self.guild.config["prefix"]):
command, *args = msg.content.lstrip(self.guild.config["prefix"]).split(" ")
if command == "ping":
await self.ping(msg, command, args)
return

View File

@ -119,6 +119,21 @@ tr = {
},
"pi": "Voici les 2000 décimales de pi que vous avez demandé (à partir de la {debut}ème):",
},
"tools": {
"description": "Commandes utiles",
"help": {
"ping": {
"description": "Renvoie le temps de réponse du bot",
"examples": [
("`{prefix}ping`", "Affiche le temps de réponse du bot"),
],
},
},
"ping": {
"title": "Pong!"
}
},
},
"errors": {
"LangNotFoundError": "La langue {lang} est introuvable, tapez {prefix}list_lang pour voir les langues "