every single time.

(simple .json config for the token and later probably the plugin path)
master
cynic 4 years ago
parent 459496d198
commit 663ca911ea
  1. 1
      .gitignore
  2. 11
      client.py
  3. 3
      config.json
  4. 2
      main.py

1
.gitignore vendored

@ -1,3 +1,4 @@
*.pyc *.pyc
__pycache__ __pycache__
.vscode .vscode
config.json

@ -3,13 +3,14 @@ from random import randint
import disc_api import disc_api
from grim_logger import glog, glog_level from grim_logger import glog, glog_level
class client(): class client():
def __init__(self, token): def __init__(self, config_path = "config.json"):
self.logger = glog(level = glog_level.TRACE) self.logger = glog(level = glog_level.TRACE)
self.ws = None self.ws = None
self.last_sequence = None self.last_sequence = None
self.session_id = None self.session_id = None
self.token = token
self.user = None self.user = None
with open(config_path, "r") as conf_fd:
self.config = json.loads(conf_fd.read())
async def shit(self): async def shit(self):
# https://discord.com/developers/docs/topics/gateway#connecting-to-the-gateway # https://discord.com/developers/docs/topics/gateway#connecting-to-the-gateway
# you're supposed to ask an HTTP endpoint what the ws gateway is but the docs didnt tell me the domain after 1sec so HAHA NOPE # you're supposed to ask an HTTP endpoint what the ws gateway is but the docs didnt tell me the domain after 1sec so HAHA NOPE
@ -33,13 +34,13 @@ class client():
asyncio.get_event_loop().create_task(self.heartbeat(interval)) asyncio.get_event_loop().create_task(self.heartbeat(interval))
await asyncio.sleep(1) await asyncio.sleep(1)
# https://discord.com/developers/docs/topics/gateway#identify-example-identify # https://discord.com/developers/docs/topics/gateway#identify-example-identify
await self.ws.send(json.dumps({"op":2, "d":{"token":self.token, "intents": 513, "properties":{"$os":"linux", "browser":"mdbf", "device":"mdbf"}}})) await self.ws.send(json.dumps({"op":2, "d":{"token":self.config["token"], "intents": 513, "properties":{"$os":"linux", "browser":"mdbf", "device":"mdbf"}}}))
else: else:
# https://discord.com/developers/docs/topics/gateway#identify-example-identify # https://discord.com/developers/docs/topics/gateway#identify-example-identify
await self.ws.send(json.dumps({"op":6, "d":{"token":self.token, "session_id":self.session_id, "seq":self.last_sequence}})) await self.ws.send(json.dumps({"op":6, "d":{"token":self.config["token"], "session_id":self.session_id, "seq":self.last_sequence}}))
async def op_invalid_session(self, res): async def op_invalid_session(self, res):
await asyncio.sleep(randint(1, 5)) # try again await asyncio.sleep(randint(1, 5)) # try again
await self.ws.send(json.dumps({"op":2, "d":{"token":self.token, "intents": 513, "properties":{"$os":"linux", "browser":"mdbf", "device":"mdbf"}}})) await self.ws.send(json.dumps({"op":2, "d":{"token":self.config["token"], "intents": 513, "properties":{"$os":"linux", "browser":"mdbf", "device":"mdbf"}}}))
async def op_dispatch(self, res): async def op_dispatch(self, res):
if res["t"] == "READY": if res["t"] == "READY":
self.session_id = res["d"]["session_id"] self.session_id = res["d"]["session_id"]

@ -0,0 +1,3 @@
{
"token": "YOUR_TOKEN_HERE"
}

@ -1,3 +1,3 @@
from client import client from client import client
olive = client("OTIxMDg0ODA3Mjk4MDU2MjAz.YbtxEg.NxS1h63qKDeTn_4voc2Axa_QIFI") olive = client()
olive.run() olive.run()
Loading…
Cancel
Save