Skip to content

Commit 07ba660

Browse files
authored
Merge pull request #37 from Mineinjava/mineinjavaDev
Add RESUME data
2 parents a19345c + 3f9c746 commit 07ba660

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

discordSplash/__init__.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ def __init__(self, token: str, presence: Presence = None):
281281
TOKEN = token
282282
AUTH_HEADER = {"Authorization": f"Bot {token}"}
283283

284+
284285
self.auth = {
285286
"token": self.TOKEN,
286287
"properties": {
@@ -309,19 +310,32 @@ def __init__(self, token: str, presence: Presence = None):
309310
"afk": False
310311
}
311312

312-
asyncio.run(self.main())
313+
try:
314+
asyncio.run(self.main(False))
315+
except websockets.exceptions.ConnectionClosedError:
316+
while True:
317+
try:
318+
asyncio.run(self.main(True))
319+
except websockets.exceptions.ConnectionClosedError:
320+
pass
313321
# asyncio.get_event_loop().run_until_complete(self.hello())
314322
# print(self.opcode(1, self.sequence))
315323

316-
async def main(self):
324+
async def main(self, resume=False):
317325
async with websockets.connect(
318326
'wss://gateway.discord.gg/?v=6&encoding=json') \
319327
as self.websocket:
320-
await self.hello()
321-
if self.interval is None:
322-
print("Hello failed, exiting")
323-
return
324-
await asyncio.gather(self.heartbeat(), self.receive())
328+
if resume is False:
329+
await self.hello()
330+
if self.interval is None:
331+
print("Hello failed, exiting")
332+
return
333+
await asyncio.gather(self.heartbeat(), self.receive())
334+
if resume is True:
335+
await self.resume()
336+
print('RESUMING------------------------------------------------------------------------------------------------------------------------------------------------')
337+
await asyncio.gather(self.heartbeat(), self.receive())
338+
325339
# while self.interval is not None:
326340
# pass
327341

@@ -383,8 +397,19 @@ def opcode(self, opcode: int, payload) -> str:
383397
"d": payload
384398
}
385399
return json.dumps(data)
400+
386401
async def resume(self):
387-
pass
402+
resume_pkt = await self.create_resume_packet()
403+
await self.send(op.RESUME, resume_pkt)
404+
405+
async def create_resume_packet(self):
406+
resume_blk = {
407+
"token": self.TOKEN,
408+
"session_id": self.session_id,
409+
"seq": self.sequence
410+
}
411+
return resume_blk
412+
388413

389414

390415
def command(name: str):

discordSplash/guild.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
try:
2-
from __init__ import AUTH_HEADER as HEADER
3-
from __init__ import API_URL as URL
2+
from ..discordSplash import AUTH_HEADER as HEADER
3+
from ..discordSplash import API_URL as URL
44
import member
55
import channel
66
except ImportError:

discordSplash/member.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import aiohttp
22

33
try:
4-
from __init__ import AUTH_HEADER as HEADER
5-
from __init__ import API_URL as URL
4+
from ..discordSplash import AUTH_HEADER as HEADER
5+
from ..discordSplash import API_URL as URL
66
except Exception:
77
from discordSplash import API_URL as URL
88
from discordSplash import AUTH_HEADER as HEADER

0 commit comments

Comments
 (0)