async def annonce_msg(client: discord.Client, message: discord.Message, args: List[str]): with open('run/config/config.yml', 'r') as file: config = yaml.safe_load(file) # Check permissions if not PermissionsManager.has_perm(message.author, 'annonce'): return await message.channel.send(embed=EmbedsManager.error_embed( "Vous n'avez pas les permissions pour cette commande.")) # Help message if args and args[0] == '-h': return await message.channel.send(embed=EmbedsManager.information_embed( "Rappel de la commande : \n" f"`{config['prefix']}annonce <#channel> <couleur> <contenue>`\n" f"La couleur doit etre au format hexadécimale (FFFFFF) sans le #." f" Une image peut etre ajouté à la commande.")) if len(message.channel_mentions) != 1: return await message.channel.send(embed=EmbedsManager.error_embed( f":x: Erreur dans la commande. Merci de specifier un channel")) # Get channel channel: discord.TextChannel = message.channel_mentions[0] args.pop(0) # Get color if not args: return await message.channel.send(embed=EmbedsManager.error_embed( f":x: Erreur dans la commande. Merci de specifier une couleur valide." )) try: color = int(args.pop(0), 16) except: return await message.channel.send(embed=EmbedsManager.error_embed( f":x: Erreur dans la commande. Merci de specifier une couleur valide." )) # Get content if not args: return await message.channel.send(embed=EmbedsManager.error_embed( f":x: Erreur dans la commande. Merci de specifier un contenue valide." )) content = ' '.join(args) embed = discord.Embed(color=color) embed.description = content # Get image if message.attachments: embed.set_image(url=message.attachments[0].url) try: await channel.send(embed=embed) await message.channel.send(embed=EmbedsManager.complete_embed( f"Le message a bien été envoyé dans {channel} : \n {content}")) except: await message.channel.send(embed=EmbedsManager.error_embed( "Je n'ai pas les permissions pour ce salon."))
async def change_prefix(client: discord.Client, message: discord.Message, args: List[str]): with open('run/config/config.yml', 'r') as file: config = yaml.safe_load(file) # Check permissions if not PermissionsManager.has_perm(message.author, 'prefix'): return await message.channel.send(embed=EmbedsManager.error_embed( "Vous n'avez pas les permissions pour cette commande.")) # Help message if args and args[0] == '-h': return await message.channel.send( embed=EmbedsManager.information_embed( "Rappel de la commande : \n" f"`{config['prefix']}prefix <nouveau prefix>`")) # Check input if len(args) != 1: await message.channel.send(embed=EmbedsManager.error_embed( f"Erreur dans la commande.\nRappel : `{config['prefix']}prefix <nouveau prefix>`" )) return await message.channel.send(embed=EmbedsManager.complete_embed( f"⚙ Le préfix `{config['prefix']}` a été changé par `{args[0]}`.")) with open('run/config/config.yml', 'w', encoding='utf8') as outfile: yaml.dump(config, outfile, default_flow_style=False, allow_unicode=True)
async def remove_customcommands(client: discord.Client, message: discord.Message, args: List[str]): with open('run/config/config.yml', 'r') as file: config = yaml.safe_load(file) # Check permissions if not PermissionsManager.has_perm(message.author, 'custom_commands'): return await message.channel.send(embed=EmbedsManager.error_embed( "Vous n'avez pas les permissions pour cette commande.")) # Help message if args and args[0] == '-h': return await message.channel.send( embed=EmbedsManager.information_embed( "Rappel de la commande : \n" f"`{config['prefix']}remove_command <command_id>`")) # Check inputs if len(args) != 1: return await message.channel.send( embed=EmbedsManager.error_embed(f":x: Erreur dans la commande.")) command_name = args[0] custom_commands: List[CustomCommand] = session.query( CustomCommand).filter_by(command=command_name).all() if len(custom_commands) != 1: return await message.channel.send(embed=EmbedsManager.error_embed( f":x: Erreur. Je ne trouve pas cette commande.")) session.delete(custom_commands[0]) session.commit() await message.channel.send(embed=EmbedsManager.complete_embed( f"Je viens de supprimer la commande **{command_name}**."))
async def kick_member(client: discord.Client, message: discord.Message, args: List[str]): with open('run/config/config.yml', 'r') as file: config = yaml.safe_load(file) # Check permissions if not PermissionsManager.has_perm(message.author, 'kick'): return await message.channel.send(embed=EmbedsManager.error_embed( "Vous n'avez pas les permissions pour cette commande.")) # Help message if args and args[0] == '-h': return await message.channel.send( embed=EmbedsManager.information_embed( "Rappel de la commande : \n" f"`{config['prefix']}kick <@pseudo> <reason>`\n" f"`{config['prefix']}kick <@pseudo> -r <reason_id>`")) # Check inputs if len(message.mentions) != 1: return await message.channel.send(embed=EmbedsManager.error_embed( ":x: Erreur dans la commande. Merci de mentionner un utilisateur.") ) if len(args) < 2: return await message.channel.send(embed=EmbedsManager.error_embed( ":x: Erreur dans la commande. Merci de mettre une raison.")) with open('run/config/reasons.yml', 'r', encoding='utf8') as file: reasons = yaml.safe_load(file) current_reason = "" if args[0] == '-r': # Saved reason try: for reason_index in args[1:]: current_reason += f"- {reasons[int(reason_index)]}\n" except: return await message.channel.send(embed=EmbedsManager.error_embed( ":x: Erreur dans la commande. Merci de mettre un index d'erreur valide." )) else: # Custom reason current_reason = " ".join(args) new_kick = Kick(message.mentions[0].id, message.author.id, current_reason) session.add(new_kick) session.commit() await message.channel.send(embed=EmbedsManager.complete_embed( f"👢 Le membre **{message.mentions[0]}** a été kické (id `k{new_kick.id}`):\n{current_reason}" )) await message.mentions[0].kick()
async def unfreeze_server(client: discord.Client, message: discord.Message, args: List[str]): with open('run/config/config.yml', 'r') as file: config = yaml.safe_load(file) # Check permissions if not PermissionsManager.has_perm(message.author, 'freeze'): return await message.channel.send(embed=EmbedsManager.error_embed( "Vous n'avez pas les permissions pour cette commande.")) # Help message if args and args[0] == '-h': return await message.channel.send( embed=EmbedsManager.information_embed( "Rappel de la commande : \n" f"`{config['prefix']}rfreeze`")) # Check inputs current_message: discord.Message = await message.channel.send( embed=EmbedsManager.complete_embed( f"{message.author.mention} Vous avez décidé de dégeler le serveur.\n" + f"Confirmer vous ce choix ?")) await current_message.add_reaction('✅') await current_message.add_reaction('❌') def check(reaction: discord.Reaction, user: discord.User): return user == message.author and (str(reaction.emoji) == '✅' or str(reaction.emoji) == '❌') try: reaction, user = await client.wait_for('reaction_add', timeout=20.0, check=check) except asyncio.TimeoutError: await message.channel.send(embed=EmbedsManager.error_embed( f"Vous avez __refusé__ le dégel du serveur.")) else: if str(reaction.emoji) == '❌': return await message.channel.send(embed=EmbedsManager.error_embed( f"Vous avez __refusé__ le dégel du serveur.")) await message.channel.send( embed=EmbedsManager.complete_embed(f"Le serveur a été dégelé")) members: List[discord.Member] = message.guild.members for member in members: if not member.guild_permissions.manage_messages: for channel in message.guild.channels: if not member.permissions_in(channel).send_messages: await channel.set_permissions(member, overwrite=None)
async def get_reasons_list(client: discord.Client, message: discord.Message): if not PermissionsManager.has_perm(message.author, 'manage_reason'): await message.channel.send(embed=EmbedsManager.error_embed( "Vous n'avez pas les permissions pour cette commande.")) return with open('run/config/reasons.yml', 'r', encoding='utf8') as file: reasons = yaml.safe_load(file) content = f"{message.author.mention} voici la liste des **raisons** des sanctions :\n" for i in range(len(reasons)): content += f"\n**Raison {i+1} :** {reasons[i]}" await message.channel.send(embed=EmbedsManager.complete_embed(content))
async def revoke_mute(client: discord.Client, message: discord.Message, args: List[str]): with open('run/config/config.yml', 'r') as file: config = yaml.safe_load(file) if not PermissionsManager.has_perm(message.author, 'mute'): return await message.channel.send(embed=EmbedsManager.error_embed( "Vous n'avez pas les permissions pour cette commande.")) # Help message if args and args[0] == '-h': return await message.channel.send( embed=EmbedsManager.information_embed( "Rappel de la commande : \n" f"`{config['prefix']}rmute <mute_id>`")) if len(args) != 1: return await message.channel.send(embed=EmbedsManager.error_embed( f":x: Erreur dans la commande, merci de spécifier l'index du mute." )) if not args[0].startswith("m"): return await message.channel.send( embed=EmbedsManager.error_embed(":x: Erreur, index invalide.")) index = int(args[0][1:]) current_mute: Mute = session.query(Mute).filter_by(id=index).first() if current_mute is None: return await message.channel.send( embed=EmbedsManager.error_embed(":x: Erreur, index invalide.")) if not current_mute.is_active: return await message.channel.send(embed=EmbedsManager.error_embed( ":x: Erreur, ce mute est déjà révoqué.")) current_mute.is_active = False session.commit() target: discord.Member = message.guild.get_member(current_mute.target_id) for channel in message.guild.channels: if not target.permissions_in(channel).send_messages: await channel.set_permissions(target, overwrite=None) await message.channel.send(embed=EmbedsManager.complete_embed( f"⚠ Le mute **{args[0]}** a été révoqué."))
async def revoke_warn(client: discord.Client, message: discord.Message, args: List[str]): with open('run/config/config.yml', 'r') as file: config = yaml.safe_load(file) # Check permissions if not PermissionsManager.has_perm(message.author, 'warn'): return await message.channel.send(embed=EmbedsManager.error_embed( "Vous n'avez pas les permissions pour cette commande.")) # Help message if args and args[0] == '-h': return await message.channel.send( embed=EmbedsManager.information_embed( "Rappel de la commande : \n" f"`{config['prefix']}rwarn <warn_id>`")) # Check inputs if len(args) != 1: return await message.channel.send(embed=EmbedsManager.error_embed( f":x: Erreur dans la commande, merci de spécifier l'index de l'avertissement." )) if not args[0].startswith("w"): return await message.channel.send( embed=EmbedsManager.error_embed(f":x: Erreur, index invalide.")) # Process code index = int(args[0][1:]) current_warn: Warn = session.query(Warn).filter_by(id=index).first() if current_warn is None: return await message.channel.send( embed=EmbedsManager.error_embed(f":x: Erreur, index invalide.")) if not current_warn.is_active: return await message.channel.send(embed=EmbedsManager.error_embed( ":x: Erreur, cet avertissement est déjà révoqué.")) current_warn.is_active = False session.commit() await message.channel.send(embed=EmbedsManager.complete_embed( f"🔨 L'avertissement **{args[0]}** a été révoqué."))
async def add_reason(client: discord.Client, message: discord.Message, args: List[str]): with open('run/config/config.yml', 'r') as file: config = yaml.safe_load(file) # Check permissions if not PermissionsManager.has_perm(message.author, 'manage_reason'): return await message.channel.send( embed=EmbedsManager.error_embed( "Vous n'avez pas les permissions pour cette commande." ) ) # Help message if args and args[0] == '-h': return await message.channel.send( embed=EmbedsManager.information_embed( "Rappel de la commande : \n" f"`{config['prefix']}reason_add <reason>`" ) ) # Check inputs if len(args) < 2: return await message.channel.send( embed=EmbedsManager.error_embed( f":x: Merci de mettre une raison d'au moins deux mots." ) ) # Process code with open('run/config/reasons.yml', 'r', encoding='utf8') as file: reasons = yaml.safe_load(file) reasons.append((' '.join(args))) with open('run/config/reasons.yml', 'w', encoding='utf8') as outfile: yaml.dump(reasons, outfile, default_flow_style=False, allow_unicode=True) await message.channel.send( embed=EmbedsManager.complete_embed( f"{message.author.mention} La raison `{reasons[-1]}` a été ajouté à la liste.\n" f"Son numéro d'attribution est le {len(reasons)}." ) )
async def add_customcommands(client: discord.Client, message: discord.Message, args: List[str]): with open('run/config/config.yml', 'r') as file: config = yaml.safe_load(file) # Check permissions if not PermissionsManager.has_perm(message.author, 'custom_commands'): return await message.channel.send( embed=EmbedsManager.error_embed( "Vous n'avez pas les permissions pour cette commande." ) ) # Help message if args and args[0] == '-h': return await message.channel.send( embed=EmbedsManager.information_embed( "Rappel de la commande : \n" f"`{config['prefix']}add_command <name> <content>`" ) ) # Process code if len(args) < 2: return await message.channel.send( embed=EmbedsManager.error_embed( f":x: Erreur dans la commande." ) ) command_name = args[0] command_content = ' '.join(args[1:]) await message.channel.send( embed=EmbedsManager.complete_embed( f"{message.author.mention} vient de créer une nouvelle commande :\n" f"**Nom :** {command_name}\n" f"**Contenue :** {command_content}." ) ) custom_command = CustomCommand(command_name, command_content) session.add(custom_command) session.commit()
async def mute_member(client: discord.Client, message: discord.Message, args: List[str]): with open('run/config/config.yml', 'r') as file: config = yaml.safe_load(file) # Check permissions if not PermissionsManager.has_perm(message.author, 'mute'): return await message.channel.send(embed=EmbedsManager.error_embed( "Vous n'avez pas les permissions pour cette commande.")) # Help message if args and args[0] == '-h': return await message.channel.send( embed=EmbedsManager.information_embed( "Rappel de la commande : \n" f"`{config['prefix']}mute <@pseudo> <reason>`\n" f"`{config['prefix']}mute <@pseudo> -r <reason_id>`")) # Check inputs if len(message.mentions) != 1: return await message.channel.send(embed=EmbedsManager.error_embed( f":x: Erreur dans la commande. Merci de mentionner un utilisateur." )) if len(args) < 3: return await message.channel.send(embed=EmbedsManager.error_embed( f":x: Erreur dans la commande. Merci de mettre une raison.")) # Process code args = args[1:] if not args[0].isdigit(): return await message.channel.send(embed=EmbedsManager.error_embed( f":x: Erreur dans la commande. Merci de mettre une durée valide.")) duration: int = int(args[0]) args = args[1:] with open('run/config/reasons.yml', 'r', encoding='utf8') as file: reasons = yaml.safe_load(file) current_reason = "" if args[0] == '-r': # Saved reason try: for reason_index in args[1:]: current_reason += f"- {reasons[int(reason_index)]}\n" except: return await message.channel.send(embed=EmbedsManager.error_embed( f":x: Erreur dans la commande. Merci de mettre un index d'erreur valide." )) else: # Custom reason current_reason = " ".join(args) new_mute = Mute(message.mentions[0].id, message.author.id, current_reason, duration) session.add(new_mute) session.commit() # Remove permission target: discord.Member = message.mentions[0] for channel in message.guild.channels: if target.permissions_in(channel).read_messages: await channel.set_permissions(target, send_messages=False) await message.channel.send(embed=EmbedsManager.complete_embed( f"⚠ Le membre **{message.mentions[0]}** a été mute (id `m{new_mute.id}`):\n{current_reason}" ))
async def remove_reason(client: discord.Client, message: discord.Message, args: List[str]): with open('run/config/config.yml', 'r') as file: config = yaml.safe_load(file) # Check permissions if not PermissionsManager.has_perm(message.author, 'manage_reason'): return await message.channel.send(embed=EmbedsManager.error_embed( "Vous n'avez pas les permissions pour cette commande.")) # Help message if args and args[0] == '-h': return await message.channel.send( embed=EmbedsManager.information_embed( "Rappel de la commande : \n" f"`{config['prefix']}reason_remove <number>`")) # Check inputs if len(args) != 1: return await message.channel.send(embed=EmbedsManager.error_embed( ":x: Merci de mettre le numéro de la raison à retirer.")) # Process code with open('run/config/reasons.yml', 'r', encoding='utf8') as file: reasons = yaml.safe_load(file) index = int(args[0]) - 1 if index >= len(reasons): return await message.channel.send(embed=EmbedsManager.error_embed( ":x: Merci de mettre un index valide.")) current_message: discord.Message = await message.channel.send( embed=EmbedsManager.complete_embed( f"{message.author.mention} La raison **{reasons[index]}** va être retiré de la liste.\n" f"Confirmer vous ce choix ?")) await current_message.add_reaction('✅') await current_message.add_reaction('❌') def check(reaction: discord.Reaction, user: discord.User): return user == message.author and (str(reaction.emoji) == '✅' or str(reaction.emoji) == '❌') try: reaction, user = await client.wait_for('reaction_add', timeout=20.0, check=check) except asyncio.TimeoutError: return await message.channel.send(embed=EmbedsManager.error_embed( f"Vous avez __refusé__ la suppresion de la raison `{reasons[index]}` de la liste." )) else: if str(reaction.emoji) == '❌': return await message.channel.send(embed=EmbedsManager.error_embed( f"Vous avez __refusé__ la suppresion de la raison `{reasons[index]}` de la liste." )) await message.channel.send(embed=EmbedsManager.complete_embed( f"La raison **{reasons[index]}** a été __définitivement__ retiré de la liste." )) reasons.pop(index) with open('run/config/reasons.yml', 'w', encoding='utf8') as outfile: yaml.dump(reasons, outfile, default_flow_style=False, allow_unicode=True)