2019-02-22 11:23:36 +00:00
|
|
|
import enum
|
2019-03-03 23:34:39 +00:00
|
|
|
from src import EventManager, ModuleManager, utils
|
2019-02-22 11:23:36 +00:00
|
|
|
from . import channel, core, ircv3, message, user
|
|
|
|
|
|
|
|
class Module(ModuleManager.BaseModule):
|
|
|
|
def _handle(self, server, line):
|
|
|
|
hooks = self.events.on("raw.received").on(line.command).get_hooks()
|
|
|
|
default_events = []
|
|
|
|
for hook in hooks:
|
2019-06-26 09:59:52 +00:00
|
|
|
default_events.append(hook.get_kwarg("default_event", False))
|
2019-02-22 11:23:36 +00:00
|
|
|
|
2019-06-22 11:17:45 +00:00
|
|
|
kwargs = {"server": server, "line": line,
|
2019-06-03 10:03:12 +00:00
|
|
|
"direction": utils.Direction.Recv}
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
self.events.on("raw.received").on(line.command).call_unsafe(**kwargs)
|
2019-06-22 11:17:45 +00:00
|
|
|
if any(default_events) or not hooks:
|
2019-02-22 11:23:36 +00:00
|
|
|
self.events.on("received").on(line.command).call(**kwargs)
|
|
|
|
|
|
|
|
@utils.hook("raw.received")
|
|
|
|
def handle_raw(self, event):
|
2019-05-09 09:36:33 +00:00
|
|
|
if ("batch" in event["line"].tags and
|
|
|
|
event["line"].tags["batch"] in event["server"].batches):
|
2019-06-02 09:13:51 +00:00
|
|
|
event["server"].batches[event["line"].tags["batch"]].add_line(
|
2019-05-22 07:42:03 +00:00
|
|
|
event["line"])
|
2019-02-22 11:23:36 +00:00
|
|
|
else:
|
2019-05-09 09:36:33 +00:00
|
|
|
self._handle(event["server"], event["line"])
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
@utils.hook("raw.send")
|
|
|
|
def handle_send(self, event):
|
2019-02-23 21:33:04 +00:00
|
|
|
self.events.on("raw.send").on(event["line"].command).call_unsafe(
|
2019-06-22 11:17:45 +00:00
|
|
|
server=event["server"], direction=utils.Direction.Send,
|
|
|
|
line=event["line"])
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
# ping from the server
|
|
|
|
@utils.hook("raw.received.ping")
|
|
|
|
def ping(self, event):
|
|
|
|
core.ping(event)
|
|
|
|
|
|
|
|
@utils.hook("raw.received.error")
|
|
|
|
def error(self, event):
|
2019-03-19 10:26:15 +00:00
|
|
|
self.log.error("ERROR received from %s: %s",
|
2019-06-22 11:17:45 +00:00
|
|
|
[str(event["server"]), event["line"].args[0]])
|
2019-02-22 11:23:36 +00:00
|
|
|
@utils.hook("raw.received.fail")
|
|
|
|
def fail(self, event):
|
2019-06-22 11:17:45 +00:00
|
|
|
command = event["line"].args[0]
|
|
|
|
error_code = event["line"].args[1]
|
|
|
|
context = event["line"].args[2:-1]
|
|
|
|
description = event["line"].args[-1]
|
2019-02-22 11:23:36 +00:00
|
|
|
|
2019-06-22 11:17:45 +00:00
|
|
|
self.log.warn("FAIL (%s %s) received on %s: %s",
|
|
|
|
[command, error_code, str(event["server"]), description])
|
2019-05-22 10:56:21 +00:00
|
|
|
self.events.on("received.fail").on(command).call(error_code=error_code,
|
|
|
|
context=context, description=description, server=event["server"])
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
# first numeric line the server sends
|
|
|
|
@utils.hook("raw.received.001", default_event=True)
|
|
|
|
def handle_001(self, event):
|
|
|
|
core.handle_001(event)
|
|
|
|
|
|
|
|
# server telling us what it supports
|
|
|
|
@utils.hook("raw.received.005")
|
|
|
|
def handle_005(self, event):
|
|
|
|
core.handle_005(self.events, event)
|
|
|
|
|
2019-05-15 16:12:21 +00:00
|
|
|
# RPL_MYINFO
|
|
|
|
@utils.hook("raw.received.004")
|
|
|
|
def handle_004(self, event):
|
|
|
|
core.handle_004(event)
|
|
|
|
|
2019-02-22 11:23:36 +00:00
|
|
|
# whois respose (nickname, username, realname, hostname)
|
|
|
|
@utils.hook("raw.received.311", default_event=True)
|
|
|
|
def handle_311(self, event):
|
|
|
|
user.handle_311(event)
|
|
|
|
|
|
|
|
# on-join channel topic line
|
|
|
|
@utils.hook("raw.received.332")
|
|
|
|
def handle_332(self, event):
|
2019-02-22 11:25:04 +00:00
|
|
|
channel.handle_332(self.events, event)
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
# channel topic changed
|
|
|
|
@utils.hook("raw.received.topic")
|
|
|
|
def topic(self, event):
|
2019-02-22 11:27:31 +00:00
|
|
|
channel.topic(self.events, event)
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
# on-join channel topic set by/at
|
|
|
|
@utils.hook("raw.received.333")
|
|
|
|
def handle_333(self, event):
|
|
|
|
channel.handle_333(self.events, event)
|
|
|
|
|
|
|
|
# /names response, also on-join user list
|
|
|
|
@utils.hook("raw.received.353", default_event=True)
|
|
|
|
def handle_353(self, event):
|
|
|
|
channel.handle_353(event)
|
|
|
|
|
|
|
|
# on-join user list has finished
|
|
|
|
@utils.hook("raw.received.366", default_event=True)
|
|
|
|
def handle_366(self, event):
|
|
|
|
channel.handle_366(event)
|
|
|
|
|
2019-03-03 22:46:24 +00:00
|
|
|
@utils.hook("raw.received.375", priority=EventManager.PRIORITY_HIGH)
|
2019-02-22 11:23:36 +00:00
|
|
|
def motd_start(self, event):
|
|
|
|
core.motd_start(event)
|
|
|
|
|
|
|
|
@utils.hook("raw.received.372")
|
2019-03-03 22:46:24 +00:00
|
|
|
@utils.hook("raw.received.375")
|
2019-02-22 11:23:36 +00:00
|
|
|
def motd_line(self, event):
|
|
|
|
core.motd_line(event)
|
|
|
|
|
|
|
|
# on user joining channel
|
|
|
|
@utils.hook("raw.received.join")
|
|
|
|
def join(self, event):
|
|
|
|
channel.join(self.events, event)
|
|
|
|
|
|
|
|
# on user parting channel
|
|
|
|
@utils.hook("raw.received.part")
|
|
|
|
def part(self, event):
|
|
|
|
channel.part(self.events, event)
|
|
|
|
|
|
|
|
# unknown command sent by us, oops!
|
|
|
|
@utils.hook("raw.received.421", default_event=True)
|
|
|
|
def handle_421(self, event):
|
2019-06-22 11:17:45 +00:00
|
|
|
self.bot.log.warn("We sent an unknown command to %s: %s",
|
|
|
|
[str(event["server"]), event["line"].args[1]])
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
# a user has disconnected!
|
|
|
|
@utils.hook("raw.received.quit")
|
|
|
|
@utils.hook("raw.send.quit")
|
|
|
|
def quit(self, event):
|
|
|
|
user.quit(self.events, event)
|
|
|
|
|
|
|
|
# the server is telling us about its capabilities!
|
|
|
|
@utils.hook("raw.received.cap")
|
|
|
|
def cap(self, event):
|
2019-06-20 15:52:23 +00:00
|
|
|
ircv3.cap(self.exports, self.events, event)
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
# the server is asking for authentication
|
|
|
|
@utils.hook("raw.received.authenticate")
|
|
|
|
def authenticate(self, event):
|
|
|
|
ircv3.authenticate(self.events, event)
|
|
|
|
|
|
|
|
# someone has changed their nickname
|
|
|
|
@utils.hook("raw.received.nick")
|
|
|
|
def nick(self, event):
|
|
|
|
user.nick(self.events, event)
|
|
|
|
|
|
|
|
# something's mode has changed
|
|
|
|
@utils.hook("raw.received.mode")
|
|
|
|
def mode(self, event):
|
|
|
|
core.mode(self.events, event)
|
2019-06-06 10:16:47 +00:00
|
|
|
# server telling us our own modes
|
|
|
|
@utils.hook("raw.received.221")
|
|
|
|
def umodeis(self, event):
|
|
|
|
core.handle_221(event)
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
# someone (maybe me!) has been invited somewhere
|
|
|
|
@utils.hook("raw.received.invite")
|
|
|
|
def invite(self, event):
|
|
|
|
core.invite(self.events, event)
|
|
|
|
|
2019-06-03 10:03:12 +00:00
|
|
|
# we've received/sent a PRIVMSG, NOTICE or TAGMSG
|
2019-02-22 11:23:36 +00:00
|
|
|
@utils.hook("raw.received.privmsg")
|
|
|
|
@utils.hook("raw.received.notice")
|
|
|
|
@utils.hook("raw.received.tagmsg")
|
2019-06-03 10:03:12 +00:00
|
|
|
def message(self, event):
|
|
|
|
message.message(self.events, event)
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
# IRCv3 AWAY, used to notify us that a client we can see has changed /away
|
|
|
|
@utils.hook("raw.received.away")
|
|
|
|
def away(self, event):
|
|
|
|
user.away(self.events, event)
|
|
|
|
|
|
|
|
@utils.hook("raw.received.batch")
|
|
|
|
def batch(self, event):
|
2019-06-22 11:17:45 +00:00
|
|
|
identifier = event["line"].args[0]
|
2019-02-22 11:23:36 +00:00
|
|
|
modifier, identifier = identifier[0], identifier[1:]
|
|
|
|
|
|
|
|
if modifier == "+":
|
2019-06-22 11:17:45 +00:00
|
|
|
batch_type = event["line"].args[1]
|
|
|
|
args = event["line"].args[2:]
|
2019-06-02 14:18:09 +00:00
|
|
|
|
|
|
|
batch = utils.irc.IRCBatch(identifier, batch_type, args,
|
2019-09-19 17:16:10 +00:00
|
|
|
event["line"].tags, source=event["line"].source)
|
2019-05-30 14:34:39 +00:00
|
|
|
event["server"].batches[identifier] = batch
|
|
|
|
|
|
|
|
self.events.on("received.batch.start").call(batch=batch,
|
|
|
|
server=event["server"])
|
2019-02-22 11:23:36 +00:00
|
|
|
else:
|
|
|
|
batch = event["server"].batches[identifier]
|
|
|
|
del event["server"].batches[identifier]
|
|
|
|
|
2019-06-02 14:18:09 +00:00
|
|
|
lines = batch.get_lines()
|
|
|
|
|
|
|
|
results = self.events.on("received.batch.end").call(batch=batch,
|
2019-05-30 14:34:39 +00:00
|
|
|
server=event["server"])
|
2019-02-22 11:23:36 +00:00
|
|
|
|
2019-06-02 14:18:09 +00:00
|
|
|
for result in results:
|
|
|
|
if not result == None:
|
|
|
|
lines = result
|
|
|
|
break
|
|
|
|
|
|
|
|
for line in lines:
|
2019-05-22 07:42:41 +00:00
|
|
|
self._handle(event["server"], line)
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
# IRCv3 CHGHOST, a user's username and/or hostname has changed
|
|
|
|
@utils.hook("raw.received.chghost")
|
|
|
|
def chghost(self, event):
|
|
|
|
user.chghost(event)
|
|
|
|
|
|
|
|
# IRCv3 SETNAME, to change a user's realname
|
|
|
|
@utils.hook("raw.received.setname")
|
|
|
|
def setname(self, event):
|
|
|
|
user.setname(event)
|
|
|
|
|
|
|
|
@utils.hook("raw.received.account")
|
|
|
|
def account(self, event):
|
|
|
|
user.account(self.events, event)
|
|
|
|
|
|
|
|
# response to a WHO command for user information
|
|
|
|
@utils.hook("raw.received.352", default_event=True)
|
|
|
|
def handle_352(self, event):
|
|
|
|
core.handle_352(event)
|
|
|
|
|
|
|
|
# response to a WHOX command for user information, including account name
|
|
|
|
@utils.hook("raw.received.354", default_event=True)
|
|
|
|
def handle_354(self, event):
|
|
|
|
core.handle_354(event)
|
|
|
|
|
|
|
|
# response to an empty mode command
|
2019-07-03 07:13:28 +00:00
|
|
|
@utils.hook("raw.received.324")
|
2019-02-22 11:23:36 +00:00
|
|
|
def handle_324(self, event):
|
2019-07-03 07:13:28 +00:00
|
|
|
channel.handle_324(self.events, event)
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
# channel creation unix timestamp
|
|
|
|
@utils.hook("raw.received.329", default_event=True)
|
|
|
|
def handle_329(self, event):
|
|
|
|
channel.handle_329(event)
|
|
|
|
|
|
|
|
# nickname already in use
|
|
|
|
@utils.hook("raw.received.433", default_event=True)
|
|
|
|
def handle_433(self, event):
|
|
|
|
core.handle_433(event)
|
2019-07-04 09:44:52 +00:00
|
|
|
# nickname/channel is temporarily unavailable
|
|
|
|
@utils.hook("raw.received.437")
|
|
|
|
def handle_437(self, event):
|
|
|
|
core.handle_437(event)
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
# we need a registered nickname for this channel
|
|
|
|
@utils.hook("raw.received.477", default_event=True)
|
|
|
|
def handle_477(self, event):
|
2019-09-07 14:21:35 +00:00
|
|
|
channel.handle_477(self.timers, event)
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
# someone's been kicked from a channel
|
|
|
|
@utils.hook("raw.received.kick")
|
|
|
|
def kick(self, event):
|
|
|
|
channel.kick(self.events, event)
|
|
|
|
|
|
|
|
# a channel has been renamed
|
|
|
|
@utils.hook("raw.received.rename")
|
|
|
|
def rename(self, event):
|
|
|
|
channel.rename(self.events, event)
|