-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbot.py
More file actions
44 lines (33 loc) · 1.25 KB
/
bot.py
File metadata and controls
44 lines (33 loc) · 1.25 KB
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
# configuration
from settings import settings
# discord
import discord
from requests import post
# regex
import re
# base64
import io
from base64 import b64decode
client = discord.Client()
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('!hello'):
await message.channel.send('Hello!')
if message.content.startswith('!generate:'):
await message.channel.send("Making the request - it may take a while")
req = post(url = settings.URL, json = {'prompt': message.content.split("!generate:")[1].strip()})
await message.channel.send("Result is completed")
images = re.search('\[(.*)\]', req.content.decode("utf-8") ).group(0)
encodings = [e.replace("\\n", "") for e in re.findall('"([^"]*)"', images)]
myfiles = []
for i, encoded in enumerate(encodings):
with open("img/image{}.png".format(i), "wb") as fh:
fh.write(b64decode(encoded))
myfiles.append(discord.File("img/image{}.png".format(i)))
await message.channel.send(files = myfiles)
client.run(settings.TOKEN)