import aiohttp

from registrar import AbstractCommand, bot_command


@bot_command
class Command(AbstractCommand):
    """ Template for bot command classes. """
    _name = 'changepic'
    _aliases = ['changepic']
    _enabled = True
    tags = {'misc': ['private'], 'args': {'req': ['pic'], 'nreq': []}}

    @staticmethod
    async def execute(client, msg, **kwargs):
        """ Executes this command.
        :type client: bot.Bot
        :type msg: discord.Message
        """
        with aiohttp.Timeout(10):
            async with aiohttp.get(kwargs.get('pic')) as res:
                await client.edit_profile(avatar=await res.read())

    @property
    def name(self):
        """ The name of this command """
        return self._name

    @property
    def aliases(self):
        """ The aliases that can be used to call this command """
        return self._aliases

    @property
    def enabled(self):
        """ Controls whether the command is allowed to be executed. """
        return self._enabled

    @enabled.setter
    def enabled(self, value):
        """ Setter for `enabled` """
        self.enabled = value
