-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathprompt_sender.py
56 lines (45 loc) · 1.69 KB
/
prompt_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
import requests
import json
class Sender:
def __init__(self,
params,
index,flag):
self.params = params
self.index = index
try:
self.flag = int(flag)
except ValueError:
self.flag = 0
self.sender_initializer()
def sender_initializer(self):
with open(self.params, "r") as json_file:
params = json.load(json_file)
self.channelid=params['channelid']
self.authorization=params['authorization']
self.application_id = params['application_id']
self.guild_id = params['guild_id']
self.session_id = params['session_id']
self.version = params['version']
self.id = params['id']
self.flags = params['flags']
def send(self, prompt):
header = {
'authorization': self.authorization
}
payload = {'type': 2,
'application_id': self.application_id,
'guild_id': self.guild_id,
'channel_id': self.channelid[self.index],
'session_id': self.session_id,
'data': {
'version': self.version,
'id': self.id,
'name': 'imagine',
'type': 1,
'options': [{'type': 3, 'name': 'prompt', 'value': str(prompt) + ' ' + self.flags[self.flag]}],
'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)
print('prompt [{}] successfully sent!'.format(prompt))