first commit

This commit is contained in:
Mylloon 2020-10-14 03:02:43 +02:00
parent 0432400880
commit 56be15c10f
6 changed files with 226 additions and 217 deletions

0
.gitignore vendored Normal file → Executable file
View file

11
README.md Normal file → Executable file
View file

@ -15,4 +15,13 @@ token = "ton token"
#### __Mise en marche__
- Lancer [main.py](main.py)
- Lancer [main.py](main.py)
## __Commandes__
- Gestion des réactions à un certain message + attribution des rôles correspondant
- Commande info pour une liste d'informations sur le bot
- Commande calculatrice pour faire des calculs simples
- Commande help pour plus de précisions sur les commandes
- Commande syntax qui explique la syntaxe sur Discord
- Commande ping pour vérifier le ping du bot

218
cogs/commands.py Normal file → Executable file
View file

@ -5,126 +5,126 @@ from datetime import datetime
import time
class Commands(commands.Cog):
"""Commandes générales du bot."""
"""Commandes générales du bot."""
def __init__(self, bot):
self.bot = 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 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)
@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.")
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()
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))
@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)
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)
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)
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)
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)
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))
bot.add_cog(Commands(bot))

100
cogs/help.py Normal file → Executable file
View file

@ -3,57 +3,57 @@ from discord.ext import commands
from random import randint
class Help(commands.Cog):
"""Listes des commandes et/ou catégories."""
"""Listes des commandes et/ou catégories."""
def __init__(self, bot):
self.bot = bot
def __init__(self, bot):
self.bot = bot
@commands.command()
async def help(self, ctx, *cog):
"""Affiche toutes les commandes du bot.\n ➡ Syntaxe: .help [catégorie]"""
if not cog:
"""Liste des Cog"""
halp=discord.Embed(title = 'Liste des catégories et commandes non catégorisées',
description = 'Utilisez `.help *Catégorie*` pour en savoir plus sur eux !',
color = randint(0, 0xFFFFFF))
cogs_desc = ''
for x in self.bot.cogs:
cogs_desc += (f'{x} - {self.bot.cogs[x].__doc__}\n')
halp.add_field(name = 'Catégories', value = cogs_desc[0:len(cogs_desc)-1], inline = False)
cmds_desc = ''
for y in self.bot.walk_commands():
if not y.cog_name and not y.hidden:
cmds_desc += (f'.{y.name} - {y.help}\n ')
if len(cmds_desc) > 1:
halp.add_field(name = 'Commandes sans catégories', value = cmds_desc[0:len(cmds_desc)-1], inline = False)
await ctx.message.add_reaction(emoji = '')
await ctx.send(embed = halp)
else:
"""Avertissement si il y a trop d'arguments dans la variable cog"""
if len(cog) > 1:
halp = discord.Embed(title = 'Erreur !', description = "Tu as renseigné trop d'arguments !", color = 0xC41B1B)
await ctx.send(embed = halp)
else:
"""Liste des commandes avec cogs."""
cog = [item.capitalize() for item in cog]
@commands.command()
async def help(self, ctx, *cog):
"""Affiche toutes les commandes du bot.\n ➡ Syntaxe: .help [catégorie]"""
if not cog:
"""Liste des Cog"""
halp=discord.Embed(title = 'Liste des catégories et commandes non catégorisées',
description = 'Utilisez `.help *Catégorie*` pour en savoir plus sur eux !',
color = randint(0, 0xFFFFFF))
cogs_desc = ''
for x in self.bot.cogs:
cogs_desc += (f'{x} - {self.bot.cogs[x].__doc__}\n')
halp.add_field(name = 'Catégories', value = cogs_desc[0:len(cogs_desc)-1], inline = False)
cmds_desc = ''
for y in self.bot.walk_commands():
if not y.cog_name and not y.hidden:
cmds_desc += (f'.{y.name} - {y.help}\n ')
if len(cmds_desc) > 1:
halp.add_field(name = 'Commandes sans catégories', value = cmds_desc[0:len(cmds_desc)-1], inline = False)
await ctx.message.add_reaction(emoji = '')
await ctx.send(embed = halp)
else:
"""Avertissement si il y a trop d'arguments dans la variable cog"""
if len(cog) > 1:
halp = discord.Embed(title = 'Erreur !', description = "Tu as renseigné trop d'arguments !", color = 0xC41B1B)
await ctx.send(embed = halp)
else:
"""Liste des commandes avec cogs."""
cog = [item.capitalize() for item in cog]
found = False
for x in self.bot.cogs:
for y in cog:
if x == y:
halp = discord.Embed(title = f'{cog[0]} - Liste des commandes', description = self.bot.cogs[cog[0]].__doc__, color = randint(0, 0xFFFFFF))
for c in self.bot.get_cog(y).get_commands():
if not c.hidden:
halp.add_field(name = f".{c.name}", value = f"{c.help}\n ", inline = False)
found = True
if not found:
"""Rappel si le cog n'existe pas."""
await ctx.message.add_reaction(emoji = '')
halp = discord.Embed(title = 'Erreur !', description = f"Qu'est ce que {cog[0]} ?", color = 0xC41B1B)
else:
await ctx.message.add_reaction(emoji = '')
await ctx.send('', embed = halp)
found = False
for x in self.bot.cogs:
for y in cog:
if x == y:
halp = discord.Embed(title = f'{cog[0]} - Liste des commandes', description = self.bot.cogs[cog[0]].__doc__, color = randint(0, 0xFFFFFF))
for c in self.bot.get_cog(y).get_commands():
if not c.hidden:
halp.add_field(name = f".{c.name}", value = f"{c.help}\n ", inline = False)
found = True
if not found:
"""Rappel si le cog n'existe pas."""
await ctx.message.add_reaction(emoji = '')
halp = discord.Embed(title = 'Erreur !', description = f"Qu'est ce que {cog[0]} ?", color = 0xC41B1B)
else:
await ctx.message.add_reaction(emoji = '')
await ctx.send('', embed = halp)
def setup(bot):
bot.add_cog(Help(bot))
bot.add_cog(Help(bot))

