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 on_guild(client: discord.Client, message: discord.Message): with open('run/config/config.yml', 'r') as file: config = yaml.safe_load(file) if message.channel.category.id != config['category_id']: return link: Channel = session.query(Channel).filter_by( channel_id=message.channel.id).first() if not link: await message.channel.send( "❌ | Aucune discussion n'est en cours dans ce salon.") return if message.content == config['prefix'] + "close": current_message: discord.Message = await message.channel.send \ (f"{message.author.mention} Vous avez décidé de fermer cette discussion.\n" f"Confirmer vous ce choix ?") await current_message.add_reaction('✅') await current_message.add_reaction('❌') def check(reaction, 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( f"Vous avez __refusé__ l'arret de la discussion.") else: if str(reaction.emoji) == '❌': await message.channel.send( f"Vous avez __refusé__ l'arret de la discussion.") return await message.channel.delete() await client.get_user( link.author_id ).send("Le staff a décidé d'arrêter cette discussion.") session.delete(link) session.commit() else: if message.content: await client.get_user(link.author_id).send(f"{message.content}") for attachment in message.attachments: await client.get_user(link.author_id).send(attachment.proxy_url) await message.add_reaction('📨')
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 on_mp(client: discord.Client, message: discord.Message): with open('run/config/config.yml', 'r') as file: config = yaml.safe_load(file) author: discord.User = message.author link: Channel = session.query(Channel).filter_by( author_id=author.id).first() if not link: # Pas encore connecté now = datetime.now() topic = f"Username : {author.name}#{author.discriminator}\n" \ f"ID : {author.id}\n" \ f"Conversation commencé le : {now.day}/{now.month}/{now.year} à {now.hour}:{now.minute}" channel = await client.get_guild( config['guild_id']).create_text_channel( author.name[:10], category=client.get_guild(config['guild_id']).get_channel( config['category_id']), topic=topic) link = Channel(author.id, channel.id) session.add(link) session.commit() await message.channel.send( "Merci pour votre message! " "Notre équipe de modérateurs vous répondra dans les plus brefs délais.\n" "Tous les messages que vous posterez ici (y compris votre précédent message), " "sera retransmis au staff.") await client.get_channel(link.channel_id).send( f"**Une discussion vient de commencer avec " f"{author.name}#{author.discriminator} | {author.id}.**") if message.content: await client.get_channel(link.channel_id).send(message.content) for attachment in message.attachments: await client.get_channel(link.channel_id).send(attachment.proxy_url) await message.add_reaction('📨')
async def list_customcommands(client: discord.Client, message: discord.Message, args: List[str]): with open('run/config/config.yml', 'r') as file: config = yaml.safe_load(file) # 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']}list_command`")) custom_commands: List[CustomCommand] = session.query(CustomCommand).all() content = "Voici les commandes personnalisées :" for custom_command in custom_commands: content += f'\n - `{custom_command.command}`' await message.channel.send(embed=EmbedsManager.complete_embed(content))
async def run(client: discord.Client, message: discord.Message): with open('run/config/config.yml', 'r') as file: config = yaml.safe_load(file) if message.author.bot: return await check_mute(client, message) if not message.content.startswith(config['prefix']): return command = message.content[1:].split(' ')[0] args = message.content[1:].split(' ')[1:] # Check for custom command custom_commands: List[CustomCommand] = session.query(CustomCommand).filter_by(command=command).all() if len(custom_commands) == 1: await message.delete() await message.channel.send(custom_commands[0].content) elif command == 'prefix': await change_prefix(client, message, args) # Reason management elif command == 'reason_list': await get_reasons_list(client, message) elif command == 'reason_add': await add_reason(client, message, args) elif command == 'reason_remove': await remove_reason(client, message, args) # Ban management if command == 'ban': await ban_member(client, message, args) elif command == 'rban': await revoke_ban(client, message, args) # Kick management elif command == 'kick': await kick_member(client, message, args) elif command == 'rkick': await revoke_kick(client, message, args) # Warn management elif command == 'warn': await warn_member(client, message, args) elif command == 'rwarn': await revoke_warn(client, message, args) # Mute management elif command == 'mute': await mute_member(client, message, args) elif command == 'rmute': await revoke_mute(client, message, args) # Mod management elif command == "mod": await get_mod(client, message, args) # Annonce management elif command == "annonce": await annonce_msg(client, message, args) # Freeze management elif command == "freeze": await freeze_server(client, message, args) elif command == "rfreeze": await unfreeze_server(client, message, args) # Custom command mangement elif command == "add_command": await add_customcommands(client, message, args) elif command == "remove_command": await remove_customcommands(client, message, args) elif command == "list_command": await list_customcommands(client, message, args) elif command == 'perm': await permissions(client, message, args)
async def get_mod(client: discord.Client, message: discord.Message, args: List[str]): with open('run/config/config.yml', 'r') as file: config = yaml.safe_load(file) # 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']}mod <@user>`")) # 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.") ) target: discord.Member = message.mentions[0] infos = { 'warns': session.query(Warn).filter_by(target_id=target.id, is_active=True).all(), 'rwarns': session.query(Warn).filter_by(target_id=target.id, is_active=False).all(), 'kicks': session.query(Kick).filter_by(target_id=target.id, is_active=True).all(), 'rkicks': session.query(Kick).filter_by(target_id=target.id, is_active=False).all(), 'bans': session.query(Ban).filter_by(target_id=target.id, is_active=True).all(), 'rbans': session.query(Ban).filter_by(target_id=target.id, is_active=False).all(), 'mutes': session.query(Mute).filter_by(target_id=target.id, is_active=True).all(), 'rmutes': session.query(Mute).filter_by(target_id=target.id, is_active=False).all() } embed = discord.Embed() embed.set_author(name=f'{target.display_name} (ID: {target.id})', icon_url=target.avatar_url) \ .add_field(name=f'Voici les informations sur {target.display_name}:', value=f'Sourdine : {len(infos["mutes"]) + len(infos["rmutes"])}' f' (dont {len(infos["rmutes"])} révoqués).\n' f'Avertissements : {len(infos["warns"]) + len(infos["rwarns"])}' f' (dont {len(infos["rwarns"])} révoqués).\n' f'Exclusions : {len(infos["kicks"]) + len(infos["rkicks"])}' f' (dont {len(infos["rkicks"])} révoqués).\n' f'Bannissements : {len(infos["bans"]) + len(infos["rbans"])}' f' (dont {len(infos["rbans"])} révoqués).\n') \ .set_footer(text=f"{client.user.display_name}", icon_url=client.user.avatar_url) embed.timestamp = datetime.now() - timedelta(hours=2) await message.channel.send(embed=embed) for type in ['warns', 'kicks', 'bans']: embed = discord.Embed() \ .set_author(name=f'{type} de {target.display_name} (ID: {target.id})', icon_url=target.avatar_url) if infos[type]: for things in infos[type]: embed.add_field( name= f"{type} par {message.guild.get_member(things.author_id)}" f" (ID: {type[0]}{things.id})", value= f"Le {things.date.day}/{things.date.month}/{things.date.year}" f" à {things.date.hour}:{things.date.minute}" f" pour : \n {things.reason}") await message.channel.send(embed=embed)