From 8a0d99f9699b3cb27908fee0e485faf028d3e6fe Mon Sep 17 00:00:00 2001 From: jesopo Date: Fri, 21 Jun 2019 17:15:46 +0100 Subject: [PATCH] Adda system of aliases for CAPs, mostly for changeable draft specs and creating dependence between moving specs --- modules/ircv3_chathistory.py | 3 ++- modules/ircv3_labeled_responses.py | 3 ++- modules/ircv3_metadata.py | 2 +- modules/ircv3_multiline.py | 2 +- modules/ircv3_resume.py | 2 +- modules/line_handler/ircv3.py | 4 ++-- src/utils/irc/__init__.py | 7 +++++-- 7 files changed, 14 insertions(+), 9 deletions(-) diff --git a/modules/ircv3_chathistory.py b/modules/ircv3_chathistory.py index 27daad2b..e540673a 100644 --- a/modules/ircv3_chathistory.py +++ b/modules/ircv3_chathistory.py @@ -5,7 +5,8 @@ from src import ModuleManager, utils TAG = utils.irc.MessageTag("msgid", "draft/msgid") CHATHISTORY_BATCH = utils.irc.BatchType("chathistory") -EVENTPLAYBACK_CAP = utils.irc.Capability(None, "draft/event-playback") +EVENTPLAYBACK_CAP = utils.irc.Capability(None, "draft/event-playback", + alias="event-playback") HISTORY_BATCH = utils.irc.BatchType("history") @utils.export("cap", EVENTPLAYBACK_CAP) diff --git a/modules/ircv3_labeled_responses.py b/modules/ircv3_labeled_responses.py index 57cea4b6..1fde7b4a 100644 --- a/modules/ircv3_labeled_responses.py +++ b/modules/ircv3_labeled_responses.py @@ -1,7 +1,8 @@ import uuid from src import ModuleManager, utils -CAP = utils.irc.Capability(None, "draft/labeled-response-0.2") +CAP = utils.irc.Capability(None, "draft/labeled-response-0.2", + alias="labeled-response") TAG = utils.irc.MessageTag(None, "draft/label") BATCH = utils.irc.BatchType(None, "draft/labeled-response") diff --git a/modules/ircv3_metadata.py b/modules/ircv3_metadata.py index dd210d54..e0e6d387 100644 --- a/modules/ircv3_metadata.py +++ b/modules/ircv3_metadata.py @@ -1,6 +1,6 @@ from src import IRCBot, ModuleManager, utils -CAP = utils.irc.Capability(None, "draft/metadata") +CAP = utils.irc.Capability(None, "draft/metadata", alias="metadata") class Module(ModuleManager.BaseModule): @utils.hook("received.cap.new") diff --git a/modules/ircv3_multiline.py b/modules/ircv3_multiline.py index 357b99a3..11d07346 100644 --- a/modules/ircv3_multiline.py +++ b/modules/ircv3_multiline.py @@ -1,6 +1,6 @@ from src import ModuleManager, utils -CAP = utils.irc.Capability(None, "bitbot.dev/multiline") +CAP = utils.irc.Capability(None, "bitbot.dev/multiline", alias="multiline") BATCH = utils.irc.BatchType(None, "bitbot.dev/multiline") TAG = utils.irc.MessageTag(None, "+bitbot.dev/multiline-concat") diff --git a/modules/ircv3_resume.py b/modules/ircv3_resume.py index 1750e954..1d8e678c 100644 --- a/modules/ircv3_resume.py +++ b/modules/ircv3_resume.py @@ -2,7 +2,7 @@ from src import ModuleManager, utils -CAP = utils.irc.Capability(None, "draft/resume-0.5") +CAP = utils.irc.Capability(None, "draft/resume-0.5", alias="resume") class Module(ModuleManager.BaseModule): def _setting(self, new): diff --git a/modules/line_handler/ircv3.py b/modules/line_handler/ircv3.py index 23d14ed5..ceda7e4b 100644 --- a/modules/line_handler/ircv3.py +++ b/modules/line_handler/ircv3.py @@ -12,8 +12,8 @@ CAPABILITIES = [ utils.irc.Capability("message-tags", "draft/message-tags-0.2"), utils.irc.Capability("cap-notify"), utils.irc.Capability("batch"), - utils.irc.Capability(None, "draft/rename"), - utils.irc.Capability(None, "draft/setname") + utils.irc.Capability(None, "draft/rename", alias="rename"), + utils.irc.Capability(None, "draft/setname", alias="setname") ] def _cap_match(server, caps): diff --git a/src/utils/irc/__init__.py b/src/utils/irc/__init__.py index 13414ed3..c6dcbf0d 100644 --- a/src/utils/irc/__init__.py +++ b/src/utils/irc/__init__.py @@ -286,8 +286,11 @@ class IRCSendBatch(IRCBatch): return lines class Capability(object): - def __init__(self, name: typing.Optional[str], draft_name: str=None): - self._caps = set([name, draft_name]) + def __init__(self, ratified_name: typing.Optional[str], + draft_name: str=None, alias: str=None, + depends_on: typing.List[str]=None): + self.alias = alias or ratified_name + self._caps = set([ratified_name, draft_name]) self._on_ack_callbacks = [ ] # type: typing.List[typing.Callable[[], None]]