Making it so that you can get the people's avatar greyscaled

pull/9/head
sgoudham 4 years ago
parent 7c4db815d7
commit f99e26377e

@ -15,16 +15,18 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
import datetime import datetime
import io
import string import string
from asyncio.subprocess import Process from asyncio.subprocess import Process
from platform import python_version from platform import python_version
from time import time from time import time
from typing import Optional, Union from typing import Optional, Union
from discord import Embed, Role from PIL import Image
from discord import Embed, Role, File
from discord import Member, TextChannel from discord import Member, TextChannel
from discord import __version__ as discord_version from discord import __version__ as discord_version
from discord.ext.commands import BucketType, cooldown, bot_has_permissions, guild_only, Cog from discord.ext.commands import bot_has_permissions, guild_only, Cog, group
from discord.ext.commands import command from discord.ext.commands import command
from psutil import Process, virtual_memory from psutil import Process, virtual_memory
@ -436,8 +438,7 @@ class Info(Cog):
await ctx.send(embed=stats) await ctx.send(embed=stats)
@command(name="avatar") @group(name="avatar", invoke_without_command=True, case_insensitive=True, usage="`[member]|<greyscale> [member]`")
@cooldown(1, 1, BucketType.user)
@bot_has_permissions(embed_links=True) @bot_has_permissions(embed_links=True)
async def get_user_avatar(self, ctx, *, member: Optional[Member] = None): async def get_user_avatar(self, ctx, *, member: Optional[Member] = None):
""" """
@ -460,6 +461,32 @@ class Info(Cog):
await ctx.send(embed=embed) await ctx.send(embed=embed)
@get_user_avatar.command(name="greyscale", aliases=["gs"])
@bot_has_permissions(embed_links=True)
async def greyscale_user_avatar(self, ctx, *, member: Optional[Member] = None):
"""Get the greyscale avatar of the member"""
# Get member mentioned or set to author
member = ctx.author if not member else member
attach = await member.avatar_url.read()
image = Image.open(io.BytesIO(attach)).convert('LA')
# Save new grayscale image as bytes
file = io.BytesIO()
image.save(file, format='PNG')
file.seek(0)
# Send image in an embed
f = File(file, "image.png")
embed = Embed(title=f"{member}'s Avatar | Greyscale",
colour=self.bot.admin_colour,
timestamp=datetime.datetime.utcnow())
embed.set_image(url="attachment://image.png")
embed.set_footer(text=f"Requested by {ctx.author}", icon_url=ctx.author.avatar_url)
await ctx.send(file=f, embed=embed)
def setup(bot): def setup(bot):
bot.add_cog(Info(bot)) bot.add_cog(Info(bot))

Loading…
Cancel
Save