-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathClient.py
218 lines (200 loc) · 6.29 KB
/
Client.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
import requests
import json
import consolemenu
import io
import threading
import time
import traceback
from img2ascii import img2ascii
from PIL import Image
class MainUser:
def __init__(self, obj, token):
self.id = obj['id']
self.user = obj['username']
self.avatar = obj['avatar']
self.num = obj['discriminator']
self.email = obj['email']
self.verified = obj['verified']
self.phone = obj['phone']
self.token = token
Me = None
def login():
token = input('Token = ')
r = requests.get('https://discord.com/api/v6/users/@me', headers={'authorization': token})
if not r.status_code == 200:
print('Login failed.')
exit()
global Me
Me = MainUser(json.loads(r.text), token)
def get_avatar(id, avatar, size = '64'):
r = requests.get(f'https://cdn.discordapp.com/avatars/{id}/{avatar}.png?size=' + size)
if r.status_code == 200:
return r.content
return ''
def info():
img_content = get_avatar(Me.id, Me.avatar)
if img_content == '':
print('[No Avatar]')
else:
img = Image.open(io.BytesIO(img_content))
img2ascii.print_img(img, (32,32), 'o', 1, True)
print(f'\nUsername: {Me.user}#{Me.num}')
print(f'User ID: {Me.id}')
print(f'Email: {Me.email}')
print(f'Phone: {Me.phone}')
print(f'Verified: {Me.verified}')
input()
def send_raw_message(ch_id, msg, fpath = ''):
data = {
'content': msg,
'tts': 'false'
}
files = {}
if not fpath == '':
files['file'] = (fpath.split('\\')[-1], open(fpath, 'rb').read())
r = requests.post(f'https://discord.com/api/v6/channels/{ch_id}/messages',
headers={'authorization': Me.token},
data=data, files=files
)
return r
def send_message():
ch_id = input('Channel ID: ')
msg = input('Message: ')
r = send_raw_message(ch_id, msg)
if r.status_code == 200:
print('Message sent!')
else:
print('Failed to send message:', r.status_code)
input()
def send_file():
ch_id = input('Channel ID: ')
msg = input('Message: ')
f = input('File path: ')
r = send_raw_message(ch_id, msg, f)
if r.status_code == 200:
print('Message sent!')
else:
print('Failed to send message:', r.status_code)
input()
def user_info_raw(user_id, retry = True):
r = requests.get(f'https://discord.com/api/v6/users/{user_id}/profile', headers={'authorization': Me.token})
if not r.status_code == 200:
if retry:
if r.status_code == 429:
lim = json.loads(r.text)
time.sleep(lim['retry_after'] / 1000)
return user_info_raw(user_id, True)
return None
return json.loads(r.text)
def mutual_friends_raw(user_id):
r = requests.get(f'https://discord.com/api/v6/users/{user_id}/relationships', headers={'authorization': Me.token})
if not r.status_code == 200:
return None
return json.loads(r.text)
def flag_value(flag):
arr = {
0: 'None',
1 << 0: 'Discord Employee',
1 << 1: 'Discord Partner',
1 << 2: 'HypeSquad Events',
1 << 3: 'Bug Hunter Level 1',
1 << 6: 'House Bravery',
1 << 7: 'House Brilliance',
1 << 8: 'House Balance',
1 << 9: 'Early Supporter',
1 << 10: 'Team User',
1 << 11: 'Magic Man Level 1',
1 << 12: 'System',
1 << 11: 'Magic Man Level 2',
1 << 14: 'Bug Hunter Level 2',
1 << 15: 'Magic Man Level 3',
1 << 16: 'Verified Bot',
1 << 17: 'Verified Bot Developer'
}
try:
return arr[flag]
except:
return 'Unknown'
def user_info():
user_id = input('User ID: ')
t = user_info_raw(user_id)
# print(t)
if t == None:
print('Failed to get user info.')
input()
return
nitro = not t['premium_since'] == None
t = t['user']
img_content = get_avatar(t['id'], t['avatar'])
if img_content == '':
print('[No Avatar]')
else:
img = Image.open(io.BytesIO(img_content))
img2ascii.print_img(img, (32,32), 'o', 1, True)
print(f'\nUsername: {t["username"]}#{t["discriminator"]}')
print(f'User ID: {t["id"]}')
print(f'Premium: {nitro}')
print(f'Public Flags: {flag_value(t["public_flags"])}')
print(f'Private Flags: {flag_value(t["flags"])}')
print(f'Bot: {"bot" in t}')
input()
def download_avatar():
user_id = input('User ID: ')
t = user_info_raw(user_id)
if t == None:
print('Failed to get user info.')
input()
return
t = t['user']
img_content = get_avatar(t['id'], t['avatar'], '512')
if img_content == '':
print('[No Avatar]')
else:
img = Image.open(io.BytesIO(img_content))
img.save(user_id + '.png', 'png')
print('Avatar saved!')
input()
def get_member_count(srv_id):
r = requests.get(f'https://discord.com/api/v6/guilds/{srv_id}?with_counts=true', headers={'authorization': Me.token})
if not r.status_code == 200:
return -1
return json.loads(r.text)['approximate_member_count']
def get_servers_raw():
r = requests.get(f'https://discord.com/api/v6/users/@me/guilds', headers={'authorization': Me.token})
if not r.status_code == 200:
return None
return json.loads(r.text)
def get_servers():
t = get_servers_raw()
if t == None:
print('Filed to get the list of servers')
input()
return
for srv in t:
print(f'[{srv["id"]}] {srv["name"]}')
input()
def create_list():
import Members
input()
def bulk_send():
ch_id = input('Channel ID: ')
msg = input('Message: ')
count = int(input('Count: '))
print('Sending messages...')
for i in range(count):
sent = False
while not sent:
r = send_raw_message(ch_id, msg)
if not r.status_code == 200:
if r.status_code == 429:
lim = json.loads(r.text)
time.sleep(lim['retry_after'] / 1000)
else:
print('Unknown response encountered:', r.status_code)
input()
return
else:
sent = True
print(f'\tSent {i+1}/{count} -> ~{((i+1)*100/count):.2f}%', end='\r')
print('\nDone')
input()