initial commit
This commit is contained in:
commit
000c512877
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
configuration.json
|
||||
.idea/
|
15
enums.py
Normal file
15
enums.py
Normal file
@ -0,0 +1,15 @@
|
||||
from enum import Enum
|
||||
|
||||
class OpCode(Enum):
|
||||
DISPATCH = 0
|
||||
HEARTBEAT = 1
|
||||
IDENTIFY = 2
|
||||
PRESENCE_UPDATE = 3
|
||||
VOICE_STATE_UPDATE = 4
|
||||
RESUME = 6
|
||||
RECONNECT = 7
|
||||
REQUEST_GUILD_MEMBERS = 8
|
||||
INVALID_SESSION = 9
|
||||
HELLO = 10
|
||||
HEARTBEAT_ACK = 11
|
||||
REQUEST_SOUNDBOARD_SOUNDS = 31
|
42
main.py
Normal file
42
main.py
Normal file
@ -0,0 +1,42 @@
|
||||
import asyncio
|
||||
import websockets
|
||||
import json
|
||||
from enums import OpCode
|
||||
|
||||
GATEWAY_URL = "wss://gateway.discord.gg/?v=10&encoding=json"
|
||||
CONFIG = json.load(open('configuration.json', 'r'))
|
||||
TOKEN = CONFIG["TOKEN"]
|
||||
async def identify(websocket):
|
||||
payload = {
|
||||
"op": OpCode.IDENTIFY, # OpCode 2 = Identify
|
||||
"d": {
|
||||
"token": TOKEN,
|
||||
"properties": {
|
||||
"os": "windows",
|
||||
"browser": "gambling",
|
||||
"device": "gambling"
|
||||
},
|
||||
"intents": 513,
|
||||
}
|
||||
}
|
||||
await websocket.send(json.dumps(payload))
|
||||
|
||||
async def heartbeat(websocket, interval):
|
||||
while True:
|
||||
await asyncio.sleep(interval / 1000)
|
||||
await websocket.send(json.dumps({"op": OpCode.HEARTBEAT, "d": None}))
|
||||
|
||||
async def connect():
|
||||
async with websockets.connect(GATEWAY_URL) as websocket:
|
||||
response = json.loads(await websocket.recv())
|
||||
heartbeat_interval = response["d"]["heartbeat_interval"]
|
||||
|
||||
asyncio.create_task(heartbeat(websocket, heartbeat_interval))
|
||||
|
||||
await identify(websocket)
|
||||
|
||||
while True:
|
||||
message = json.loads(await websocket.recv())
|
||||
print("Received: ", message)
|
||||
|
||||
asyncio.run(connect())
|
Loading…
Reference in New Issue
Block a user