Add an export for IRCv3 CAPs

This commit is contained in:
jesopo 2019-06-20 16:52:23 +01:00
parent 8797be9457
commit 24cdff9e44
6 changed files with 9 additions and 22 deletions

View file

@ -8,12 +8,8 @@ CHATHISTORY_BATCH = utils.irc.BatchType("chathistory")
EVENTPLAYBACK_CAP = utils.irc.Capability(None, "draft/event-playback")
HISTORY_BATCH = utils.irc.BatchType("history")
@utils.export("cap", EVENTPLAYBACK_CAP)
class Module(ModuleManager.BaseModule):
@utils.hook("received.cap.ls")
@utils.hook("received.cap.new")
def on_cap(self, event):
return EVENTPLAYBACK_CAP.copy()
@utils.hook("received.batch.end")
def batch_end(self, event):
if (CHATHISTORY_BATCH.match(event["batch"].type) or

View file

@ -15,16 +15,12 @@ class WaitingForLabel(object):
self.events = events
self.labels_since = 0
@utils.export("cap", CAP)
class Module(ModuleManager.BaseModule):
@utils.hook("new.server")
def new_server(self, event):
event["server"]._label_cache = {}
@utils.hook("received.cap.ls")
@utils.hook("received.cap.new")
def on_cap(self, event):
return CAP.copy()
@utils.hook("preprocess.send")
def raw_send(self, event):
available_cap = event["server"].available_capability(CAP)

View file

@ -4,12 +4,8 @@ CAP = utils.irc.Capability(None, "bitbot.dev/multiline")
BATCH = utils.irc.BatchType(None, "bitbot.dev/multiline")
TAG = utils.irc.MessageTag(None, "+bitbot.dev/multiline-concat")
@utils.export("cap", CAP)
class Module(ModuleManager.BaseModule):
@utils.hook("received.cap.ls")
@utils.hook("received.cap.new")
def on_cap(self, event):
return CAP.copy()
@utils.hook("preprocess.send.privmsg")
def preprocess_send_privmsg(self, event):
if len(event["line"].args) > 1:

View file

@ -3,12 +3,8 @@ from src import ModuleManager, utils
CAP = utils.irc.Capability("server-time")
TAG = utils.irc.MessageTag("time")
@utils.export("cap", CAP)
class Module(ModuleManager.BaseModule):
@utils.hook("received.cap.ls")
@utils.hook("received.cap.new")
def on_cap(self, event):
return CAP.copy()
@utils.hook("raw.received")
def raw_recv(self, event):
server_time = TAG.get_value(event["line"].tags)

View file

@ -133,7 +133,7 @@ class Module(ModuleManager.BaseModule):
# the server is telling us about its capabilities!
@utils.hook("raw.received.cap")
def cap(self, event):
ircv3.cap(self.events, event)
ircv3.cap(self.exports, self.events, event)
# the server is asking for authentication
@utils.hook("raw.received.authenticate")

View file

@ -27,7 +27,7 @@ def _cap_match(server, caps):
matched_caps[available] = cap
return matched_caps
def cap(events, event):
def cap(exports, events, event):
capabilities = utils.parse.keyvalue(event["args"][-1])
subcommand = event["args"][1].upper()
is_multiline = len(event["args"]) > 3 and event["args"][2] == "*"
@ -50,6 +50,9 @@ def cap(events, event):
server_caps = list(event["server"].server_capabilities.keys())
all_caps = CAPABILITIES[:]
export_caps = [cap.copy() for cap in exports.get_all("cap")]
all_caps.extend(export_caps)
module_caps = events.on("received.cap.ls").call(
capabilities=event["server"].server_capabilities,
server=event["server"])