-
Notifications
You must be signed in to change notification settings - Fork 0
/
dsuserapi.py
283 lines (274 loc) · 8.77 KB
/
dsuserapi.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
import requests
import json
import time
import socket
import asyncio
#RelativeModder, 2021. MIT License
class Locales():
'''All Language Locales goes here'''
dansk="da"
deutsch="de"
english_gb="en-GB"
english_us="en-US"
english="en-US"
spanish = "es-ES"
french = "fr"
horvatski = "hr"
italian = "it"
netherland = "nl"
russian = "ru"
ukrainian = "uk"
class Account():
'''User object ~ Account Object'''
id:int
username:str
avatar_id:str
discriminator:int
public_flags:int
class User():
'''Discord user: id, username, avatar_id, discriminator, premium_since'''
id:int
username:str
avatar_id:str
discriminator:int
premium_since:(None, str)
class Message():
message_id:str
message_type:0
content:str
channel_id:int
author:Account()
attachments:list
embeds:list
mentions:list
mention_roles:list
pinned:bool
mention_everyone:bool
tts:bool
timestamp:str
edited_timestamp:(str, None)
flags:str
class Theme():
'''dark or light theme'''
dark = "dark"
light = "light"
class ExplicitContentFilter():
'''Filter of Explicit content:
everyone
friends
noscan'''
everyone = 2
friends = 1
noscan = 0
class MessageDisplay():
'''Mode of Message displaying:
cozy
compact'''
cozy = False
compact = True
def createDM(recipient:int, token:str, debug=False):
'''Returns DM channel ID'''
url = "https://discord.com/api/v8/users/@me/channels"
headers = {
'authorization': token
}
payload = {
'recipients': [recipient]
}
response = requests.post(url, headers=headers, json=payload)
if(debug):
print(response.text)
return json.loads(response.text)["id"]
def SendMessage(channel:int ,token:str, content:str, tts=False, embed:str="", debug=False, addtitonal_fields:dict={}):
'''Sends message to Channel'''
headers = {
'authorization': token
}
payload = {
'content': content,
'tts': tts,
'embed': embed
}
response = requests.post("https://discord.com/api/v8/channels/"+str(channel)+"/messages", headers=headers, json=payload)
if(debug):
print(response.text)
return json.loads(response.text)["id"]
def changeStatus( token:str, text:str, emoji_name="", emoji_id=0, status="online"):
'''Changing your Discord status such as:
status of online: idle, dnd, online, invisible
custom text status
custom emoji status'''
url = "https://discord.com/api/v8/users/@me/settings"
headers = {
'authorization': token
}
payload = {
'status': status,
'custom_status': {'text':text, 'emoji_name':emoji_name}
}
response = requests.patch(url, headers=headers, json=payload)
return response.text
def getUserInfo(token:str, user_id:int)->User:
'''Getting info about User'''
url = "https://discord.com/api/v8/users/"+str(user_id)+"/profile"
headers = {
'authorization': token
}
response = requests.get(url, headers=headers)
info = json.loads(response.text)
u = User()
u.id = info["user"]["id"]
u.username = info["user"]["username"]
u.avatar_id = info["user"]["avatar"]
u.discriminator = info["user"]["discriminator"]
u.premium_since = info["premium_since"]
return u
def makeFakeRPC(token:str, app_id:int):
'''Making fake Rich Presence(in development)'''
url="https://discord.com/api/v8/oauth2/applications"+str(app_id)+"/rpc"
headers = {
'authorization': token
}
req = requests.get(url, headers=headers)
print(req.text)
def changeTheme(token:str, state:Theme):
'''Changes mode of theme like: dark or light'''
url = "https://discord.com/api/v8/users/@me/settings"
headers = {
'authorization': token
}
payload = {
'theme': state
}
req = requests.patch(url, headers=headers, json=payload)
return req
def changeExplicitContentFilter(token:str, level:ExplicitContentFilter):
'''Changes Explicit Filter Content Level'''
url = "https://discord.com/api/v8/users/@me/settings"
headers = {
'authorization': token
}
payload = {
'explicit_content_filter': level
}
req = requests.patch(url, headers=headers, json=payload)
return req
def changeMessageDisplay(token:str, mode:MessageDisplay):
'''Changes Message Display Mode (cozy, compact)'''
url = "https://discord.com/api/v8/users/@me/settings"
headers = {
'authorization': token
}
payload = {
'message_display_compact': mode
}
req = requests.patch(url, headers=headers, json=payload)
return req
def changeLocale(token:str, locale:Locales):
'''Changes interface language'''
url = "https://discord.com/api/v8/users/@me/settings"
headers = {
'authorization': token
}
payload = {
'locale': locale
}
req = requests.patch(url, headers=headers, json=payload)
return req
def call(token:str, voice_channel_id:int):
'''Calls to voice channel (in development)'''
url = "https://discord.com/api/v8/channels/"+str(voice_channel_id)+"/call"
headers = {
'authorization': token
}
response = requests.get(url, headers=headers)
return response.text
def typing(token:str, channel:int):
'''Making user "typing" the message'''
url = "https://discord.com/api/v8/channels/"+str(channel)+"/typing"
headers = {
'authorization': token
}
response = requests.post(url, headers=headers)
return response.text
def getRelationShips(token:str, user_id):
'''Gets Mutual Friends of User'''
url="https://discord.com/api/v8/users/"+str(user_id)+"/relationships"
headers = {
'authorization': token
}
req = requests.get(url, headers=headers)
members=[]
for member in req.json():
m = Account()
m.id=member["id"]
m.username=member["username"]
m.avatar_id=member["avatar"]
m.discriminator=member["discriminator"]
m.public_flags=member["public_flags"]
members.append(m)
return members
def login(login:str, password:str):
'''Direct Auth with login and password\r\n
Returns: token'''
payload = {
'captcha_key': None,
'login': login,
'password': password
}
req = requests.post("https://discord.com/api/v8/auth/login", json=payload)
return req.json()["token"]
def deleteMessage(token:str, message_id:int, channel_id:int):
url = "https://discord.com/api/v8/channels/"+str(channel_id)+"/messages/"+str(message_id)
headers = {
'authorization': token
}
requests.delete(url, headers=headers)
def editMessage(token:str, message_id:int, channel_id:int, content:str):
url = "https://discord.com/api/v8/channels/"+str(channel_id)+"/messages/"+str(message_id)
headers = {
'authorization': token
}
payload = {
'content': content
}
requests.patch(url, headers=headers, json=payload)
def getMessages(token:str, channel_id:int, limit:int=50):
'''Returns Messages in channel'''
url = "https://discord.com/api/v8/channels/"+str(channel_id)+"/messages?limit="+str(limit)
headers = {
'authorization': token
}
response = requests.get(url, headers=headers)
messages = response.json()
message_list = []
for message in messages:
model = Message()
model.message_id = message["id"]
model.message_type = message["type"]
model.content = message["content"]
model.channel_id = message["channel_id"]
author = Account()
author.id = message["author"]["id"]
author.username = message["author"]["username"]
author.avatar_id = message["author"]["avatar"]
author.discriminator = message["author"]["discriminator"]
author.public_flags = message["author"]["public_flags"]
model.author = author
model.content = message["content"]
model.attachments = message["attachments"]
model.embeds = message["embeds"]
model.mentions = message["mentions"]
model.mention_roles = message["mention_roles"]
model.pinned = message["pinned"]
model.mention_everyone = message["mention_everyone"]
model.tts = message["tts"]
model.timestamp = message["timestamp"]
model.edited_timestamp = message["edited_timestamp"]
model.flags = message["flags"]
message_list.append(model)
return message_list
def getLatest(token, dmid):
latest_message = getMessages(token, dmid, 1)
return latest_message[0]
#end