112
main.py Normal file → Executable file
View file

@ -12,74 +12,74 @@ async def on_connect():
@client.event
async def on_ready():
await client.change_presence(status = discord.Status.online, activity = discord.Activity(name = "devenir fort en info", type = discord.ActivityType.playing))
print("Bot chargé à 100%.")
await client.change_presence(status = discord.Status.online, activity = discord.Activity(name = "devenir fort en info", type = discord.ActivityType.playing))
print("Bot chargé à 100%.")
@client.event
async def on_raw_reaction_add(payload):
if payload.message_id == 765470422149365760:
if payload.emoji.name == '🟡':
role = discord.utils.get(payload.member.guild.roles, name="L1A1")
await payload.member.add_roles(role)
if payload.emoji.name == '🟠':
role = discord.utils.get(payload.member.guild.roles, name="L1A2")
await payload.member.add_roles(role)
if payload.emoji.name == '🔵':
role = discord.utils.get(payload.member.guild.roles, name="L1B1")
await payload.member.add_roles(role)
if payload.emoji.name == '🟣':
role = discord.utils.get(payload.member.guild.roles, name="L1B2")
await payload.member.add_roles(role)
if payload.emoji.name == '🟤':
role = discord.utils.get(payload.member.guild.roles, name="L1C1")
await payload.member.add_roles(role)
if payload.emoji.name == '🟢':
role = discord.utils.get(payload.member.guild.roles, name="L1C2")
await payload.member.add_roles(role)
if payload.message_id == 765470422149365760:
if payload.emoji.name == '🟡':
role = discord.utils.get(payload.member.guild.roles, name="L1A1")
await payload.member.add_roles(role)
if payload.emoji.name == '🟠':
role = discord.utils.get(payload.member.guild.roles, name="L1A2")
await payload.member.add_roles(role)
if payload.emoji.name == '🔵':
role = discord.utils.get(payload.member.guild.roles, name="L1B1")
await payload.member.add_roles(role)
if payload.emoji.name == '🟣':
role = discord.utils.get(payload.member.guild.roles, name="L1B2")
await payload.member.add_roles(role)
if payload.emoji.name == '🟤':
role = discord.utils.get(payload.member.guild.roles, name="L1C1")
await payload.member.add_roles(role)
if payload.emoji.name == '🟢':
role = discord.utils.get(payload.member.guild.roles, name="L1C2")
await payload.member.add_roles(role)
@client.event
async def on_raw_reaction_remove(payload):
if payload.message_id == 765470422149365760:
if payload.emoji.name == '🟡':
guild = discord.utils.find(lambda g : g.id == payload.guild_id, client.guilds)
member = discord.utils.find(lambda m: m.id == payload.user_id, guild.members)
role = discord.utils.get(guild.roles, name="L1A1")
await member.remove_roles(role)
if payload.emoji.name == '🟠':
guild = discord.utils.find(lambda g : g.id == payload.guild_id, client.guilds)
member = discord.utils.find(lambda m: m.id == payload.user_id, guild.members)
role = discord.utils.get(guild.roles, name="L1A2")
await member.remove_roles(role)
if payload.emoji.name == '🔵':
guild = discord.utils.find(lambda g : g.id == payload.guild_id, client.guilds)
member = discord.utils.find(lambda m: m.id == payload.user_id, guild.members)
role = discord.utils.get(guild.roles, name="L1B1")
await member.remove_roles(role)
if payload.emoji.name == '🟣':
guild = discord.utils.find(lambda g : g.id == payload.guild_id, client.guilds)
member = discord.utils.find(lambda m: m.id == payload.user_id, guild.members)
role = discord.utils.get(guild.roles, name="L1B2")
await member.remove_roles(role)
if payload.emoji.name == '🟤':
guild = discord.utils.find(lambda g : g.id == payload.guild_id, client.guilds)
member = discord.utils.find(lambda m: m.id == payload.user_id, guild.members)
role = discord.utils.get(guild.roles, name="L1C1")
await member.remove_roles(role)
if payload.emoji.name == '🟢':
guild = discord.utils.find(lambda g : g.id == payload.guild_id, client.guilds)
member = discord.utils.find(lambda m: m.id == payload.user_id, guild.members)
role = discord.utils.get(guild.roles, name="L1C2")
await member.remove_roles(role)
if payload.message_id == 765470422149365760:
if payload.emoji.name == '🟡':
guild = discord.utils.find(lambda g : g.id == payload.guild_id, client.guilds)
member = discord.utils.find(lambda m: m.id == payload.user_id, guild.members)
role = discord.utils.get(guild.roles, name="L1A1")
await member.remove_roles(role)
if payload.emoji.name == '🟠':
guild = discord.utils.find(lambda g : g.id == payload.guild_id, client.guilds)
member = discord.utils.find(lambda m: m.id == payload.user_id, guild.members)
role = discord.utils.get(guild.roles, name="L1A2")
await member.remove_roles(role)
if payload.emoji.name == '🔵':
guild = discord.utils.find(lambda g : g.id == payload.guild_id, client.guilds)
member = discord.utils.find(lambda m: m.id == payload.user_id, guild.members)
role = discord.utils.get(guild.roles, name="L1B1")
await member.remove_roles(role)
if payload.emoji.name == '🟣':
guild = discord.utils.find(lambda g : g.id == payload.guild_id, client.guilds)
member = discord.utils.find(lambda m: m.id == payload.user_id, guild.members)
role = discord.utils.get(guild.roles, name="L1B2")
await member.remove_roles(role)
if payload.emoji.name == '🟤':
guild = discord.utils.find(lambda g : g.id == payload.guild_id, client.guilds)
member = discord.utils.find(lambda m: m.id == payload.user_id, guild.members)
role = discord.utils.get(guild.roles, name="L1C1")
await member.remove_roles(role)
if payload.emoji.name == '🟢':
guild = discord.utils.find(lambda g : g.id == payload.guild_id, client.guilds)
member = discord.utils.find(lambda m: m.id == payload.user_id, guild.members)
role = discord.utils.get(guild.roles, name="L1C2")
await member.remove_roles(role)
try:
client.load_extension("cogs.commands")
client.load_extension("cogs.commands")
except Exception as error:
print(error)
print(error)
client.remove_command("help")
try:
client.load_extension("cogs.help")
client.load_extension("cogs.help")
except Exception as error:
print(error)
print(error)
client.run(token)

2
requirements.txt Normal file → Executable file
View file

@ -1,2 +1,2 @@
discord.py>=1.4.0
async-timeout>=3.0.1
async-timeout>=3.0.1