Added supported for inverted images and inverted avatars

pull/9/head
sgoudham 4 years ago
parent f99e26377e
commit c47c037504

@ -25,6 +25,7 @@ from typing import Optional
import aiohttp
import discord
from PIL import Image, ImageDraw, ImageFont
from PIL.ImageOps import invert
from aiohttp import request
from discord import Member, Embed
from discord.ext import commands
@ -493,6 +494,30 @@ class Fun(Cog):
else:
await self.bot.generate_embed(ctx, desc="**Image Not Detected!**")
@command(name="invert", aliases=["negative"])
@cooldown(1, 5, BucketType.user)
@bot_has_permissions(attach_files=True)
async def invert(self, ctx):
"""Display inverted version of image uploaded"""
if ctx.message.attachments:
for attachments in ctx.message.attachments:
attach = await attachments.read()
image = Image.open(io.BytesIO(attach)).convert('RGB')
inverted = invert(image)
# Save new grayscale image as bytes
file = io.BytesIO()
inverted.save(file, format='PNG')
file.seek(0)
await ctx.message.delete()
# Send Grayscale Image
await ctx.send(file=discord.File(file, "inverted.png"))
else:
await self.bot.generate_embed(ctx, desc="**Image Not Detected!**")
@command(name="owo", aliases=["uwu"])
@cooldown(1, 1, BucketType.user)
@bot_has_permissions(manage_messages=True)

@ -23,6 +23,7 @@ from time import time
from typing import Optional, Union
from PIL import Image
from PIL.ImageOps import invert
from discord import Embed, Role, File
from discord import Member, TextChannel
from discord import __version__ as discord_version
@ -438,7 +439,8 @@ class Info(Cog):
await ctx.send(embed=stats)
@group(name="avatar", invoke_without_command=True, case_insensitive=True, usage="`[member]|<greyscale> [member]`")
@group(name="avatar", invoke_without_command=True, case_insensitive=True,
usage="`[member]|greyscale|invert`")
@bot_has_permissions(embed_links=True)
async def get_user_avatar(self, ctx, *, member: Optional[Member] = None):
"""
@ -487,6 +489,33 @@ class Info(Cog):
await ctx.send(file=f, embed=embed)
@get_user_avatar.command(name="invert", aliases=["negative"])
@bot_has_permissions(embed_links=True)
async def greyscale_user_avatar(self, ctx, *, member: Optional[Member] = None):
"""Get the inverted 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('RGB')
inverted = invert(image)
# Save new inverted image as bytes
file = io.BytesIO()
inverted.save(file, format='PNG')
file.seek(0)
# Send image in an embed
f = File(file, "image.png")
embed = Embed(title=f"{member}'s Avatar | Inverted",
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):
bot.add_cog(Info(bot))

Loading…
Cancel
Save