Better support passing "send" events through the parsers already present in
modules/line_handler.py
This commit is contained in:
parent
f7872fac43
commit
ed838193aa
3 changed files with 124 additions and 138 deletions
|
@ -1,4 +1,4 @@
|
||||||
import codecs, re, threading
|
import codecs, enum, re, threading
|
||||||
from src import ModuleManager, utils
|
from src import ModuleManager, utils
|
||||||
|
|
||||||
RE_ISUPPORT_ESCAPE = re.compile(r"\\x(\d\d)", re.I)
|
RE_ISUPPORT_ESCAPE = re.compile(r"\\x(\d\d)", re.I)
|
||||||
|
@ -9,18 +9,23 @@ CAPABILITIES = {"multi-prefix", "chghost", "invite-notify", "account-tag",
|
||||||
"draft/message-tags-0.2", "draft/message-tags-0.3", "server-time",
|
"draft/message-tags-0.2", "draft/message-tags-0.3", "server-time",
|
||||||
"cap-notify", "batch", "draft/labeled-response", "draft/rename"}
|
"cap-notify", "batch", "draft/labeled-response", "draft/rename"}
|
||||||
|
|
||||||
|
class Direction(enum.Enum):
|
||||||
|
SEND = 0
|
||||||
|
RECV = 1
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
def _handle(self, server, line):
|
def _handle(self, server, line):
|
||||||
hooks = self.events.on("raw").on(line.command).get_hooks()
|
hooks = self.events.on("raw.received").on(line.command).get_hooks()
|
||||||
default_events = []
|
default_events = []
|
||||||
for hook in hooks:
|
for hook in hooks:
|
||||||
default_events.append(hook.kwargs.get("default_event", False))
|
default_events.append(hook.kwargs.get("default_event", False))
|
||||||
default_event = any(default_events)
|
default_event = any(default_events)
|
||||||
|
|
||||||
kwargs = {"args": line.args, "tags": line.tags, "server": server,
|
kwargs = {"args": line.args, "tags": line.tags, "server": server,
|
||||||
"prefix": line.prefix, "has_arbitrary": line.has_arbitrary}
|
"prefix": line.prefix, "has_arbitrary": line.has_arbitrary,
|
||||||
|
"direction": Direction.RECV}
|
||||||
|
|
||||||
self.events.on("raw").on(line.command).call_unsafe(**kwargs)
|
self.events.on("raw.received").on(line.command).call_unsafe(**kwargs)
|
||||||
if default_event or not hooks:
|
if default_event or not hooks:
|
||||||
if line.command.isdigit():
|
if line.command.isdigit():
|
||||||
self.events.on("received.numeric").on(line.command).call(
|
self.events.on("received.numeric").on(line.command).call(
|
||||||
|
@ -28,7 +33,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
else:
|
else:
|
||||||
self.events.on("received").on(line.command).call(**kwargs)
|
self.events.on("received").on(line.command).call(**kwargs)
|
||||||
|
|
||||||
@utils.hook("raw")
|
@utils.hook("raw.received")
|
||||||
def handle_raw(self, event):
|
def handle_raw(self, event):
|
||||||
line = utils.irc.parse_line(event["line"])
|
line = utils.irc.parse_line(event["line"])
|
||||||
if "batch" in line.tags and line.tags["batch"] in event[
|
if "batch" in line.tags and line.tags["batch"] in event[
|
||||||
|
@ -40,23 +45,32 @@ class Module(ModuleManager.BaseModule):
|
||||||
@utils.hook("preprocess.send")
|
@utils.hook("preprocess.send")
|
||||||
def handle_send(self, event):
|
def handle_send(self, event):
|
||||||
line = utils.irc.parse_line(event["line"])
|
line = utils.irc.parse_line(event["line"])
|
||||||
self.events.on("send").on(line.command).call(
|
self.events.on("raw.send").on(line.command).call_unsafe(
|
||||||
args=line.args, tags=line.tags, server=event["server"])
|
args=line.args, tags=line.tags, server=event["server"],
|
||||||
|
direction=Direction.SEND)
|
||||||
|
|
||||||
|
def _event(self, event, event_name: str, **kwargs: dict):
|
||||||
|
direction = event["direction"]
|
||||||
|
if direction == Direction.RECV:
|
||||||
|
root_event = self.events.on("received")
|
||||||
|
elif direction == Direction.SEND:
|
||||||
|
root_event = self.events.on("send")
|
||||||
|
root_event.on(event_name).call(**kwargs)
|
||||||
|
|
||||||
# ping from the server
|
# ping from the server
|
||||||
@utils.hook("raw.ping")
|
@utils.hook("raw.received.ping")
|
||||||
def ping(self, event):
|
def ping(self, event):
|
||||||
event["server"].send_pong(event["args"].get(0))
|
event["server"].send_pong(event["args"].get(0))
|
||||||
|
|
||||||
# first numeric line the server sends
|
# first numeric line the server sends
|
||||||
@utils.hook("raw.001", default_event=True)
|
@utils.hook("raw.received.001", default_event=True)
|
||||||
def handle_001(self, event):
|
def handle_001(self, event):
|
||||||
event["server"].name = event["prefix"].nickname
|
event["server"].name = event["prefix"].nickname
|
||||||
event["server"].set_own_nickname(event["args"][0])
|
event["server"].set_own_nickname(event["args"][0])
|
||||||
event["server"].send_whois(event["server"].nickname)
|
event["server"].send_whois(event["server"].nickname)
|
||||||
|
|
||||||
# server telling us what it supports
|
# server telling us what it supports
|
||||||
@utils.hook("raw.005")
|
@utils.hook("raw.received.005")
|
||||||
def handle_005(self, event):
|
def handle_005(self, event):
|
||||||
isupport_list = event["args"][1:]
|
isupport_list = event["args"][1:]
|
||||||
if event["has_arbitrary"]:
|
if event["has_arbitrary"]:
|
||||||
|
@ -96,11 +110,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
if "CASEMAPPING" in isupport:
|
if "CASEMAPPING" in isupport:
|
||||||
event["server"].case_mapping = isupport["CASEMAPPING"]
|
event["server"].case_mapping = isupport["CASEMAPPING"]
|
||||||
|
|
||||||
self.events.on("received.numeric.005").call(
|
self._event(event, "numeric.005", isupport=isupport,
|
||||||
isupport=isupport, server=event["server"])
|
server=event["server"])
|
||||||
|
|
||||||
# whois respose (nickname, username, realname, hostname)
|
# whois respose (nickname, username, realname, hostname)
|
||||||
@utils.hook("raw.311", default_event=True)
|
@utils.hook("raw.received.311", default_event=True)
|
||||||
def handle_311(self, event):
|
def handle_311(self, event):
|
||||||
nickname = event["args"][1]
|
nickname = event["args"][1]
|
||||||
if event["server"].is_own_nickname(nickname):
|
if event["server"].is_own_nickname(nickname):
|
||||||
|
@ -112,26 +126,26 @@ class Module(ModuleManager.BaseModule):
|
||||||
target.realname = event["args"][4]
|
target.realname = event["args"][4]
|
||||||
|
|
||||||
# on-join channel topic line
|
# on-join channel topic line
|
||||||
@utils.hook("raw.332")
|
@utils.hook("raw.received.332")
|
||||||
def handle_332(self, event):
|
def handle_332(self, event):
|
||||||
channel = event["server"].channels.get(event["args"][1])
|
channel = event["server"].channels.get(event["args"][1])
|
||||||
topic = event["args"].get(2)
|
topic = event["args"].get(2)
|
||||||
channel.set_topic(topic)
|
channel.set_topic(topic)
|
||||||
self.events.on("received.numeric.332").call(channel=channel,
|
self._event(event, "numeric.332", channel=channel,
|
||||||
server=event["server"], topic=topic)
|
server=event["server"], topic=topic)
|
||||||
|
|
||||||
# channel topic changed
|
# channel topic changed
|
||||||
@utils.hook("raw.topic")
|
@utils.hook("raw.received.topic")
|
||||||
def topic(self, event):
|
def topic(self, event):
|
||||||
user = event["server"].get_user(event["prefix"].nickname)
|
user = event["server"].get_user(event["prefix"].nickname)
|
||||||
channel = event["server"].channels.get(event["args"][0])
|
channel = event["server"].channels.get(event["args"][0])
|
||||||
topic = event["args"].get(1)
|
topic = event["args"].get(1)
|
||||||
channel.set_topic(topic)
|
channel.set_topic(topic)
|
||||||
self.events.on("received.topic").call(channel=channel,
|
self._event(event, "topic", channel=channel, server=event["server"],
|
||||||
server=event["server"], topic=topic, user=user)
|
topic=topic, user=user)
|
||||||
|
|
||||||
# on-join channel topic set by/at
|
# on-join channel topic set by/at
|
||||||
@utils.hook("raw.333")
|
@utils.hook("raw.received.333")
|
||||||
def handle_333(self, event):
|
def handle_333(self, event):
|
||||||
channel = event["server"].channels.get(event["args"][1])
|
channel = event["server"].channels.get(event["args"][1])
|
||||||
|
|
||||||
|
@ -143,12 +157,12 @@ class Module(ModuleManager.BaseModule):
|
||||||
channel.set_topic_setter(topic_setter.nickname, topic_setter.username,
|
channel.set_topic_setter(topic_setter.nickname, topic_setter.username,
|
||||||
topic_setter.hostname)
|
topic_setter.hostname)
|
||||||
channel.set_topic_time(topic_time)
|
channel.set_topic_time(topic_time)
|
||||||
self.events.on("received.numeric.333").call(channel=channel,
|
self._event(event, "numeric.333", channel=channel,
|
||||||
setter=topic_setter.nickname, set_at=topic_time,
|
setter=topic_setter.nickname, set_at=topic_time,
|
||||||
server=event["server"])
|
server=event["server"])
|
||||||
|
|
||||||
# /names response, also on-join user list
|
# /names response, also on-join user list
|
||||||
@utils.hook("raw.353", default_event=True)
|
@utils.hook("raw.received.353", default_event=True)
|
||||||
def handle_353(self, event):
|
def handle_353(self, event):
|
||||||
channel = event["server"].channels.get(event["args"][2])
|
channel = event["server"].channels.get(event["args"][2])
|
||||||
nicknames = event["args"].get(3).split()
|
nicknames = event["args"].get(3).split()
|
||||||
|
@ -174,21 +188,21 @@ class Module(ModuleManager.BaseModule):
|
||||||
channel.add_mode(mode, nickname)
|
channel.add_mode(mode, nickname)
|
||||||
|
|
||||||
# on-join user list has finished
|
# on-join user list has finished
|
||||||
@utils.hook("raw.366", default_event=True)
|
@utils.hook("raw.received.366", default_event=True)
|
||||||
def handle_366(self, event):
|
def handle_366(self, event):
|
||||||
event["server"].send_whox(event["args"][1], "n", "ahnrtu", "111")
|
event["server"].send_whox(event["args"][1], "n", "ahnrtu", "111")
|
||||||
|
|
||||||
@utils.hook("raw.375")
|
@utils.hook("raw.received.375")
|
||||||
def motd_start(self, event):
|
def motd_start(self, event):
|
||||||
event["server"].motd_lines.clear()
|
event["server"].motd_lines.clear()
|
||||||
event["server"].motd_lines.append(event["args"][1])
|
event["server"].motd_lines.append(event["args"][1])
|
||||||
|
|
||||||
@utils.hook("raw.372")
|
@utils.hook("raw.received.372")
|
||||||
def motd_line(self, event):
|
def motd_line(self, event):
|
||||||
event["server"].motd_lines.append(event["args"][1])
|
event["server"].motd_lines.append(event["args"][1])
|
||||||
|
|
||||||
# on user joining channel
|
# on user joining channel
|
||||||
@utils.hook("raw.join")
|
@utils.hook("raw.received.join")
|
||||||
def join(self, event):
|
def join(self, event):
|
||||||
account = None
|
account = None
|
||||||
realname = None
|
realname = None
|
||||||
|
@ -215,56 +229,55 @@ class Module(ModuleManager.BaseModule):
|
||||||
|
|
||||||
channel.add_user(user)
|
channel.add_user(user)
|
||||||
user.join_channel(channel)
|
user.join_channel(channel)
|
||||||
self.events.on("received.join").call(channel=channel,
|
self._event(event, "join", channel=channel, user=user,
|
||||||
user=user, server=event["server"], account=account,
|
server=event["server"], account=account, realname=realname)
|
||||||
realname=realname)
|
|
||||||
else:
|
else:
|
||||||
channel = event["server"].channels.add(channel_name)
|
channel = event["server"].channels.add(channel_name)
|
||||||
if channel.name in event["server"].attempted_join:
|
if channel.name in event["server"].attempted_join:
|
||||||
del event["server"].attempted_join[channel.name]
|
del event["server"].attempted_join[channel.name]
|
||||||
self.events.on("self.join").call(channel=channel,
|
self._event(event,"self.join", channel=channel,
|
||||||
server=event["server"], account=account, realname=realname)
|
server=event["server"], account=account, realname=realname)
|
||||||
channel.send_mode()
|
channel.send_mode()
|
||||||
|
|
||||||
# on user parting channel
|
# on user parting channel
|
||||||
@utils.hook("raw.part")
|
@utils.hook("raw.received.part")
|
||||||
def part(self, event):
|
def part(self, event):
|
||||||
channel = event["server"].channels.get(event["args"][0])
|
channel = event["server"].channels.get(event["args"][0])
|
||||||
reason = event["args"].get(1)
|
reason = event["args"].get(1)
|
||||||
|
|
||||||
if not event["server"].is_own_nickname(event["prefix"].nickname):
|
if not event["server"].is_own_nickname(event["prefix"].nickname):
|
||||||
user = event["server"].get_user(event["prefix"].nickname)
|
user = event["server"].get_user(event["prefix"].nickname)
|
||||||
self.events.on("received.part").call(channel=channel,
|
self._event(event, "part", channel=channel, reason=reason,
|
||||||
reason=reason, user=user, server=event["server"])
|
user=user, server=event["server"])
|
||||||
channel.remove_user(user)
|
channel.remove_user(user)
|
||||||
user.part_channel(channel)
|
user.part_channel(channel)
|
||||||
if not len(user.channels):
|
if not len(user.channels):
|
||||||
event["server"].remove_user(user)
|
event["server"].remove_user(user)
|
||||||
else:
|
else:
|
||||||
self.events.on("self.part").call(channel=channel,
|
self._event(event,"self.part", channel=channel, reason=reason,
|
||||||
reason=reason, server=event["server"])
|
server=event["server"])
|
||||||
event["server"].channels.remove(channel)
|
event["server"].channels.remove(channel)
|
||||||
|
|
||||||
# unknown command sent by us, oops!
|
# unknown command sent by us, oops!
|
||||||
@utils.hook("raw.421", default_event=True)
|
@utils.hook("raw.received.421", default_event=True)
|
||||||
def handle_421(self, event):
|
def handle_421(self, event):
|
||||||
print("warning: unknown command '%s'." % event["args"][1])
|
print("warning: unknown command '%s'." % event["args"][1])
|
||||||
|
|
||||||
# a user has disconnected!
|
# a user has disconnected!
|
||||||
@utils.hook("raw.quit")
|
@utils.hook("raw.received.quit")
|
||||||
def quit(self, event):
|
def quit(self, event):
|
||||||
reason = event["args"].get(0)
|
reason = event["args"].get(0)
|
||||||
|
|
||||||
if not event["server"].is_own_nickname(event["prefix"].nickname):
|
if not event["server"].is_own_nickname(event["prefix"].nickname):
|
||||||
user = event["server"].get_user(event["prefix"].nickname)
|
user = event["server"].get_user(event["prefix"].nickname)
|
||||||
event["server"].remove_user(user)
|
event["server"].remove_user(user)
|
||||||
self.events.on("received.quit").call(reason=reason,
|
self._event(event, "quit", reason=reason, user=user,
|
||||||
user=user, server=event["server"])
|
server=event["server"])
|
||||||
else:
|
else:
|
||||||
event["server"].disconnect()
|
event["server"].disconnect()
|
||||||
|
|
||||||
# the server is telling us about its capabilities!
|
# the server is telling us about its capabilities!
|
||||||
@utils.hook("raw.cap")
|
@utils.hook("raw.received.cap")
|
||||||
def cap(self, event):
|
def cap(self, event):
|
||||||
capabilities = utils.parse.keyvalue(event["args"][2])
|
capabilities = utils.parse.keyvalue(event["args"][2])
|
||||||
subcommand = event["args"][1].lower()
|
subcommand = event["args"][1].lower()
|
||||||
|
@ -279,7 +292,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
if matched_capabilities:
|
if matched_capabilities:
|
||||||
event["server"].queue_capabilities(matched_capabilities)
|
event["server"].queue_capabilities(matched_capabilities)
|
||||||
|
|
||||||
self.events.on("received.cap.ls").call(
|
self._event(event, "cap.ls",
|
||||||
capabilities=event["server"].server_capabilities,
|
capabilities=event["server"].server_capabilities,
|
||||||
server=event["server"])
|
server=event["server"])
|
||||||
|
|
||||||
|
@ -289,17 +302,17 @@ class Module(ModuleManager.BaseModule):
|
||||||
event["server"].send_capability_end()
|
event["server"].send_capability_end()
|
||||||
elif subcommand == "new":
|
elif subcommand == "new":
|
||||||
event["server"].capabilities.update(set(capabilities.keys()))
|
event["server"].capabilities.update(set(capabilities.keys()))
|
||||||
self.events.on("received.cap.new").call(server=event["server"],
|
self._event(event, "cap.new", server=event["server"],
|
||||||
capabilities=capabilities)
|
capabilities=capabilities)
|
||||||
elif subcommand == "del":
|
elif subcommand == "del":
|
||||||
event["server"].capabilities.difference_update(set(
|
event["server"].capabilities.difference_update(set(
|
||||||
capabilities.keys()))
|
capabilities.keys()))
|
||||||
self.events.on("received.cap.del").call(server=event["server"],
|
self._event(event, "cap.del", server=event["server"],
|
||||||
capabilities=capabilities)
|
capabilities=capabilities)
|
||||||
elif subcommand == "ack":
|
elif subcommand == "ack":
|
||||||
event["server"].capabilities.update(capabilities)
|
event["server"].capabilities.update(capabilities)
|
||||||
if not is_multiline:
|
if not is_multiline:
|
||||||
self.events.on("received.cap.ack").call(
|
self._event(event, "cap.ack",
|
||||||
capabilities=event["server"].capabilities,
|
capabilities=event["server"].capabilities,
|
||||||
server=event["server"])
|
server=event["server"])
|
||||||
|
|
||||||
|
@ -311,13 +324,13 @@ class Module(ModuleManager.BaseModule):
|
||||||
event["server"].send_capability_end()
|
event["server"].send_capability_end()
|
||||||
|
|
||||||
# the server is asking for authentication
|
# the server is asking for authentication
|
||||||
@utils.hook("raw.authenticate")
|
@utils.hook("raw.received.authenticate")
|
||||||
def authenticate(self, event):
|
def authenticate(self, event):
|
||||||
self.events.on("received.authenticate").call(
|
self._event(event, "authenticate", message=event["args"][0],
|
||||||
message=event["args"][0], server=event["server"])
|
server=event["server"])
|
||||||
|
|
||||||
# someone has changed their nickname
|
# someone has changed their nickname
|
||||||
@utils.hook("raw.nick")
|
@utils.hook("raw.received.nick")
|
||||||
def nick(self, event):
|
def nick(self, event):
|
||||||
new_nickname = event["args"].get(0)
|
new_nickname = event["args"].get(0)
|
||||||
if not event["server"].is_own_nickname(event["prefix"].nickname):
|
if not event["server"].is_own_nickname(event["prefix"].nickname):
|
||||||
|
@ -326,17 +339,17 @@ class Module(ModuleManager.BaseModule):
|
||||||
user.set_nickname(new_nickname)
|
user.set_nickname(new_nickname)
|
||||||
event["server"].change_user_nickname(old_nickname, new_nickname)
|
event["server"].change_user_nickname(old_nickname, new_nickname)
|
||||||
|
|
||||||
self.events.on("received.nick").call(new_nickname=new_nickname,
|
self._event(event, "nick", new_nickname=new_nickname,
|
||||||
old_nickname=old_nickname, user=user, server=event["server"])
|
old_nickname=old_nickname, user=user, server=event["server"])
|
||||||
else:
|
else:
|
||||||
old_nickname = event["server"].nickname
|
old_nickname = event["server"].nickname
|
||||||
event["server"].set_own_nickname(new_nickname)
|
event["server"].set_own_nickname(new_nickname)
|
||||||
|
|
||||||
self.events.on("self.nick").call(server=event["server"],
|
self._event(event,"self.nick", server=event["server"],
|
||||||
new_nickname=new_nickname, old_nickname=old_nickname)
|
new_nickname=new_nickname, old_nickname=old_nickname)
|
||||||
|
|
||||||
# something's mode has changed
|
# something's mode has changed
|
||||||
@utils.hook("raw.mode")
|
@utils.hook("raw.received.mode")
|
||||||
def mode(self, event):
|
def mode(self, event):
|
||||||
user = event["server"].get_user(event["prefix"].nickname)
|
user = event["server"].get_user(event["prefix"].nickname)
|
||||||
target = event["args"][0]
|
target = event["args"][0]
|
||||||
|
@ -356,32 +369,35 @@ class Module(ModuleManager.BaseModule):
|
||||||
channel.change_mode(remove, mode, args.pop(0))
|
channel.change_mode(remove, mode, args.pop(0))
|
||||||
else:
|
else:
|
||||||
args.pop(0)
|
args.pop(0)
|
||||||
self.events.on("received.mode.channel").call(modes=modes,
|
self._event(event, "mode.channel", modes=modes, mode_args=_args,
|
||||||
mode_args=_args, channel=channel, server=event["server"],
|
channel=channel, server=event["server"], user=user)
|
||||||
user=user)
|
|
||||||
elif event["server"].is_own_nickname(target):
|
elif event["server"].is_own_nickname(target):
|
||||||
modes = RE_MODES.findall(event["args"][1])
|
modes = RE_MODES.findall(event["args"][1])
|
||||||
for chunk in modes:
|
for chunk in modes:
|
||||||
remove = chunk[0] == "-"
|
remove = chunk[0] == "-"
|
||||||
for mode in chunk[1:]:
|
for mode in chunk[1:]:
|
||||||
event["server"].change_own_mode(remove, mode)
|
event["server"].change_own_mode(remove, mode)
|
||||||
self.events.on("self.mode").call(modes=modes,
|
self._event(event,"self.mode", modes=modes, server=event["server"])
|
||||||
server=event["server"])
|
|
||||||
|
|
||||||
# someone (maybe me!) has been invited somewhere
|
# someone (maybe me!) has been invited somewhere
|
||||||
@utils.hook("raw.invite")
|
@utils.hook("raw.received.invite")
|
||||||
def invite(self, event):
|
def invite(self, event):
|
||||||
target_channel = event["args"][1]
|
target_channel = event["args"][1]
|
||||||
user = event["server"].get_user(event["prefix"].nickname)
|
user = event["server"].get_user(event["prefix"].nickname)
|
||||||
target_user = event["server"].get_user(event["args"][0])
|
target_user = event["server"].get_user(event["args"][0])
|
||||||
self.events.on("received.invite").call(user=user,
|
self._event(event, "invite", user=user, target_channel=target_channel,
|
||||||
target_channel=target_channel, server=event["server"],
|
server=event["server"], target_user=target_user)
|
||||||
target_user=target_user)
|
|
||||||
|
|
||||||
# we've received a message
|
# we've received/sent a message
|
||||||
@utils.hook("raw.privmsg")
|
@utils.hook("raw.received.privmsg")
|
||||||
|
@utils.hook("raw.send.privmsg")
|
||||||
def privmsg(self, event):
|
def privmsg(self, event):
|
||||||
|
user = None
|
||||||
|
user_nickname = None
|
||||||
|
if "prefix" in event:
|
||||||
user = event["server"].get_user(event["prefix"].nickname)
|
user = event["server"].get_user(event["prefix"].nickname)
|
||||||
|
user_nickname = user.nickname
|
||||||
|
|
||||||
message = event["args"][1]
|
message = event["args"][1]
|
||||||
message_split = message.split(" ")
|
message_split = message.split(" ")
|
||||||
target = event["args"][0]
|
target = event["args"][0]
|
||||||
|
@ -391,7 +407,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
if message.endswith("\x01"):
|
if message.endswith("\x01"):
|
||||||
message = message[:-1]
|
message = message[:-1]
|
||||||
|
|
||||||
if "account" in event["tags"]:
|
if user and "account" in event["tags"]:
|
||||||
user.identified_account = event["tags"]["account"]
|
user.identified_account = event["tags"]["account"]
|
||||||
user.identified_account_id = event["server"].get_user(
|
user.identified_account_id = event["server"].get_user(
|
||||||
event["tags"]["account"]).get_id()
|
event["tags"]["account"]).get_id()
|
||||||
|
@ -402,18 +418,17 @@ class Module(ModuleManager.BaseModule):
|
||||||
|
|
||||||
if target[0] in event["server"].channel_types:
|
if target[0] in event["server"].channel_types:
|
||||||
channel = event["server"].channels.get(event["args"][0])
|
channel = event["server"].channels.get(event["args"][0])
|
||||||
self.events.on("received.message.channel").call(
|
self._event(event, "message.channel", user=user, channel=channel,
|
||||||
user=user, channel=channel, **kwargs)
|
**kwargs)
|
||||||
channel.buffer.add_message(user.nickname, message, action,
|
channel.buffer.add_message(user_nickname, message, action,
|
||||||
event["tags"])
|
event["tags"], user==None)
|
||||||
elif event["server"].is_own_nickname(target):
|
elif event["server"].is_own_nickname(target):
|
||||||
self.events.on("received.message.private").call(
|
self._event(event, "message.private", user=user, **kwargs)
|
||||||
user=user, **kwargs)
|
user.buffer.add_message(user_nickname, message, action,
|
||||||
user.buffer.add_message(user.nickname, message, action,
|
event["tags"], user=None)
|
||||||
event["tags"])
|
|
||||||
|
|
||||||
# we've received a notice
|
# we've received a notice
|
||||||
@utils.hook("raw.notice")
|
@utils.hook("raw.received.notice")
|
||||||
def notice(self, event):
|
def notice(self, event):
|
||||||
message = event["args"][1]
|
message = event["args"][1]
|
||||||
message_split = message.split(" ")
|
message_split = message.split(" ")
|
||||||
|
@ -424,52 +439,50 @@ class Module(ModuleManager.BaseModule):
|
||||||
not event["server"].name):
|
not event["server"].name):
|
||||||
event["server"].name = event["prefix"].hostmask
|
event["server"].name = event["prefix"].hostmask
|
||||||
|
|
||||||
self.events.on("received.server-notice").call(
|
self._event(event, "server-notice", message=message,
|
||||||
message=message, message_split=message_split,
|
message_split=message_split, server=event["server"])
|
||||||
server=event["server"])
|
|
||||||
else:
|
else:
|
||||||
user = event["server"].get_user(event["prefix"].nickname)
|
user = event["server"].get_user(event["prefix"].nickname)
|
||||||
|
|
||||||
if target[0] in event["server"].channel_types:
|
if target[0] in event["server"].channel_types:
|
||||||
channel = event["server"].channels.get(target)
|
channel = event["server"].channels.get(target)
|
||||||
self.events.on("received.notice.channel").call(
|
self._event(event, "notice.channel", message=message,
|
||||||
message=message, message_split=message_split, user=user,
|
message_split=message_split, user=user,
|
||||||
server=event["server"], channel=channel,
|
server=event["server"], channel=channel,
|
||||||
tags=event["tags"])
|
tags=event["tags"])
|
||||||
elif event["server"].is_own_nickname(target):
|
elif event["server"].is_own_nickname(target):
|
||||||
self.events.on("received.notice.private").call(
|
self._event(event, "notice.private", message=message,
|
||||||
message=message, message_split=message_split, user=user,
|
message_split=message_split, user=user,
|
||||||
server=event["server"], tags=event["tags"])
|
server=event["server"], tags=event["tags"])
|
||||||
|
|
||||||
# IRCv3 TAGMSG, used to send tags without any other information
|
# IRCv3 TAGMSG, used to send tags without any other information
|
||||||
@utils.hook("raw.tagmsg")
|
@utils.hook("raw.received.tagmsg")
|
||||||
def tagmsg(self, event):
|
def tagmsg(self, event):
|
||||||
user = event["server"].get_user(event["prefix"].nickname)
|
user = event["server"].get_user(event["prefix"].nickname)
|
||||||
target = event["args"][0]
|
target = event["args"][0]
|
||||||
|
|
||||||
if target[0] in event["server"].channel_types:
|
if target[0] in event["server"].channel_types:
|
||||||
channel = event["server"].channels.get(target)
|
channel = event["server"].channels.get(target)
|
||||||
self.events.on("received.tagmsg.channel").call(channel=channel,
|
self._event(event, "tagmsg.channel", channel=channel, user=user,
|
||||||
user=user, tags=event["tags"], server=event["server"])
|
tags=event["tags"], server=event["server"])
|
||||||
elif event["server"].is_own_nickname(target):
|
elif event["server"].is_own_nickname(target):
|
||||||
self.events.on("received.tagmsg.private").call(
|
self._event(event, "tagmsg.private", user=user, tags=event["tags"],
|
||||||
user=user, tags=event["tags"], server=event["server"])
|
server=event["server"])
|
||||||
|
|
||||||
# IRCv3 AWAY, used to notify us that a client we can see has changed /away
|
# IRCv3 AWAY, used to notify us that a client we can see has changed /away
|
||||||
@utils.hook("raw.away")
|
@utils.hook("raw.received.away")
|
||||||
def away(self, event):
|
def away(self, event):
|
||||||
user = event["server"].get_user(event["prefix"].nickname)
|
user = event["server"].get_user(event["prefix"].nickname)
|
||||||
message = event["args"].get(0)
|
message = event["args"].get(0)
|
||||||
if message:
|
if message:
|
||||||
user.away = True
|
user.away = True
|
||||||
self.events.on("received.away.on").call(user=user,
|
self._event(event, "away.on", user=user, server=event["server"],
|
||||||
server=event["server"], message=message)
|
message=message)
|
||||||
else:
|
else:
|
||||||
user.away = False
|
user.away = False
|
||||||
self.events.on("received.away.off").call(user=user,
|
self._event(event, "away.off", user=user, server=event["server"])
|
||||||
server=event["server"])
|
|
||||||
|
|
||||||
@utils.hook("raw.batch")
|
@utils.hook("raw.received.batch")
|
||||||
def batch(self, event):
|
def batch(self, event):
|
||||||
identifier = event["args"][0]
|
identifier = event["args"][0]
|
||||||
modifier, identifier = identifier[0], identifier[1:]
|
modifier, identifier = identifier[0], identifier[1:]
|
||||||
|
@ -482,7 +495,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
self._handle(line)
|
self._handle(line)
|
||||||
|
|
||||||
# IRCv3 CHGHOST, a user's username and/or hostname has changed
|
# IRCv3 CHGHOST, a user's username and/or hostname has changed
|
||||||
@utils.hook("raw.chghost")
|
@utils.hook("raw.received.chghost")
|
||||||
def chghost(self, event):
|
def chghost(self, event):
|
||||||
username = event["args"][0]
|
username = event["args"][0]
|
||||||
hostname = event["args"][1]
|
hostname = event["args"][1]
|
||||||
|
@ -494,7 +507,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
target.username = username
|
target.username = username
|
||||||
target.hostname = hostname
|
target.hostname = hostname
|
||||||
|
|
||||||
@utils.hook("raw.account")
|
@utils.hook("raw.received.account")
|
||||||
def account(self, event):
|
def account(self, event):
|
||||||
user = event["server"].get_user(event["prefix"].nickname)
|
user = event["server"].get_user(event["prefix"].nickname)
|
||||||
|
|
||||||
|
@ -502,22 +515,22 @@ class Module(ModuleManager.BaseModule):
|
||||||
user.identified_account = event["args"][0]
|
user.identified_account = event["args"][0]
|
||||||
user.identified_account_id = event["server"].get_user(
|
user.identified_account_id = event["server"].get_user(
|
||||||
event["args"][0]).get_id()
|
event["args"][0]).get_id()
|
||||||
self.events.on("received.account.login").call(user=user,
|
self._event(event, "account.login", user=user,
|
||||||
server=event["server"], account=event["args"][0])
|
server=event["server"], account=event["args"][0])
|
||||||
else:
|
else:
|
||||||
user.identified_account = None
|
user.identified_account = None
|
||||||
user.identified_account_id = None
|
user.identified_account_id = None
|
||||||
self.events.on("received.account.logout").call(user=user,
|
self._event(event, "account.logout", user=user,
|
||||||
server=event["server"])
|
server=event["server"])
|
||||||
|
|
||||||
# response to a WHO command for user information
|
# response to a WHO command for user information
|
||||||
@utils.hook("raw.352", default_event=True)
|
@utils.hook("raw.received.352", default_event=True)
|
||||||
def handle_352(self, event):
|
def handle_352(self, event):
|
||||||
user = event["server"].get_user(event["args"][5])
|
user = event["server"].get_user(event["args"][5])
|
||||||
user.username = event["args"][2]
|
user.username = event["args"][2]
|
||||||
user.hostname = event["args"][3]
|
user.hostname = event["args"][3]
|
||||||
# response to a WHOX command for user information, including account name
|
# response to a WHOX command for user information, including account name
|
||||||
@utils.hook("raw.354", default_event=True)
|
@utils.hook("raw.received.354", default_event=True)
|
||||||
def handle_354(self, event):
|
def handle_354(self, event):
|
||||||
if event["args"][1] == "111":
|
if event["args"][1] == "111":
|
||||||
username = event["args"][2]
|
username = event["args"][2]
|
||||||
|
@ -534,7 +547,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
user.identified_account = account
|
user.identified_account = account
|
||||||
|
|
||||||
# response to an empty mode command
|
# response to an empty mode command
|
||||||
@utils.hook("raw.324", default_event=True)
|
@utils.hook("raw.received.324", default_event=True)
|
||||||
def handle_324(self, event):
|
def handle_324(self, event):
|
||||||
channel = event["server"].channels.get(event["args"][1])
|
channel = event["server"].channels.get(event["args"][1])
|
||||||
modes = event["args"][2]
|
modes = event["args"][2]
|
||||||
|
@ -544,18 +557,18 @@ class Module(ModuleManager.BaseModule):
|
||||||
channel.add_mode(mode)
|
channel.add_mode(mode)
|
||||||
|
|
||||||
# channel creation unix timestamp
|
# channel creation unix timestamp
|
||||||
@utils.hook("raw.329", default_event=True)
|
@utils.hook("raw.received.329", default_event=True)
|
||||||
def handle_329(self, event):
|
def handle_329(self, event):
|
||||||
channel = event["server"].channels.get(event["args"][1])
|
channel = event["server"].channels.get(event["args"][1])
|
||||||
channel.creation_timestamp = int(event["args"][2])
|
channel.creation_timestamp = int(event["args"][2])
|
||||||
|
|
||||||
# nickname already in use
|
# nickname already in use
|
||||||
@utils.hook("raw.433", default_event=True)
|
@utils.hook("raw.received.433", default_event=True)
|
||||||
def handle_433(self, event):
|
def handle_433(self, event):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# we need a registered nickname for this channel
|
# we need a registered nickname for this channel
|
||||||
@utils.hook("raw.477", default_event=True)
|
@utils.hook("raw.received.477", default_event=True)
|
||||||
def handle_477(self, event):
|
def handle_477(self, event):
|
||||||
channel_name = utils.irc.lower(event["server"].case_mapping,
|
channel_name = utils.irc.lower(event["server"].case_mapping,
|
||||||
event["args"][1])
|
event["args"][1])
|
||||||
|
@ -565,7 +578,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
server_id=event["server"].id)
|
server_id=event["server"].id)
|
||||||
|
|
||||||
# someone's been kicked from a channel
|
# someone's been kicked from a channel
|
||||||
@utils.hook("raw.kick")
|
@utils.hook("raw.received.kick")
|
||||||
def kick(self, event):
|
def kick(self, event):
|
||||||
user = event["server"].get_user(event["prefix"].nickname)
|
user = event["server"].get_user(event["prefix"].nickname)
|
||||||
target = event["args"][1]
|
target = event["args"][1]
|
||||||
|
@ -574,21 +587,20 @@ class Module(ModuleManager.BaseModule):
|
||||||
|
|
||||||
if not event["server"].is_own_nickname(target):
|
if not event["server"].is_own_nickname(target):
|
||||||
target_user = event["server"].get_user(target)
|
target_user = event["server"].get_user(target)
|
||||||
self.events.on("received.kick").call(channel=channel,
|
self._event(event, "kick", channel=channel, reason=reason,
|
||||||
reason=reason, target_user=target_user, user=user,
|
target_user=target_user, user=user, server=event["server"])
|
||||||
server=event["server"])
|
|
||||||
else:
|
else:
|
||||||
self.events.on("self.kick").call(channel=channel,
|
self._event(event,"self.kick", channel=channel, reason=reason,
|
||||||
reason=reason, user=user, server=event["server"])
|
user=user, server=event["server"])
|
||||||
|
|
||||||
# a channel has been renamed
|
# a channel has been renamed
|
||||||
@utils.hook("raw.rename")
|
@utils.hook("raw.received.rename")
|
||||||
def rename(self, event):
|
def rename(self, event):
|
||||||
old_name = event["args"][0]
|
old_name = event["args"][0]
|
||||||
new_name = event["args"][1]
|
new_name = event["args"][1]
|
||||||
channel = event["server"].channels.get(old_name)
|
channel = event["server"].channels.get(old_name)
|
||||||
|
|
||||||
event["server"].channels.rename(old_name, new_name)
|
event["server"].channels.rename(old_name, new_name)
|
||||||
self.events.on("received.rename").call(channel=channel,
|
self._event(event, "rename", channel=channel, old_name=old_name,
|
||||||
old_name=old_name, new_name=new_name,
|
new_name=new_name, reason=event["args"].get(2),
|
||||||
reason=event["args"].get(2), server=event["server"])
|
server=event["server"])
|
||||||
|
|
|
@ -32,7 +32,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
priority=EventManager.PRIORITY_MONITOR)
|
priority=EventManager.PRIORITY_MONITOR)
|
||||||
def channel_message(self, event):
|
def channel_message(self, event):
|
||||||
self._channel_message(event["user"], event)
|
self._channel_message(event["user"], event)
|
||||||
@utils.hook("self.message.channel",
|
@utils.hook("send.message.channel",
|
||||||
priority=EventManager.PRIORITY_MONITOR)
|
priority=EventManager.PRIORITY_MONITOR)
|
||||||
def self_channel_message(self, event):
|
def self_channel_message(self, event):
|
||||||
self._channel_message(event["server"].get_user(
|
self._channel_message(event["server"].get_user(
|
||||||
|
|
|
@ -201,7 +201,7 @@ class Server(IRCObject.Object):
|
||||||
def parse_data(self, line: str):
|
def parse_data(self, line: str):
|
||||||
if not line:
|
if not line:
|
||||||
return
|
return
|
||||||
self.events.on("raw").call_unsafe(server=self, line=line)
|
self.events.on("raw.received").call_unsafe(server=self, line=line)
|
||||||
self.check_users()
|
self.check_users()
|
||||||
def check_users(self):
|
def check_users(self):
|
||||||
for user in self.new_users:
|
for user in self.new_users:
|
||||||
|
@ -383,37 +383,11 @@ class Server(IRCObject.Object):
|
||||||
self.send("%sPRIVMSG %s :%s" % (self._tag_str(tags), target,
|
self.send("%sPRIVMSG %s :%s" % (self._tag_str(tags), target,
|
||||||
full_message))
|
full_message))
|
||||||
|
|
||||||
action = full_message.startswith("\01ACTION "
|
|
||||||
) and full_message.endswith("\01")
|
|
||||||
|
|
||||||
if action:
|
|
||||||
message = full_message.split("\01ACTION ", 1)[1][:-1]
|
|
||||||
|
|
||||||
full_message_split = full_message.split()
|
|
||||||
if target in self.channels:
|
|
||||||
channel = self.channels.get(target)
|
|
||||||
channel.buffer.add_message(None, message, action, tags, True)
|
|
||||||
self.events.on("self.message.channel").call(
|
|
||||||
message=full_message, message_split=full_message_split,
|
|
||||||
channel=channel, action=action, server=self)
|
|
||||||
else:
|
|
||||||
user = self.get_user(target)
|
|
||||||
user.buffer.add_message(None, message, action, tags, True)
|
|
||||||
self.events.on("self.message.private").call(
|
|
||||||
message=full_message, message_split=full_message_split,
|
|
||||||
user=user, action=action, server=self)
|
|
||||||
|
|
||||||
def send_notice(self, target: str, message: str, prefix: str=None,
|
def send_notice(self, target: str, message: str, prefix: str=None,
|
||||||
tags: dict={}):
|
tags: dict={}):
|
||||||
full_message = message if not prefix else prefix+message
|
full_message = message if not prefix else prefix+message
|
||||||
self.send("%sNOTICE %s :%s" % (self._tag_str(tags), target,
|
self.send("%sNOTICE %s :%s" % (self._tag_str(tags), target,
|
||||||
full_message))
|
full_message))
|
||||||
if target in self.channels:
|
|
||||||
self.channels.get(target).buffer.add_notice(None, message, tags,
|
|
||||||
True)
|
|
||||||
else:
|
|
||||||
self.get_user(target).buffer.add_notice(None, message, tags,
|
|
||||||
True)
|
|
||||||
|
|
||||||
def send_mode(self, target: str, mode: str=None, args: str=None):
|
def send_mode(self, target: str, mode: str=None, args: str=None):
|
||||||
self.send("MODE %s%s%s" % (target, "" if mode == None else " %s" % mode,
|
self.send("MODE %s%s%s" % (target, "" if mode == None else " %s" % mode,
|
||||||
|
|
Loading…
Reference in a new issue