Example #1
0
from typing import List

import discord

from src.utils.api_manager import APIManager
from src.utils.embeds_manager import EmbedsManager
from src.utils.permissions_manager import PermissionsManager
from src.utils.log_manager import LogManager

api_manager = APIManager()
permissions_manager = PermissionsManager()


async def add_ban(client: discord.Client, message: discord.Message,
                  args: List[str]):
    state, results = permissions_manager.get_permissions(
        message.author, message.guild)

    if not state:
        return await message.channel.send(
            embed=EmbedsManager.error_embed(results))

    # Check lvl permissions
    if results == 0 or results == 1:
        return await message.channel.send(embed=EmbedsManager.error_embed(
            "You don't have the necessary permissions."))

    # Display help
    if args and args[0] == '-h':
        return await message.channel.send(embed=EmbedsManager.information_embed(
            "**Banning command reminder:**\n\n"
Example #2
0
async def get_top(client: discord.Client, message: discord.Message,
                  args: List[str], config):
    api_manager = APIManager(config['api']['url'], config['api']['token'])

    if not PermissionChecker.is_moderator(message.author):
        return await message.channel.send(embed=EmbedsManager.error_embed(
            "Vous n'avez pas les permissions nécessaires."))

    # Display help
    if args and args[0] == '-h':
        return await message.channel.send(embed=EmbedsManager.information_embed(
            "**Rappel de la commande de récupération des meilleurs messages :**\n\n"
            "`!top`."))

    # Get channel and messages
    channel: discord.TextChannel = message.guild.get_channel(
        config['channels']['top'])

    john_message: discord.Message = await channel.fetch_message(
        id=683660205250183198)

    messages: List[discord.Message] = await channel.history(
        limit=None, after=john_message.edited_at).flatten()

    # Get cleaned data
    emoji = '👍'
    records = []
    for msg in messages:
        if not msg.author.bot:
            for reaction in msg.reactions:
                if reaction.emoji == emoji:
                    records.append({
                        'author': msg.author,
                        'content': msg.content,
                        'date': msg.created_at,
                        'link': msg.jump_url,
                        'count': reaction.count
                    })

    # Sort data
    records = sorted(records, key=lambda x: x['count'], reverse=True)

    # Get just the 10 best records
    records = records[:10]

    for index, record in enumerate(records):
        content = record['content']
        if len(content) > 1024:
            content = record['content'][:1020] + '...'

        embed = discord.Embed(color=0xff0000) \
            .set_author(
            name=f"Message {index + 1}."
        ) \
            .add_field(
            name="Contenu du message",
            value=content,
            inline=False
        ) \
            .add_field(
            name="Nombre de vote (👍) :",
            value=record['count'],
            inline=True
        ) \
            .add_field(
            name="Lien du message",
            value=record['link'],
            inline=True
        ) \
            .set_thumbnail(url=record['author'].avatar_url)

        embed.description = f"Proposition de {record['author'].name}#{record['author'].discriminator} " \
                            f"({record['author'].id})"

        await message.channel.send(embed=embed)
Example #3
0
import yaml

from src.utils.api_manager import APIManager

with open("run/config/config.yml", 'r') as stream:
    data = yaml.safe_load(stream)
    api_manager = APIManager(data['api']['url'], data['api']['token'])


class Role:
    id: int
    slug: str
    role_id: int

    def __init__(self, **kwargs):
        """
        Init of the class
        :param kwargs: a warn from the api
        """
        if 'data' in kwargs:
            self.id = int(kwargs['data']['id'])
            self.slug = kwargs['data']['slug']
            self.role_id = int(kwargs['data']['role_id'])
        else:
            self.id = -1
            self.slug = "command"
            self.role_id = -1

    def save(self):
        state, r = api_manager.post_data('roles',
                                         slug=self.slug,
Example #4
0
async def view_bantemps(client: discord.Client, message: discord.Message,
                        args: List[str], config):
    api_manager = APIManager(config['api']['url'], config['api']['token'])

    if not PermissionChecker.is_moderator(message.author) and len(
            message.mentions):
        return await message.channel.send(embed=EmbedsManager.error_embed(
            "Vous n'avez pas les permissions nécessaires."))

    channel = 289476916044627978
    if not PermissionChecker.is_moderator(
            message.author) and message.channel.id != channel:
        return await message.channel.send(embed=EmbedsManager.error_embed(
            "Hum, vous n'êtes pas dans le bon salon.\n\n"
            f"Merci de réessayer dans {message.guild.get_channel(channel).mention}."
        ))

    # Display help
    if args and args[0] == '-h':
        return await message.channel.send(embed=EmbedsManager.information_embed(
            "**Rappel de la commande de visualisation des bannissements temporaires :**\n\n"
            "`!ib <?@user>`."))

    # Check if target exist
    target: discord.Member = message.mentions[0] if len(
        message.mentions) == 1 else message.author

    state, res = api_manager.get_data('temp-bans', user_id=target.id)

    if not state:
        return

    if not res:
        return await message.channel.send(embed=EmbedsManager.sanction_embed(
            f"Le membre {target.name}#{target.discriminator} n'a aucun bannissement temporaire :",
        ).set_thumbnail(url=target.avatar_url).set_footer(
            icon_url=client.user.avatar_url, text='Made By Gastbob40'))

    if len(res) > 20:
        return await message.channel.send(
            EmbedsManager.error_embed(
                f"Hum, on dirait que {target.name}#{target.discriminator} a trop de bannissement temporaire :(\n"
                f"Je vous conseille d'aller sur le site web afin de pouvoir voir la liste detaillée."
            ))

    tempbans = [TempBan(data=x) for x in res]
    embed = EmbedsManager.sanction_embed(
        f"Voici les informations concernants {target.name}#{target.discriminator} :"
    ) \
        .set_thumbnail(url=target.avatar_url) \
        .set_footer(icon_url=client.user.avatar_url, text='Made By Gastbob40')

    for tempban in tempbans:
        moderator = message.guild.get_member(tempban.moderator_id) if \
            message.guild.get_member(tempban.moderator_id) else \
            'Un ancien modérateur'

        embed.add_field(
            name=
            f"Bannissement temporaire de {moderator}, du {tempban.start_time.strftime('%d/%m/%Y à %H:%M')} au "
            f"{tempban.end_time.strftime('%d/%m/%Y à %H:%M')}.",
            value=f"Bannissement temporaire pour `{tempban.reason}`",
            inline=False)

    await message.channel.send(embed=embed)
Example #5
0
async def reinit_restriction(client: discord.Client, message: discord.Message,
                             args: List[str], config):
    api_manager = APIManager(config['api']['url'], config['api']['token'])

    if not PermissionChecker.is_moderator(message.author):
        return await message.channel.send(embed=EmbedsManager.error_embed(
            "Vous n'avez pas les permissions nécessaires."))

    # Display help
    if args and args[0] == '-h':
        return await message.channel.send(embed=EmbedsManager.information_embed(
            "**Rappel de la commande de rénitialistion de restriction :**\n\n"
            "`!bt <@user> <durée> <reason>`.\n\n"
            "Attention, vous devez être dans le salon restreint."))

    if not message.channel.id in config['restricted_channels']:
        return await message.channel.send(embed=EmbedsManager.error_embed(
            "Erreur dans la commande. Vous n'êtes pas dans un salon restreint."
        ))

    # Check if target exist
    target: discord.Member = message.mentions[0] if len(
        message.mentions) == 1 else False

    if not target:
        return await message.channel.send(embed=EmbedsManager.error_embed(
            "Erreur dans la commande. Vous devez mentionner un utilisateur."))

    state, res = api_manager.get_data('post-restrictions',
                                      user_id=str(target.id),
                                      channel_id=str(message.channel.id))

    if not state:
        return await message.channel.send(embed=EmbedsManager.error_embed(
            "Erreur dans l'api. Merci de contacter gast."))

    restriction = None if not res else PostRestriction(data=res[0])

    if not restriction:
        return await message.channel.send(embed=EmbedsManager.error_embed(
            f"Erreur dans la commande. {target.name}#{target.discriminator} n'a pas de restriction"
            f" active dans {message.channel.mention}"))

    else:
        restriction.delete()

        await client.get_channel(
            config['channels']['log_reactions']
        ).send(embed=EmbedsManager.sanction_embed(
            f"{message.author.name}#{message.author.discriminator} vient de retirer une restriction de "
            f"{target.name}#{target.discriminator}.", ).add_field(
                name='Salon', value=message.channel.mention, inline=True
            ).add_field(
                name='Membre', value=target.mention, inline=True).set_footer(
                    icon_url=client.user.avatar_url, text='Made By Gastbob40'))

        await message.channel.send(embed=EmbedsManager.sanction_embed(
            f"Vous venez de retirer une restriction de "
            f"{target.name}#{target.discriminator}.", ).add_field(
                name='Salon', value=message.channel.mention, inline=True
            ).add_field(
                name='Membre', value=target.mention, inline=True).set_footer(
                    icon_url=client.user.avatar_url, text='Made By Gastbob40'))

        await target.send(embed=EmbedsManager.sanction_embed(
            f"{message.author.name}#{message.author.discriminator} vient de vous retirer une restriction.",
        ).add_field(
            name='Salon', value=message.channel.mention,
            inline=True).add_field(
                name='Membre', value=target.mention, inline=True).set_footer(
                    icon_url=client.user.avatar_url, text='Made By Gastbob40'))
Example #6
0
 def __init__(self, client: discord.Client):
     self.client = client
     self.get_config()
     self.api_manager = APIManager()