diff --git a/modules/resume.py b/modules/resume.py index c3999c3d..9f10086b 100644 --- a/modules/resume.py +++ b/modules/resume.py @@ -1,16 +1,22 @@ from src import ModuleManager, utils -CAP = "draft/resume-0.2" +CAP = "draft/resume-0.3" class Module(ModuleManager.BaseModule): - def _get_token(self, server): - return server.connection_params.args.get("resume-token", (None, None)) - def _set_token(Self, server, nickname, token): - server.connection_params.args["resume-token"] = (nickname, token) + def _setting(self, new): + return "resume-token%s" % ("-new" if new else "") + def _get_token(self, server, new=False): + return server.get_setting(self._setting(new), None) + def _set_token(self, server, token, new=False): + server.set_setting(self._setting(new), token) + def _del_token(self, server, new=False): + server.del_setting(self._setting(new)) + + def _get_timestamp(self, server): + return server.get_setting("last-read", None) @utils.hook("received.cap.ls") def on_cap_ls(self, event): - nickname, token = self._get_token(event["server"]) if CAP in event["capabilities"]: event["server"].queue_capability(CAP) @@ -26,26 +32,20 @@ class Module(ModuleManager.BaseModule): 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-resume-token" - ] = event["args"][1] - nickname, token = self._get_token(event["server"]) + token = self._get_token(event["server"]) + self._set_token(event["server"], event["args"][1], new=True) - if nickname and token: - event["server"].send("RESUME %s %s" % (nickname, token)) + if token: + timestamp = self._get_timestamp(event["server"]) + + event["server"].send("RESUME %s%s" % + (token, " %s" % timestamp if timestamp else "")) event["server"].cap_started = False event["server"].capability_done("resume") @utils.hook("received.numeric.001") def on_connect(self, event): - new_token = event["server"].connection_params.args.get( - "new-resume-token", None) + new_token = self._get_token(event["server"], new=True) if new_token: - self._set_token(event["server"], event["server"].nickname, - new_token) - del event["server"].connection_params.args["new-resume-token"] - - @utils.hook("self.nick") - def nick_change(self, event): - nickname, token = self._get_token(event["server"]) - if nickname and token: - self._set_token(event["server"], event["new_nickname"], token) + self._set_token(event["server"], new_token) + self._del_token(event["server"], new=True) diff --git a/src/IRCServer.py b/src/IRCServer.py index f9f85c32..125d0ca8 100644 --- a/src/IRCServer.py +++ b/src/IRCServer.py @@ -233,6 +233,10 @@ class Server(IRCObject.Object): lines = self.socket.read() if lines: self.ping_sent = False + + now = datetime.datetime.utcnow() + self.set_setting("last-read", datetime.datetime.strftime(now, + utils.ISO8601_FORMAT)) return lines def send(self, line: str):