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}**."))
示例#2
0
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()
示例#3
0
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('📨')
示例#4
0
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é."))
示例#5
0
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é."))
示例#6
0
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()
示例#7
0
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('📨')
示例#8
0
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}"
    ))