Support IRCv3's draft/resume-0.2
This commit is contained in:
parent
3ff68dc427
commit
b3625dbe13
1 changed files with 38 additions and 0 deletions
38
modules/resume.py
Normal file
38
modules/resume.py
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
from src import ModuleManager, utils
|
||||||
|
|
||||||
|
CAP = "draft/resume-0.2"
|
||||||
|
|
||||||
|
class Module(ModuleManager.BaseModule):
|
||||||
|
def _get_token(self, server):
|
||||||
|
return server.connection_params.args.get("resume", [None, None])
|
||||||
|
|
||||||
|
@utils.hook("received.cap.ls")
|
||||||
|
def on_cap_new(self, event):
|
||||||
|
username, token = self._get_token(event["server"])
|
||||||
|
if CAP in event["capabilities"] and (not username or not token):
|
||||||
|
event["server"].queue_capability("draft/resume-0.2")
|
||||||
|
|
||||||
|
@utils.hook("received.cap.ack")
|
||||||
|
def on_cap_ack(self, event):
|
||||||
|
username token = self._get_token(event["server"])
|
||||||
|
if CAP in event["capabilities"] and username and token:
|
||||||
|
event["server"].send("RESUME %s %s" % (username, token))
|
||||||
|
return False
|
||||||
|
|
||||||
|
@utils.hook("received.resume")
|
||||||
|
def on_resume(self, event):
|
||||||
|
if event["args"][0] == "SUCCESS":
|
||||||
|
self.log.info("Successfully resumed session")
|
||||||
|
elif event["args"][0] == "ERR":
|
||||||
|
self.log.info("Failed to resume session: %s" % event["args"][1])
|
||||||
|
elif event["args"][0] == "TOKEN":
|
||||||
|
event["server"].connection_params.args["new-token"
|
||||||
|
] = event["args"][1]
|
||||||
|
|
||||||
|
@utils.hook("received.numeric.001")
|
||||||
|
def on_connect(self, event):
|
||||||
|
new_token = event["server"].connection_params.get("new-token")
|
||||||
|
if new_token:
|
||||||
|
event["server"].connection_params.args["resume"] = [
|
||||||
|
event["server"].nickname, new_token]
|
||||||
|
del event["server"].connection_params.args["resume"]
|
Loading…
Reference in a new issue