2019-02-12 20:42:26 +00:00
|
|
|
from src import ModuleManager, utils
|
|
|
|
|
|
|
|
class Module(ModuleManager.BaseModule):
|
2019-02-12 20:48:52 +00:00
|
|
|
def _done_connecting(self, server):
|
2019-12-25 01:41:01 +00:00
|
|
|
target_nick = self._target(server)
|
|
|
|
if not self._regained(server, target_nick):
|
2019-02-12 20:48:52 +00:00
|
|
|
if "MONITOR" in server.isupport:
|
2019-05-12 21:07:25 +00:00
|
|
|
server.send_raw("MONITOR + %s" % target_nick)
|
2019-02-12 21:01:28 +00:00
|
|
|
else:
|
2019-10-08 12:49:43 +00:00
|
|
|
self.timers.add("ison-check", self._ison_check, 30,
|
|
|
|
server=server)
|
2019-02-12 20:48:52 +00:00
|
|
|
|
2019-02-16 15:53:14 +00:00
|
|
|
@utils.hook("received.376")
|
2019-02-12 20:48:52 +00:00
|
|
|
def end_of_motd(self, event):
|
|
|
|
self._done_connecting(event["server"])
|
2019-02-16 15:53:14 +00:00
|
|
|
@utils.hook("received.422")
|
2019-02-12 20:48:52 +00:00
|
|
|
def no_motd(self, event):
|
|
|
|
self._done_connecting(event["server"])
|
2019-02-12 20:42:26 +00:00
|
|
|
|
2019-12-25 01:41:01 +00:00
|
|
|
def _regained(self, server, target_nickname):
|
|
|
|
return server.irc_equals(target_nickname, server.nickname)
|
|
|
|
def _target(self, server):
|
|
|
|
return server.connection_params.nickname
|
|
|
|
|
2019-02-12 20:42:26 +00:00
|
|
|
@utils.hook("self.nick")
|
|
|
|
def self_nick(self, event):
|
2019-12-25 01:41:01 +00:00
|
|
|
target_nick = self._target(event["server"])
|
|
|
|
if self._regained(event["server"], target_nick):
|
2019-02-12 20:42:26 +00:00
|
|
|
if "MONITOR" in event["server"].isupport:
|
2019-05-12 21:07:25 +00:00
|
|
|
event["server"].send_raw("MONITOR - %s " % target_nick)
|
2019-02-12 20:42:26 +00:00
|
|
|
|
2019-12-25 01:41:01 +00:00
|
|
|
@utils.hook("received.nick")
|
|
|
|
def nick(self, event):
|
|
|
|
self._check(event["server"], event["old_nickname"])
|
|
|
|
@utils.hook("received.quit")
|
|
|
|
def quit(self, event):
|
|
|
|
self._check(event["server"], event["user"].nickname)
|
|
|
|
|
|
|
|
def _check(self, server, nickname):
|
|
|
|
target_nick = self._target(server)
|
|
|
|
if (not self._regained(server, target_nick)
|
|
|
|
and server.irc_equals(nickname, target_nick)):
|
|
|
|
server.send_nick(target_nick)
|
|
|
|
|
2019-02-16 15:53:14 +00:00
|
|
|
@utils.hook("received.731")
|
2019-02-12 20:42:26 +00:00
|
|
|
def mon_offline(self, event):
|
2019-12-25 01:41:01 +00:00
|
|
|
target_nick = self._target(event["server"])
|
2019-06-22 21:08:39 +00:00
|
|
|
nicks = event["line"].args[1].split(",")
|
2019-02-12 20:42:26 +00:00
|
|
|
nicks = [event["server"].irc_lower(n) for n in nicks]
|
|
|
|
if event["server"].irc_lower(target_nick) in nicks:
|
|
|
|
event["server"].send_nick(target_nick)
|
|
|
|
|
2019-10-08 12:49:43 +00:00
|
|
|
def _ison_check(self, timer):
|
|
|
|
server = timer.kwargs["server"]
|
2019-12-25 01:41:01 +00:00
|
|
|
target_nick = self._target(server)
|
|
|
|
if not self._regained(server, target_nick):
|
2019-10-08 12:49:43 +00:00
|
|
|
server.send_raw("ISON %s" % target_nick)
|
|
|
|
timer.redo()
|
2019-02-12 20:42:26 +00:00
|
|
|
|
2019-02-16 15:53:14 +00:00
|
|
|
@utils.hook("received.303")
|
2019-02-12 20:42:26 +00:00
|
|
|
def ison_response(self, event):
|
2019-12-25 01:41:01 +00:00
|
|
|
target_nick = self._target(event["server"])
|
|
|
|
if (not event["line"].args[1] and
|
|
|
|
not self._regained(event["server"], target_nick)):
|
2019-02-12 20:42:26 +00:00
|
|
|
event["server"].send_nick(target_nick)
|
|
|
|
|