Exemplo n.º 1
0
    async def rename(self, context, *args):
        r"""Renames an emote. You must own it.

		Example:
		ec/rename a b
		Renames \:a: to \:b:
		"""

        if not args:
            return await context.send(
                _('You must specify an old name and a new name.'))

        # allow e.g. foo{bar,baz} -> rename foobar to foobaz
        if len(args) == 1:
            old_name, new_name = utils.expand_cartesian_product(args[0])
            if not new_name:
                return await context.send(
                    _('Error: you must provide a new name for the emote.'))
        else:
            old_name, new_name, *rest = args

        old_name, new_name = map(lambda c: c.strip(':;'), (old_name, new_name))

        try:
            await self.db.rename_emote(old_name, new_name, context.author.id)
        except discord.HTTPException as ex:
            await context.send(utils.format_http_exception(ex))
        else:
            await context.send(_('Emote successfully renamed.'))
Exemplo n.º 2
0
 async def add_safe(self, name, url, author_id):
     """Try to add an emote. Returns a string that should be sent to the user."""
     if not re.fullmatch(r'\w{2,32}', name, re.ASCII):
         return _(
             '{name} is not a valid emote name; use 2–32 English letters, numbers and underscores.'
         ).format(name=discord.utils.escape_mentions(name))
     try:
         emote = await self.add_from_url(name, url, author_id)
     except discord.HTTPException as ex:
         return (_('An error occurred while creating the emote:\n') +
                 utils.format_http_exception(ex))
     except ValueError:
         return _('Error: Invalid URL.')
     except aiohttp.ServerDisconnectedError:
         return _(
             'Error: The connection was closed early by the remote host.')
     except aiohttp.ClientResponseError as exc:
         raise errors.HTTPException(exc.status)
     else:
         return _('Emote {emote} successfully created.').format(emote=emote)