-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
147 lines (117 loc) · 4.61 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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import io
import json
import discord
from discord import ActionRow, app_commands
from discord.app_commands import Choice
from discord.ext import commands
from discord import SelectMenu, SelectOption
from dotenv import load_dotenv
from loggingChannel import sendLog
import os
import asyncio
from styles import styles
from sd_requests import sd_request
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
GUILD = os.getenv('DISCORD_GUILD')
intents = discord.Intents(messages=True, guilds=True, guild_messages=True,
guild_reactions=True, members=True, reactions=True, presences=True)
intents.message_content = True
intents.reactions = True
class MyClient(discord.Client):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
async def on_ready(self):
# Get the guild object
guild_ids = [786690956514426910,
254779349352448001, 885595844999532624]
for guild_id in guild_ids:
print(f"Syncing trees for guild {guild_id}")
await tree.sync(guild=client.get_guild(guild_id))
print("Synced trees")
# Loaded
print(await sendLog(log=(f'{client.user} has connected to Discord!'), client=client))
await updateStatus()
async def on_message(self, message):
if message.author == client.user:
return
# Update Status
await updateStatus()
# Log message
print(
f'{message.author.name} [{message.author.id}] sent: {message.content} on Channel: {message.channel.id}')
async def updateStatus():
global streamers
with open('status.json') as fs:
data = json.load(fs)
await client.change_presence(
activity=await activityType(data))
async def activityType(data):
if data["activity"]["type"] == "PLAYING":
return discord.Activity(type=discord.Game(data["activity"]["name"]))
elif data["activity"]["type"] == "STREAMING":
return discord.Activity(activity=discord.Streaming(name=data["activity"]["name"], url=data["activity"]["url"]))
elif data["activity"]["type"] == "WATCHING":
return discord.Activity(type=discord.ActivityType.watching, name=data["activity"]["name"])
elif data["activity"]["type"] == "LISTENING":
return discord.Activity(type=discord.ActivityType.listening, name=data["activity"]["name"])
client = MyClient(intents=intents)
tree = app_commands.CommandTree(client)
myid = '<@1043957906921492562>'
# ================================== #
# Slash Commands #
# ================================== #
# Command: /dream
# Description: Dream of an Image
# This should have most of the payload options
# ================================== #
@tree.command(description="Dream of an Image")
async def dream(interaction: discord.Interaction, prompt: str, negative: str = "", easy_negative: bool = True,
steps: int = 20, seed: int = -1, cfg_scale: int = 7, width: int = 512, height: int = 640):
# Dream
print(await sendLog(log=f'{interaction.user.name} dreaming of {prompt}', client=client))
# Acknowledge the interaction
await interaction.response.defer()
# Nerf dangerous commands
if steps > 50:
steps = 50
if width > 800:
width = 800
if height > 800:
height = 800
if width < 100:
width = 100
if height < 100:
height = 100
if steps < 1:
steps = 1
if easy_negative:
if negative != "":
negative += ", "
negative += "lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, artist name"
# Add the command to the queue
payload = {
"prompt": prompt,
"negative_prompt": negative,
"steps": steps,
"seed": seed,
"cfg_scale": cfg_scale,
"width": width,
"height": height
}
# Add the command to the queue
await sd_request(interaction, payload, "txt2img", defer=True)
@tree.command(description="Send something sus")
async def sus(interaction: discord.Interaction):
# Among Us
print(await sendLog(log=f'{interaction.user.name} Sus!', client=client))
# Acknowledge the interaction
await interaction.response.defer()
# Add the command to the queue
payload = {
"prompt": "(masterpiece), best quality, highres, absurdres, 1other, amongus <lora:amongUsLORAV1_v10:0.8>",
"steps": 20
}
await sd_request(interaction, payload, "txt2img")
# Get the TOKEN variable from the environment
client.run(TOKEN)