From 8c7c808a6728dd6992151f7e8a8e4d315fccff40 Mon Sep 17 00:00:00 2001 From: Andrey <50486086+DarkCat09@users.noreply.github.com> Date: Tue, 20 Jul 2021 18:34:40 +0400 Subject: [PATCH] Add files via upload --- Procfile | 1 + pictoolsbot.py | 104 +++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 29 +++++++++++++ runtime.txt | 1 + 4 files changed, 135 insertions(+) create mode 100644 Procfile create mode 100644 pictoolsbot.py create mode 100644 requirements.txt create mode 100644 runtime.txt diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..b400771 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +worker: python pictoolsbot.py diff --git a/pictoolsbot.py b/pictoolsbot.py new file mode 100644 index 0000000..442bd6e --- /dev/null +++ b/pictoolsbot.py @@ -0,0 +1,104 @@ +import os +import discord +from discord.ext import commands +from PIL import Image +from PIL import ImageFilter + +# Add the bot: +# https://discord.com/api/oauth2/authorize?client_id=867021940174094397&permissions=2147585024&scope=bot + +# Setting Up +token = '*** YOUR TOKEN ***' +bot = commands.Bot(command_prefix='/') + +@bot.command() +async def picresize(ctx, *args): + if ctx.message.attachments and len(args) > 0: + attachedimg = ctx.message.attachments[0] + await attachedimg.save(attachedimg.filename) + + img = Image.open(attachedimg.filename) + w, h = img.size + if (len(args) == 2) and (args[0] == 'w'): + neww = int(args[1]) + newh = neww * h // w + elif (len(args) == 2) and (args[0] == 'h'): + newh = int(args[1]) + neww = newh * w // h + elif (len(args) == 2): + neww = int(args[0]) + newh = int(args[1]) + + img = img.resize((neww, newh), Image.ANTIALIAS) + img.save(attachedimg.filename) + await ctx.send(file=discord.File(attachedimg.filename)) + os.remove(attachedimg.filename) + +@bot.command() +async def pic8bit(ctx): + if ctx.message.attachments: + attachedimg = ctx.message.attachments[0] + await attachedimg.save(attachedimg.filename) + + img = Image.open(attachedimg.filename) + w, h = img.size + img = img.resize((w // 8, h // 8), Image.NEAREST) + img = img.resize((w * 8, h * 8), Image.NEAREST) + + img.save(attachedimg.filename) + await ctx.send(file=discord.File(attachedimg.filename)) + os.remove(attachedimg.filename) + +@bot.command() +async def piccrop(ctx, *args): + if ctx.message.attachments and len(args) > 3: + attachedimg = ctx.message.attachments[0] + await attachedimg.save(attachedimg.filename) + + img = Image.open(attachedimg.filename) + img = img.crop((int(args[0]),int(args[1]),int(args[2]),int(args[3]))) + img.save(attachedimg.filename) + await ctx.send(file=discord.File(attachedimg.filename)) + os.remove(attachedimg.filename) + +@bot.command() +async def picrotate(ctx, *args): + if ctx.message.attachments and len(args) > 0: + attachedimg = ctx.message.attachments[0] + await attachedimg.save(attachedimg.filename) + + img = Image.open(attachedimg.filename) + img = img.rotate(int(args[0])) + img.save(attachedimg.filename) + await ctx.send(file=discord.File(attachedimg.filename)) + os.remove(attachedimg.filename) + +@bot.command() +async def picblur(ctx, *args): + if ctx.message.attachments: + attachedimg = ctx.message.attachments[0] + await attachedimg.save(attachedimg.filename) + + img = Image.open(attachedimg.filename) + radius = int(args[0]) if len(args) > 0 else 40 + img = img.filter(ImageFilter.GaussianBlur(radius)) + img.save(attachedimg.filename) + await ctx.send(file=discord.File(attachedimg.filename)) + os.remove(attachedimg.filename) + +@bot.command() +async def picconv(ctx, *args): + if ctx.message.attachments and len(args) > 0: + attachedimg = ctx.message.attachments[0] + await attachedimg.save(attachedimg.filename) + + img = Image.open(attachedimg.filename) + ext = str(args[0]) + newname = attachedimg.filename[:attachedimg.filename.rfind('.')] + '.' + ext + img.save(newname, ext) + await ctx.send(file=discord.File(newname)) + os.remove(attachedimg.filename) + os.remove(newname) + +# Starting +bot.run(token) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..5cb3673 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,29 @@ +aiohttp==3.7.4.post0 +anyio==3.2.1 +async-timeout==3.0.1 +attrs==21.2.0 +beautifulsoup4==4.9.3 +certifi==2020.12.5 +cffi==1.14.5 +chardet==4.0.0 +click==7.1.2 +discord.py==1.7.3 +h11==0.12.0 +httpcore==0.13.6 +httpx==0.18.2 +idna==2.10 +multidict==5.1.0 +numpy==1.20.2 +Pillow==8.2.0 +pycparser==2.20 +pygal==2.4.0 +pygame==2.0.1 +PyNaCl==1.4.0 +PySocks==1.7.1 +rfc3986==1.5.0 +six==1.15.0 +sniffio==1.2.0 +soupsieve==2.2.1 +typing-extensions==3.10.0.0 +urllib3==1.26.3 +yarl==1.6.3 diff --git a/runtime.txt b/runtime.txt new file mode 100644 index 0000000..9096f8c --- /dev/null +++ b/runtime.txt @@ -0,0 +1 @@ +python-3.9.6