Add files via upload
This commit is contained in:
parent
eca767d25f
commit
8c7c808a67
4 changed files with 135 additions and 0 deletions
1
Procfile
Normal file
1
Procfile
Normal file
|
@ -0,0 +1 @@
|
||||||
|
worker: python pictoolsbot.py
|
104
pictoolsbot.py
Normal file
104
pictoolsbot.py
Normal file
|
@ -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)
|
29
requirements.txt
Normal file
29
requirements.txt
Normal file
|
@ -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
|
1
runtime.txt
Normal file
1
runtime.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
python-3.9.6
|
Loading…
Add table
Reference in a new issue