This repository has been archived on 2022-03-31. You can view files and clone it, but cannot push or open issues or pull requests.
bot-licence/cogs/commands.py
2020-10-14 02:50:24 +02:00

130 lines
No EOL
6.1 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import discord
from discord.ext import commands
from random import randint, choice
from datetime import datetime
import time
class Commands(commands.Cog):
"""Commandes générales du bot."""
def __init__(self, bot):
self.bot = bot
@commands.command()
async def ping(self, ctx, *, question = '0'):
"""Affiche mon ping.\n ➡ Syntaxe: .ping [help]"""
if question == 'help':
return await ctx.send(embed = discord.Embed(color = randint(0, 0xFFFFFF), description = ":hourglass: correspond au temps entre deux battements de cœurs (en millisecondes)\n\n:stopwatch: correspond au temps que met le bot a calculer le ping (en millisecondes)\n\n:heartbeat: correspond au temps que met le bot a réagir au messages (en millisecondes)"))
else:
now = int(round(time.time() * 1000))
ping = now - int(round(ctx.message.created_at.timestamp() * 1000))
embed = discord.Embed(description = 'Pinging...')
message = await ctx.send(embed = embed)
ping2 = int(round(time.time() * 1000)) - now
await message.edit(embed = discord.Embed(color = randint(0, 0xFFFFFF), description = f':hourglass: {round(self.bot.latency * 1000)}ms\n\n:stopwatch: {ping2}ms\n\n:heartbeat: {ping}ms'))
await ctx.message.add_reaction(emoji = '')
@commands.command()
async def calc(self, ctx, *, msg):
"""Calculatrice.\n ➡ Syntaxe: .calc <calcul>"""
equation = msg.replace('^', '**').replace('x', '*').replace('×', '*').replace('÷', '/').replace('', '>=').replace('', '<=')
try:
try:
if '=' in equation:
if '<' in equation:
left = eval(equation.split("<=")[0])
right = eval(equation.split("<=")[1])
answer = str(left <= right)
elif '>' in equation:
left = eval(equation.split(">=")[0])
right = eval(equation.split(">=")[1])
answer = str(left >= right)
else:
left = eval(equation.split("=")[0])
right = eval(equation.split("=")[1])
answer = str(left == right)
else:
answer = str(eval(equation))
except ZeroDivisionError:
return await ctx.send("Tu ne peux pas divisé par 0.")
except TypeError:
return await ctx.send("Requête de calcul invalide.")
if '.' in answer:
aftercomma = answer.split(".")[1]
if len(aftercomma) > 2:
answer = str(round(float(answer),2))
equation = f"'{equation}' arrondi à 2"
equation = equation.replace('*', '×').replace('/', '÷').replace('>=', '').replace('<=', '')
embed = discord.Embed(color = randint(0, 0xFFFFFF), title = 'Calculatrice')
embed.set_footer(text = ctx.author)
embed.add_field(name = 'Calcul :', value = equation, inline = False)
embed.add_field(name = 'Réponse :', value = answer.replace('False', 'Faux').replace('True', 'Vrai'), inline = False)
await ctx.message.add_reaction(emoji = '')
await ctx.send(content = None, embed = embed)
@calc.error
async def calc_error(self, ctx, error):
await ctx.send("Tu n'as pas spécifié de calcul.")
@commands.command()
async def syntax(self, ctx):
"""Informations pour bien éditer son texte."""
syntaxe = "-----------------------------------------------------\n"
syntaxe += discord.utils.escape_markdown("```Js\n")
syntaxe += discord.utils.escape_markdown("//code en js (possible de remplacer 'js' par d'autres languages . adaptez le !)\n")
syntaxe += discord.utils.escape_markdown('console.log("hi");\n')
syntaxe += discord.utils.escape_markdown("```\n")
syntaxe += "```Js\n"
syntaxe += "//code en js (possible de remplacer 'js' par d'autres languages . adaptez le !)\n"
syntaxe += 'console.log("hi");\n'
syntaxe += "```\n"
syntaxe += "-----------------------------------------------------\n"
syntaxe += discord.utils.escape_markdown("`code sur une seule ligne`\n")
syntaxe += "`code sur une seule ligne`\n"
syntaxe += "-----------------------------------------------------\n"
syntaxe += discord.utils.escape_markdown("*texte en italique*\n")
syntaxe += "*texte en italique*\n"
syntaxe += "-----------------------------------------------------\n"
syntaxe += discord.utils.escape_markdown("**text en gras**\n")
syntaxe += "**text en gras**\n"
syntaxe += "-----------------------------------------------------\n"
syntaxe += discord.utils.escape_markdown("***text en italique-gras***\n")
syntaxe += "***text en italique-gras***\n"
syntaxe += "-----------------------------------------------------\n"
syntaxe += discord.utils.escape_markdown("> cette ligne est cité\npas celle là\n")
syntaxe += "> cette ligne est cité\npas celle là\n"
syntaxe += "-----------------------------------------------------\n"
syntaxe += discord.utils.escape_markdown(">>> cette ligne est cité\ncelle là aussi (et elles le seront toutes!)\n")
syntaxe += ">>> cette ligne est cité\ncelle là aussi (et elles le seront toutes!)\n"
await ctx.message.add_reaction(emoji = '')
await ctx.send(syntaxe)
@commands.command(aliases = ['infos'])
async def info(self, ctx):
"""Donne des infos sur le bot.\n ➡ Syntaxe: .info/infos"""
embed = discord.Embed(url = 'https://github.com/Mylloon', color = randint(0, 0xFFFFFF))
embed.set_author(name='Bot Licence L1', icon_url=ctx.author.avatar_url)
total_online = len({m.id for m in self.bot.get_all_members() if m.status is discord.Status.online})
total_unique = len(self.bot.users)
voice_channels = []
text_channels = []
for guild in self.bot.guilds:
voice_channels.extend(guild.voice_channels)
text_channels.extend(guild.text_channels)
text = len(text_channels)
voice = len(voice_channels)
embed.add_field(name='Développeur', value='Mylloon#7869')
embed.add_field(name='Serveurs', value=len(self.bot.guilds))
embed.add_field(name='Membres', value=f'{total_unique} au total\n{total_online} en ligne')
embed.add_field(name='Channels', value=f'{text} textuelles\n{voice} vocales')
embed.set_footer(text=f'Basé sur discord.py {discord.__version__}')
await ctx.send(embed=embed)
def setup(bot):
bot.add_cog(Commands(bot))