-
Notifications
You must be signed in to change notification settings - Fork 0
/
pb2.py
103 lines (84 loc) · 3.4 KB
/
pb2.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import time
import discord
from discord.ext import commands
from dotenv import load_dotenv
import pyautogui as pg
import cv2
import pygetwindow as gw
import os
from PIL import Image
import requests
from io import BytesIO
import threading
import queue
# Set up camera
load_dotenv()
discord_token = os.getenv("DISCORD_TOKEN")
client = commands.Bot(command_prefix="*", intents=discord.Intents.all())
# Open the first camera connected to the computer.
cap = cv2.VideoCapture(0)
background_image_url = "https://cdn.discordapp.com/attachments/1131904046488354897/1131906142021357568/chihiro007.jpg"
# Create a queue to communicate between threads
frame_queue = queue.Queue()
def run_bot():
while True:
frame = frame_queue.get()
if frame is None:
break
cv2.imwrite("frame.jpg", frame)
client.loop.create_task(send_frame())
async def send_frame():
for guild in client.guilds:
for channel in guild.text_channels:
await channel.send(file=discord.File('frame.jpg'))
@client.event
async def on_ready():
print("Bot connected")
@client.event
async def on_message(message):
msg = message.content
print(message)
# Listen for the bot's own messages
if message.author == client.user:
for attachment in message.attachments:
image_url = attachment.url
# Loop through all windows
pg.write(f'/imagine {image_url} {background_image_url} anime, hand-drawn and cel animation techniques, guests at party, natural design, beautifully rendered and expressive rich colors, vibrant pastel colors,imaginative and fantastical landscapes, sharp attention to detail,realism and a strong sense of nostalgia and warmth, sharp attention to small details and textures,fantastical creatures, settings, depth and emotions emphasized and accentuated by lighting and shading,extremely high quality, incredibly high finite definition, high resolution, hand-drawn and cel animation techniques, anime --ar 3:2 --stylize 1000 --q 2 --niji 5', interval=0)
time.sleep(3)
pg.press('enter')
time.sleep(5)
# Still need to test this,
# but also need to have none blocking thread
# to listen to button press instead of constantly capturing
# Listen for messages from Midjourney Bot
if message.author.id == 9282:
for attachment in message.attachments:
response = requests.get(attachment.url)
img = Image.open(BytesIO(response.content))
width, height = img.size
img1 = img.crop((0, 0, width // 2, height // 2))
img2 = img.crop((width // 2, 0, width, height // 2))
img3 = img.crop((0, height // 2, width // 2, height))
img4 = img.crop((width // 2, height // 2, width, height))
img1.save('img1.jpg')
img2.save('img2.jpg')
img3.save('img3.jpg')
img4.save('img4.jpg')
# Create threads
bot_thread = threading.Thread(target=run_bot)
# Start threads
bot_thread.start()
while True:
# Capture frame-by-frame
ret, frame = cap.read()
# Display the resulting frame
cv2.imshow('Frame', frame)
# Capture a frame on 'c' key press
if cv2.waitKey(1) & 0xFF == ord('c'):
frame_queue.put(frame)
# Break the loop on 'q' key press
if cv2.waitKey(1) & 0xFF == ord('q'):
frame_queue.put(None)
break
# Wait for bot thread to finish
bot_thread.join()