Add utils.irc.MessageTag and use it for both draft and ratified msgid

This commit is contained in:
jesopo 2019-05-14 13:02:45 +01:00
parent b75fc02c4b
commit 421d9c10c7
2 changed files with 10 additions and 1 deletions

View file

@ -7,6 +7,8 @@ COMMAND_METHODS = ["PRIVMSG", "NOTICE"]
REGEX_ARG_NUMBER = re.compile(r"\$(\d+)(-?)")
MSGID_TAG = utils.irc.MessageTag("msgid", "draft/msgid")
def _command_method_validate(s):
if s.upper() in COMMAND_METHODS:
return s.upper()
@ -133,7 +135,7 @@ class Module(ModuleManager.BaseModule):
if not module_name and hasattr(hook.function, "__self__"):
module_name = hook.function.__self__._name
msgid = event["tags"].get("draft/msgid", None)
msgid = MSGID_TAG.get_value(event["tags"])
statusmsg = "".join(event.get("statusmsg", []))
stdout = outs.StdOut(event["server"], module_name, target, msgid,
statusmsg)

View file

@ -295,3 +295,10 @@ class Capability(object):
callback()
def nak(self):
pass
def MessageTag(object):
def __init__(self, name, draft_name=None):
self._names = set([name, draft_name])
def get_value(self, tags: typing.Dict[str, str]) -> typing.Optional[str]:
key = list(set(tags.keys())&self._names)
return tags[key[0]] if key else None