2019-02-22 11:23:36 +00:00
|
|
|
from src import utils
|
|
|
|
|
2019-05-11 14:11:09 +00:00
|
|
|
CAPABILITIES = [
|
|
|
|
utils.irc.Capability("multi-prefix"),
|
|
|
|
utils.irc.Capability("chghost"),
|
|
|
|
utils.irc.Capability("invite-notify"),
|
|
|
|
utils.irc.Capability("account-tag"),
|
|
|
|
utils.irc.Capability("account-notify"),
|
|
|
|
utils.irc.Capability("extended-join"),
|
|
|
|
utils.irc.Capability("away-notify"),
|
|
|
|
utils.irc.Capability("userhost-in-names"),
|
|
|
|
utils.irc.Capability("message-tags", "draft/message-tags-0.2"),
|
|
|
|
utils.irc.Capability("server-time"),
|
|
|
|
utils.irc.Capability("cap-notify"),
|
|
|
|
utils.irc.Capability("batch"),
|
|
|
|
utils.irc.Capability("echo-message"),
|
|
|
|
utils.irc.Capability(None, "draft/labeled-response"),
|
|
|
|
utils.irc.Capability(None, "draft/rename"),
|
|
|
|
utils.irc.Capability(None, "draft/setname")
|
|
|
|
]
|
2019-02-22 11:23:36 +00:00
|
|
|
|
2019-05-11 17:22:40 +00:00
|
|
|
def _match_caps(our_capabilities, offered_capabilities):
|
|
|
|
matched = {}
|
|
|
|
for capability in our_capabilities:
|
|
|
|
available = capability.available(offered_capabilities)
|
2019-05-11 14:11:09 +00:00
|
|
|
if available:
|
2019-05-11 17:22:40 +00:00
|
|
|
matched[available] = capability
|
2019-05-11 14:11:09 +00:00
|
|
|
return matched
|
2019-02-22 11:23:36 +00:00
|
|
|
|
2019-05-11 17:22:40 +00:00
|
|
|
def _caps_offered(server, caps):
|
|
|
|
blacklist = server.get_setting("blacklisted-caps", [])
|
|
|
|
for cap_name, cap in caps.items():
|
|
|
|
if not cap_name in blacklist:
|
|
|
|
server.capability_queue[cap_name] = cap
|
|
|
|
|
2019-02-22 11:23:36 +00:00
|
|
|
def cap(events, event):
|
|
|
|
capabilities = utils.parse.keyvalue(event["args"][-1])
|
2019-05-18 13:57:09 +00:00
|
|
|
subcommand = event["args"][1].upper()
|
2019-02-22 11:23:36 +00:00
|
|
|
is_multiline = len(event["args"]) > 3 and event["args"][2] == "*"
|
|
|
|
|
2019-05-18 13:57:09 +00:00
|
|
|
if subcommand == "LS":
|
2019-02-22 11:23:36 +00:00
|
|
|
event["server"].cap_started = True
|
|
|
|
event["server"].server_capabilities.update(capabilities)
|
|
|
|
if not is_multiline:
|
2019-05-11 17:22:40 +00:00
|
|
|
server_caps = list(event["server"].server_capabilities.keys())
|
|
|
|
matched_caps = _match_caps(CAPABILITIES, server_caps)
|
2019-02-22 11:23:36 +00:00
|
|
|
|
2019-05-11 17:22:40 +00:00
|
|
|
module_caps = events.on("received.cap.ls").call(
|
2019-02-22 11:23:36 +00:00
|
|
|
capabilities=event["server"].server_capabilities,
|
|
|
|
server=event["server"])
|
2019-05-11 17:22:40 +00:00
|
|
|
module_caps = list(filter(None, module_caps))
|
|
|
|
matched_caps.update(_match_caps(module_caps, server_caps))
|
|
|
|
|
|
|
|
_caps_offered(event["server"], matched_caps)
|
2019-02-22 11:23:36 +00:00
|
|
|
|
2019-05-11 17:22:40 +00:00
|
|
|
if event["server"].capability_queue:
|
2019-02-22 11:23:36 +00:00
|
|
|
event["server"].send_capability_queue()
|
|
|
|
else:
|
|
|
|
event["server"].send_capability_end()
|
2019-05-18 13:57:09 +00:00
|
|
|
elif subcommand == "NEW":
|
2019-02-22 11:23:36 +00:00
|
|
|
capabilities_keys = capabilities.keys()
|
|
|
|
event["server"].server_capabilities.update(capabilities)
|
|
|
|
|
2019-05-24 04:47:01 +00:00
|
|
|
matched_caps = _match_caps(CAPABILITIES, list(capabilities_keys))
|
2019-02-22 11:23:36 +00:00
|
|
|
|
2019-05-11 17:22:40 +00:00
|
|
|
module_caps = events.on("received.cap.new").call(
|
|
|
|
server=event["server"], capabilities=capabilities)
|
|
|
|
module_caps = list(filter(None, module_caps))
|
|
|
|
matched_caps.update(_match_caps(module_caps, capabilities_keys))
|
|
|
|
|
|
|
|
_caps_offered(event["server"], matched_caps)
|
2019-02-22 11:23:36 +00:00
|
|
|
|
2019-05-11 17:22:40 +00:00
|
|
|
if event["server"].capability_queue:
|
2019-02-22 11:23:36 +00:00
|
|
|
event["server"].send_capability_queue()
|
2019-05-18 13:57:09 +00:00
|
|
|
elif subcommand == "DEL":
|
2019-02-22 11:23:36 +00:00
|
|
|
for capability in capabilities.keys():
|
|
|
|
event["server"].agreed_capabilities.discard(capability)
|
|
|
|
del event["server"].server_capabilities[capability]
|
|
|
|
|
|
|
|
events.on("received.cap.del").call(server=event["server"],
|
|
|
|
capabilities=capabilities)
|
2019-05-18 13:57:09 +00:00
|
|
|
elif subcommand == "ACK":
|
2019-02-22 11:23:36 +00:00
|
|
|
event["server"].agreed_capabilities.update(capabilities)
|
|
|
|
events.on("received.cap.ack").call(capabilities=capabilities,
|
|
|
|
server=event["server"])
|
|
|
|
|
2019-05-18 13:57:09 +00:00
|
|
|
if subcommand == "ACK" or subcommand == "NAK":
|
|
|
|
ack = subcommand == "ACK"
|
2019-02-22 11:23:36 +00:00
|
|
|
for capability in capabilities:
|
2019-05-11 17:22:40 +00:00
|
|
|
cap_obj = event["server"].capability_queue[capability]
|
|
|
|
del event["server"].capability_queue[capability]
|
|
|
|
if ack:
|
|
|
|
cap_obj.ack()
|
|
|
|
else:
|
|
|
|
cap_obj.nak()
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
if (event["server"].cap_started and
|
2019-05-11 17:22:40 +00:00
|
|
|
not event["server"].capability_queue and
|
2019-02-22 11:23:36 +00:00
|
|
|
not event["server"].waiting_for_capabilities()):
|
|
|
|
event["server"].cap_started = False
|
|
|
|
event["server"].send_capability_end()
|
|
|
|
|
|
|
|
def authenticate(events, event):
|
|
|
|
events.on("received.authenticate").call(message=event["args"][0],
|
|
|
|
server=event["server"])
|