update (cogs.basics>ping): optimisation
Remove unused parts
This commit is contained in:
parent
783f7507f0
commit
951784718b
1 changed files with 68 additions and 71 deletions
139
cogs/basics.py
139
cogs/basics.py
|
@ -1,71 +1,68 @@
|
||||||
import platform
|
import platform
|
||||||
import socket
|
import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from discord.http import Route
|
from discord.http import Route
|
||||||
|
|
||||||
|
|
||||||
class Basics(commands.Cog):
|
class Basics(commands.Cog):
|
||||||
"""Commandes générales."""
|
"""Commandes générales."""
|
||||||
|
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def ping(self, ctx):
|
async def ping(self, ctx):
|
||||||
ping_res = str(subprocess.Popen(["/bin/ping", "-c1", "discord.com"],
|
result = self.bot.latency * 1000
|
||||||
stdout=subprocess.PIPE).stdout.read())
|
|
||||||
formated_res = [item for item in ping_res.split() if 'time=' in item]
|
if float(result) >= 300:
|
||||||
result = self.bot.latency * 1000 # str(formated_res[0])[5:]
|
em = discord.Embed(title="Ping : " + str(result) + "ms",
|
||||||
|
description="... c'est quoi ce ping !",
|
||||||
if float(result) >= 200:
|
colour=0xFF1111)
|
||||||
em = discord.Embed(title="Ping : " + str(result) + "ms",
|
await ctx.send(embed=em)
|
||||||
description="... c'est quoi ce ping !",
|
elif float(result) > 200:
|
||||||
colour=0xFF1111)
|
em = discord.Embed(title="Ping : " + str(result) + "ms",
|
||||||
await ctx.send(embed=em)
|
description="Ca va, ça peut aller, mais j'ai "
|
||||||
elif float(result) > 100 < 200:
|
"l'impression d'avoir 40 ans !",
|
||||||
em = discord.Embed(title="Ping : " + str(result) + "ms",
|
colour=0xFFA500)
|
||||||
description="Ca va, ça peut aller, mais j'ai "
|
await ctx.send(embed=em)
|
||||||
"l'impression d'avoir 40 ans !",
|
else:
|
||||||
colour=0xFFA500)
|
em = discord.Embed(title="Ping : " + str(result) + "ms",
|
||||||
await ctx.send(embed=em)
|
description="Wow c'te vitesse de réaction, "
|
||||||
else:
|
"je m'épate moi-même !",
|
||||||
em = discord.Embed(title="Ping : " + str(result) + "ms",
|
colour=0x11FF11)
|
||||||
description="Wow c'te vitesse de réaction, "
|
await ctx.send(embed=em)
|
||||||
"je m'épate moi-même !",
|
|
||||||
colour=0x11FF11)
|
"""---------------------------------------------------------------------"""
|
||||||
await ctx.send(embed=em)
|
|
||||||
|
@commands.command()
|
||||||
"""---------------------------------------------------------------------"""
|
async def info(self, ctx):
|
||||||
|
"""Affiches des informations sur le bot"""
|
||||||
@commands.command()
|
text = open('texts/info.md').read()
|
||||||
async def info(self, ctx):
|
os_info = str(platform.system()) + " / " + str(platform.release())
|
||||||
"""Affiches des informations sur le bot"""
|
em = discord.Embed(title='Informations sur TuxBot',
|
||||||
text = open('texts/info.md').read()
|
description=text.format(os_info,
|
||||||
os_info = str(platform.system()) + " / " + str(platform.release())
|
platform.python_version(),
|
||||||
em = discord.Embed(title='Informations sur TuxBot',
|
socket.gethostname(),
|
||||||
description=text.format(os_info,
|
discord.__version__,
|
||||||
platform.python_version(),
|
Route.BASE),
|
||||||
socket.gethostname(),
|
colour=0x89C4F9)
|
||||||
discord.__version__,
|
em.set_footer(text="/home/****/bot.py")
|
||||||
Route.BASE),
|
await ctx.send(embed=em)
|
||||||
colour=0x89C4F9)
|
|
||||||
em.set_footer(text="/home/****/bot.py")
|
"""---------------------------------------------------------------------"""
|
||||||
await ctx.send(embed=em)
|
|
||||||
|
@commands.command()
|
||||||
"""---------------------------------------------------------------------"""
|
async def help(self, ctx, page: int = 1):
|
||||||
|
"""Affiches l'aide du bot"""
|
||||||
@commands.command()
|
page = int(page) if 0 < int(page) < 5 else 1
|
||||||
async def help(self, ctx, page: int = 1):
|
text = open('texts/help.md').read().split("[split]")
|
||||||
"""Affiches l'aide du bot"""
|
em = discord.Embed(title='Commandes de TuxBot', description=text[page - 1],
|
||||||
page = int(page) if 0 < int(page) < 5 else 1
|
colour=0x89C4F9)
|
||||||
text = open('texts/help.md').read().split("[split]")
|
await ctx.send(content=f"page {page}/{len(text)}", embed=em)
|
||||||
em = discord.Embed(title='Commandes de TuxBot', description=text[page - 1],
|
|
||||||
colour=0x89C4F9)
|
|
||||||
await ctx.send(content=f"page {page}/{len(text)}", embed=em)
|
def setup(bot):
|
||||||
|
bot.add_cog(Basics(bot))
|
||||||
|
|
||||||
def setup(bot):
|
|
||||||
bot.add_cog(Basics(bot))
|
|
||||||
|
|
Loading…
Reference in a new issue