import discord
import operator
import base64
import asyncio
import random
import time
import datetime
import os
import codecs
import aiohttp
import urllib.request
import json
import shutil
import urllib.parse
import glob
import moviepy.editor as mpy
from discord.ext import commands
from PIL import Image,ImageFilter,ImageDraw,ImageFont
from ext.colours import ColorNames


class Noble(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        self.stopwatches = {}

    @commands.command()
    async def textgif(self,ctx,*,args):
        '''Turn TEXT to GIF'''
        img = Image.new('RGB', (500, 45),"black")
        d = ImageDraw.Draw(img)
        c = 0
        font = ImageFont.truetype('./Tabitha.ttf', 27)
        for m in range(len(args)):
            x = 9
            d.text((x+c, 5), args[m], fill=(255, 255, 255), font = font)
            img.save(f'{m}.png')
            c += 13
        file_list = glob.glob('*.png')
        list.sort(file_list)
        clip = mpy.ImageSequenceClip(file_list, fps=10)
        clip.write_gif('content.gif', fps=10)
        await ctx.send(file=discord.File('content.gif'))
        await ctx.message.delete()
        for f in glob.glob("*.png"):
            os.remove(f)

    @commands.command()
    async def pil(self, ctx,args, *,member : discord.Member=None):
        '''A SIMPLE DEMO FOR WELCOMING (DEV)'''
        user = member or ctx.message.author
        avi = user.avatar_url
        url = avi
        response = requests.get(url, stream=True)
        with open('img.png', 'wb') as out_file:
            shutil.copyfileobj(response.raw, out_file)
        del response
        img = Image.open("img.png")
        img.thumbnail((200, 200))
        new_im = Image.new("RGBA", (400,400))
        img.thumbnail((150,150))
        new_im.paste(img,(100,100))
        font = ImageFont.truetype('./arial.ttf', 19)
        xoff, yoff = (10,5)
        d = ImageDraw.Draw(new_im)
        d.text((90, 280), args, fill="green",font = font)
        new_im.save("on_test.png")
        await ctx.send(file=discord.File('on_test.png'))
        await ctx.message.delete()

    @commands.command()
    async def pictext(self,ctx,*,args):
        '''Turn Text to PIC'''
        font = ImageFont.truetype('./Tabitha.ttf', 21)
        xoff, yoff = (10,5)
        img = Image.new('RGB', (500, 45),'black')
        d = ImageDraw.Draw(img)
        d.text((9, 5), args, fill="white",font = font)
        img.save('content.jpeg')
        await ctx.message.delete()
        await ctx.send(file=discord.File('content.jpeg'))

    @commands.command()
    async def encode(self,ctx,*,args):
        '''Encode ascii Text to base64'''
        decoded_stuff = base64.b64encode('{}'.format(args).encode('ascii'))
        encoded_stuff = str(decoded_stuff)
        encoded_stuff = encoded_stuff[2:len(encoded_stuff)-1]
        await ctx.message.delete()
        await ctx.send(content = "{}".format(encoded_stuff))

    @commands.command()
    async def decode(self,ctx,*,args : str):
        '''Decode to ascii'''
        strOne = (args).encode("ascii")
        pad = len(strOne)%4
        strOne += b"="*pad
        encoded_stuff = codecs.decode(strOne.strip(),'base64')
        decoded_stuff = str(encoded_stuff)
        decoded_stuff = decoded_stuff[2:len(decoded_stuff)-1]
        await ctx.message.delete()
        await ctx.send(content = "{}".format(decoded_stuff))

    @commands.command()
    async def stopwatch(self, ctx):
        """Starts/stops stopwatch"""
        author = ctx.author
        if not author.id in self.stopwatches:
            self.stopwatches[author.id] = int(time.perf_counter())
            await ctx.send(author.mention + " Stopwatch started!")
        else:
            tmp = abs(self.stopwatches[author.id] - int(time.perf_counter()))
            tmp = str(datetime.timedelta(seconds=tmp))
            await ctx.send(author.mention + " Stopwatch stopped! Time: **" + tmp + "**")
            self.stopwatches.pop(author.id, None)

    @commands.command()
    async def disabled(self,ctx,*, member: discord.Member = None):
        'Make A disabled MEME Image (one pic only) XD'
        server = ctx.guild
        user = member or ctx.message.author
        avi = user.avatar_url
        url = '{}'.format(avi)
        response = requests.get(url, stream=True)
        with open('img2.png', 'wb') as out_file:
            shutil.copyfileobj(response.raw, out_file)
        del response
        img = Image.open("img2.png")
        new_im = Image.open("disability.jpg")
        img.thumbnail((98,98))
        new_im.paste(img,(318,216))
        new_im.save("disabled.jpg")
        await ctx.message.delete()
        await ctx.send(file=discord.File('disabled.jpg'))

        
def setup(bot):
    bot.add_cog(Noble(bot))

import discord
import operator
import base64
import asyncio
import random
import time
import datetime
import os
import codecs
import aiohttp
import urllib.request
import json
import shutil
import urllib.parse
import glob
import moviepy.editor as mpy
from discord.ext import commands
from PIL import Image,ImageFilter,ImageDraw,ImageFont
from ext.colours import ColorNames


class Noble(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        self.stopwatches = {}

    @commands.command()
    async def textgif(self,ctx,*,args):
        '''Turn TEXT to GIF'''
        img = Image.new('RGB', (500, 45),"black")
        d = ImageDraw.Draw(img)
        c = 0
        font = ImageFont.truetype('./Tabitha.ttf', 27)
        for m in range(len(args)):
            x = 9
            d.text((x+c, 5), args[m], fill=(255, 255, 255), font = font)
            img.save(f'{m}.png')
            c += 13
        file_list = glob.glob('*.png')
        list.sort(file_list)
        clip = mpy.ImageSequenceClip(file_list, fps=10)
        clip.write_gif('content.gif', fps=10)
        await ctx.send(file=discord.File('content.gif'))
        await ctx.message.delete()
        for f in glob.glob("*.png"):
            os.remove(f)

    @commands.command()
    async def pil(self, ctx,args, *,member : discord.Member=None):
        '''A SIMPLE DEMO FOR WELCOMING (DEV)'''
        user = member or ctx.message.author
        avi = user.avatar_url
        url = avi
        response = requests.get(url, stream=True)
        with open('img.png', 'wb') as out_file:
            shutil.copyfileobj(response.raw, out_file)
        del response
        img = Image.open("img.png")
        img.thumbnail((200, 200))
        new_im = Image.new("RGBA", (400,400))
        img.thumbnail((150,150))
        new_im.paste(img,(100,100))
        font = ImageFont.truetype('./arial.ttf', 19)
        xoff, yoff = (10,5)
        d = ImageDraw.Draw(new_im)
        d.text((90, 280), args, fill="green",font = font)
        new_im.save("on_test.png")
        await ctx.send(file=discord.File('on_test.png'))
        await ctx.message.delete()

    @commands.command()
    async def pictext(self,ctx,*,args):
        '''Turn Text to PIC'''
        font = ImageFont.truetype('./Tabitha.ttf', 21)
        xoff, yoff = (10,5)
        img = Image.new('RGB', (500, 45),'black')
        d = ImageDraw.Draw(img)
        d.text((9, 5), args, fill="white",font = font)
        img.save('content.jpeg')
        await ctx.message.delete()
        await ctx.send(file=discord.File('content.jpeg'))

    @commands.command()
    async def encode(self,ctx,*,args):
        '''Encode ascii Text to base64'''
        decoded_stuff = base64.b64encode('{}'.format(args).encode('ascii'))
        encoded_stuff = str(decoded_stuff)
        encoded_stuff = encoded_stuff[2:len(encoded_stuff)-1]
        await ctx.message.delete()
        await ctx.send(content = "{}".format(encoded_stuff))

    @commands.command()
    async def decode(self,ctx,*,args : str):
        '''Decode to ascii'''
        strOne = (args).encode("ascii")
        pad = len(strOne)%4
        strOne += b"="*pad
        encoded_stuff = codecs.decode(strOne.strip(),'base64')
        decoded_stuff = str(encoded_stuff)
        decoded_stuff = decoded_stuff[2:len(decoded_stuff)-1]
        await ctx.message.delete()
        await ctx.send(content = "{}".format(decoded_stuff))

    @commands.command()
    async def stopwatch(self, ctx):
        """Starts/stops stopwatch"""
        author = ctx.author
        if not author.id in self.stopwatches:
            self.stopwatches[author.id] = int(time.perf_counter())
            await ctx.send(author.mention + " Stopwatch started!")
        else:
            tmp = abs(self.stopwatches[author.id] - int(time.perf_counter()))
            tmp = str(datetime.timedelta(seconds=tmp))
            await ctx.send(author.mention + " Stopwatch stopped! Time: **" + tmp + "**")
            self.stopwatches.pop(author.id, None)

    @commands.command()
    async def disabled(self,ctx,*, member: discord.Member = None):
        'Make A disabled MEME Image (one pic only) XD'
        server = ctx.guild
        user = member or ctx.message.author
        avi = user.avatar_url
        url = '{}'.format(avi)
        response = requests.get(url, stream=True)
        with open('img2.png', 'wb') as out_file:
            shutil.copyfileobj(response.raw, out_file)
        del response
        img = Image.open("img2.png")
        new_im = Image.open("disability.jpg")
        img.thumbnail((98,98))
        new_im.paste(img,(318,216))
        new_im.save("disabled.jpg")
        await ctx.message.delete()
        await ctx.send(file=discord.File('disabled.jpg'))

        
def setup(bot):
    bot.add_cog(Noble(bot))

Turn TEXT to GIF A SIMPLE DEMO FOR WELCOMING (DEV) Turn Text to PIC Encode ascii Text to base64 Decode to ascii Starts/stops stopwatch