From 10ad2a559a4192d73b6878e3910e06ad8fa5122d Mon Sep 17 00:00:00 2001 From: Kowlin Date: Mon, 13 Apr 2020 02:27:55 +0200 Subject: [PATCH] [Core] Support setting avatar via attachment (#3747) * [Core] Support avatars via attachments * Fix the thing I was actually annoyed about. * Updated error texts * English is a damn annoying language. --- redbot/core/core_commands.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py index 8e8661ebe..b8d55edde 100644 --- a/redbot/core/core_commands.py +++ b/redbot/core/core_commands.py @@ -1095,11 +1095,21 @@ class Core(commands.Cog, CoreLogic): @_set.command() @checks.is_owner() - async def avatar(self, ctx: commands.Context, url: str): - """Sets [botname]'s avatar""" - async with aiohttp.ClientSession() as session: - async with session.get(url) as r: - data = await r.read() + async def avatar(self, ctx: commands.Context, url: str = None): + """Sets [botname]'s avatar + + Supports either an attachment or an image URL.""" + if len(ctx.message.attachments) > 0: # Attachments take priority + data = await ctx.message.attachments[0].read() + elif url is not None: + if url.startswith("<") and url.endswith(">"): + url = url[1:-1] + + async with aiohttp.ClientSession() as session: + async with session.get(url) as r: + data = await r.read() + else: + return await ctx.send(_("Please upload an attachment or provide an URL link.")) try: await ctx.bot.user.edit(avatar=data) @@ -1107,8 +1117,8 @@ class Core(commands.Cog, CoreLogic): await ctx.send( _( "Failed. Remember that you can edit my avatar " - "up to two times a hour. The URL must be a " - "direct link to a JPG / PNG." + "up to two times a hour. The URL or attachment " + "must be a valid image in either JPG or PNG format." ) ) except discord.InvalidArgument: