<commit_before>from enum import Enum
from typing import Dict, List, NamedTuple
import logging

from discord.ext import commands
import discord

from cogs import utils

class Category(Enum):
    GENERAL: int = discord.Permissions().general().value
    TEXT: int = discord.Permissions().text().value
    VOICE: int = discord.Permissions().voice().value

class Permission(NamedTuple):
    name: str
    value: bool
    category: Category

class Permissions:
    def __init__(self, bot: commands.Bot):
        self.bot: commands.Bot = bot
        self.log: logging.Logger = logging.getLogger("bot.cogs.Permissions")
        self.log.info("cogs.Permissions loaded successfully.")
        self.config: Dict = utils.load_config("Permissions")

    @commands.command()
    @commands.guild_only()
    async def perms(self,
                    ctx,
                    user: discord.User = None,
                    channel: discord.TextChannel = None):
        msg: discord.Message = ctx.message

        if user is None:
            user = msg.author

        if channel is None:
            channel = msg.channel

        # Deletes the command message.
        await msg.delete()

        perms: List[Permission] = self.get_list(msg.channel.permissions_for(msg.author))

        if self.config["justify"]:
            width: int = self.get_max_width(perms, self.config["padding"])
        else:
            width: int = 0

        embed: discord.Embed = discord.Embed()
        embed.colour = discord.Colour(utils.get_random_colour())
        embed.title = "Member Permissions"
        embed.description = f"Permissions for {user.mention} in {channel.mention}."

        embed.add_field(name = "General Permissions",
                        value = self.get_string(perms, Category.GENERAL, width),
                        inline = False)

        embed.add_field(name = "Text Permissions",
                        value = self.get_string(perms, Category.TEXT, width),
                        inline = False)

        embed.add_field(name = "Voice Permissions",
                        value = self.get_string(perms, Category.VOICE, width),
                        inline = False)

        await msg.channel.send(embed = embed)
        self.log.info(f"{msg.author} retrieved {user}'s permissions for "
                      f"#{channel.name} in {msg.guild.name} "
                      f"#{msg.channel.name}.")

    @staticmethod
    def get_list(perms: discord.Permissions) -> List[Permission]:
        lst: List[Permission] = []

        # Iterates through every permission. perm is the name of the
        # permission's respective attribute in discord.Permissions.
        for perm, value in perms:
            # Creates a Permissions object with no bits set for the purpose of
            # comparison.
            p: discord.Permissions = discord.Permissions().none()

            # Updates the bit that corresponds to the current permission in the
            # loop iteration.
            p.update(**{perm: True})

            # Iterates through every permission category.
            cat: int<commit_msg>Fixed incorrect type hint.<commit_after>from enum import Enum
from typing import Dict, List, NamedTuple
import logging

from discord.ext import commands
import discord

from cogs import utils

class Category(Enum):
    GENERAL: int = discord.Permissions().general().value
    TEXT: int = discord.Permissions().text().value
    VOICE: int = discord.Permissions().voice().value

class Permission(NamedTuple):
    name: str
    value: bool
    category: Category

class Permissions:
    def __init__(self, bot: commands.Bot):
        self.bot: commands.Bot = bot
        self.log: logging.Logger = logging.getLogger("bot.cogs.Permissions")
        self.log.info("cogs.Permissions loaded successfully.")
        self.config: Dict = utils.load_config("Permissions")

    @commands.command()
    @commands.guild_only()
    async def perms(self,
                    ctx,
                    user: discord.User = None,
                    channel: discord.TextChannel = None):
        msg: discord.Message = ctx.message

        if user is None:
            user = msg.author

        if channel is None:
            channel = msg.channel

        # Deletes the command message.
        await msg.delete()

        perms: List[Permission] = self.get_list(msg.channel.permissions_for(msg.author))

        if self.config["justify"]:
            width: int = self.get_max_width(perms, self.config["padding"])
        else:
            width: int = 0

        embed: discord.Embed = discord.Embed()
        embed.colour = discord.Colour(utils.get_random_colour())
        embed.title = "Member Permissions"
        embed.description = f"Permissions for {user.mention} in {channel.mention}."

        embed.add_field(name = "General Permissions",
                        value = self.get_string(perms, Category.GENERAL, width),
                        inline = False)

        embed.add_field(name = "Text Permissions",
                        value = self.get_string(perms, Category.TEXT, width),
                        inline = False)

        embed.add_field(name = "Voice Permissions",
                        value = self.get_string(perms, Category.VOICE, width),
                        inline = False)

        await msg.channel.send(embed = embed)
        self.log.info(f"{msg.author} retrieved {user}'s permissions for "
                      f"#{channel.name} in {msg.guild.name} "
                      f"#{msg.channel.name}.")

    @staticmethod
    def get_list(perms: discord.Permissions) -> List[Permission]:
        lst: List[Permission] = []

        # Iterates through every permission. perm is the name of the
        # permission's respective attribute in discord.Permissions.
        for perm, value in perms:
            # Creates a Permissions object with no bits set for the purpose of
            # comparison.
            p: discord.Permissions = discord.Permissions().none()

            # Updates the bit that corresponds to the current permission in the
            # loop iteration.
            p.update(**{perm: True})

            # Iterates through every permission category.
            cat: Category
{'fraction_non_alphanumeric': 0.09938985228002568, 'fraction_numerical': 0.0003211303789338471, 'mean_word_length': 2.0851906884596336, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '949648', 'n_tokens_mistral': 1692, 'n_tokens_neox': 1615, 'n_words': 448}