-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlogger.py
59 lines (51 loc) · 1.47 KB
/
logger.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
import websocket
import json
import threading
import time
import os
from dotenv import load_dotenv
def send_json_request(ws, request) -> None:
ws.send(json.dumps(request))
def recieve_json_response(ws):
response = ws.recv()
if response:
return json.loads(response)
def heartbeat(interval, ws) -> None:
print('Heartbeat begin')
while True:
time.sleep(interval)
heartbeatJSON = {
"op": 1,
"d": "null"
}
send_json_request(ws, heartbeatJSON)
print("Heartbeat sent")
def initialize(q) -> None:
load_dotenv()
ws = websocket.WebSocket()
ws.connect('wss://gateway.discord.gg/?v=6&encording=json')
event = recieve_json_response(ws)
heartbeat_interval = event['d']['heartbeat_interval'] / 1000
threading._start_new_thread(heartbeat, (heartbeat_interval, ws))
payload = {
'op': 2,
"d": {
"token": os.environ.get('TOKEN'),
"properties": {
"$os": "windows",
"$browser": "chrome",
"$device": 'pc'
}
}
}
send_json_request(ws, payload)
while True:
event = recieve_json_response(ws)
try:
if event['d']['author']['username'] != os.environ.get('BOT_USERNAME'):
q.put(f"{event['d']['content']}")
op_code = event['op']
if op_code == 11:
print('heartbeat received')
except:
pass