This repository has been archived by the owner on May 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
64 lines (50 loc) · 1.76 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import random
import io
from PIL import Image
import requests
import sys
import patterns
import discord
from discord.ext import commands
from utils import permissions, default, http, dataIO
# Cog Beta-Release
class ImageDis(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.config = default.get("config.json")
def _downloadExternalImg(self, url: str) -> Image.Image:
response: requests.Response = requests.get(url)
im = Image.open(io.BytesIO(response.content))
return im
def _serve_pil_image(self, pil_img):
img_io = io.BytesIO()
pil_img.save(img_io, 'PNG')
img_io.seek(0)
# return img_io
@commands.command()
@commands.check(permissions.is_owner)
# @commands.guild_only()
async def discordMsgApi(self, ctx):
conditionals = 'picture user message'.split(" ")
hasAllConditionals = all(
list(map(lambda x: x in request.json, conditionals)))
if not request.json or not hasAllConditionals:
abort(400)
imageFile = _downloadExternalImg(request.json['picture'])
task = {
'picture': imageFile,
'message': request.json.get('message', 'lorem ipsum dolor'),
'user': request.json['user'],
'color': request.json.get('color', "#8e9b9b")
}
patternAppliedImg = patterns.discordMsg(**task)
# return _serve_pil_image(patternAppliedImg)
# TODO Get a way to server pil images in discord chat
await ctx.send("error 404")
@commands.command()
@commands.check(permissions.is_owner)
@commands.guild_only()
async def getrandomuser(self, ctx):
await ctx.send("getting all users -->")
def setup(bot):
bot.add_cog(ImageDis(bot))