-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathSender.py
153 lines (131 loc) · 4.88 KB
/
Sender.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
148
149
150
151
152
153
import requests
import re
import time
import random
class Sender():
def __init__(self, config):
self.params = config
self.sender_initializer()
def sender_initializer(self):
self.channel_id = self.params["channel_id"]
self.authorization = self.params["authorization"]
self.application_id = self.params["application_id"]
self.guild_id = self.params["guild_id"]
self.session_id = self.params["session_id"]
self.version = self.params["version"]
self.id = self.params["id"]
def send(self, prompt, seed=None, flags=""):
header = {
"authorization": self.authorization
}
prompt = prompt.replace("_", " ")
prompt = " ".join(prompt.split())
prompt = re.sub(r"[^a-zA-Z0-9:,\-\s]+", "", prompt)
prompt = prompt.lower()
if seed is None:
seed = random.randint(0, 4294967295)
full_prompt = f"{str(prompt)} --seed {int(seed)} {flags}".strip()
full_prompt = re.sub(r"\s+", " ", full_prompt)
payload = {
"type": 2,
"application_id": self.application_id,
"guild_id": self.guild_id,
"channel_id": self.channel_id,
"session_id": self.session_id,
"data": {
"version": self.version,
"id": self.id,
"name": "imagine",
"type": 1,
"options": [{
"type": 3,
"name": "prompt",
"value": f"{full_prompt}",
}],
"attachments": []
},
}
r = requests.post("https://discord.com/api/v9/interactions", json = payload , headers = header)
while r.status_code != 204:
r = requests.post("https://discord.com/api/v9/interactions", json = payload , headers = header)
time.sleep(1)
print(f"Prompt [{full_prompt}] successfully sent!")
return full_prompt
def send_component(self, message_id, custom_id):
header = {
"authorization": self.authorization
}
payload = {
"type": 3,
"application_id": self.application_id,
"guild_id": self.guild_id,
"channel_id": self.channel_id,
"session_id": self.session_id,
"data": {
"component_type": 2,
"custom_id": custom_id,
},
"message_flags": 0,
"message_id": message_id,
}
r = requests.post("https://discord.com/api/v9/interactions", json = payload , headers = header)
while r.status_code != 204:
r = requests.post("https://discord.com/api/v9/interactions", json = payload , headers = header)
time.sleep(1)
print(f"[{custom_id}] successfully sent!")
def send_describe(self, filename, uploaded_filename):
header = {
"authorization": self.authorization
}
payload = {
"type": 2,
"application_id": self.application_id,
"guild_id": self.guild_id,
"channel_id": self.channel_id,
"session_id": self.session_id,
"data": {
"version": self.version,
"id": self.id,
"name": "describe",
"type": 1,
"options": [{
"type": 11,
"name": "image",
"value": 0
}],
"attachments": [{
"id": "0",
"filename": filename,
"uploaded_filename": uploaded_filename
}],
},
}
r = requests.post("https://discord.com/api/v9/interactions", json = payload , headers = header)
while r.status_code != 204:
r = requests.post("https://discord.com/api/v9/interactions", json = payload , headers = header)
time.sleep(1)
print(f"Describe [{filename}] successfully sent!")
def send_info(self):
header = {
"authorization": self.authorization
}
payload = {
"type": 2,
"application_id": self.application_id,
"guild_id": self.guild_id,
"channel_id": self.channel_id,
"session_id": self.session_id,
"data": {
"version": self.version,
"id": self.id,
"name": "info",
"type": 1,
"options": [],
"attachments": [],
},
}
r = requests.post("https://discord.com/api/v9/interactions", json = payload , headers = header)
while r.status_code != 204:
r = requests.post("https://discord.com/api/v9/interactions", json = payload , headers = header)
time.sleep(1)
print(f"Info successfully sent!")