aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jesopo2019-06-16 09:52:54 +0100
committerGravatar jesopo2019-06-16 09:52:54 +0100
commit919a488e86c16a05adca0c97a293a4f9acb1dd95 (patch)
treed5e538e079da24db50bbeb50c638ec2a66dbca8c
parentType annotate ParsedLine.tags, add ParsedLine.add_tag() (diff)
signature
Implement client-to-server BATCHes
-rw-r--r--src/utils/irc/__init__.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/utils/irc/__init__.py b/src/utils/irc/__init__.py
index c9b50c6c..f05e5e57 100644
--- a/src/utils/irc/__init__.py
+++ b/src/utils/irc/__init__.py
@@ -1,4 +1,4 @@
-import fnmatch, json, string, re, typing
+import fnmatch, json, string, re, typing, uuid
from src import IRCLine, utils
from . import protocol
@@ -259,17 +259,32 @@ def parse_ctcp(s: str) -> typing.Optional[CTCPMessage]:
class IRCBatch(object):
def __init__(self, identifier: str, batch_type: str, args: typing.List[str],
- tags: typing.Dict[str, str]={}):
+ tags: typing.Dict[str, str]=None):
self.identifier = identifier
self.type = batch_type
self.args = args
- self.tags = tags
+ self.tags = tags or {}
self._lines = [] # type: typing.List[IRCLine.ParsedLine]
def add_line(self, line: IRCLine.ParsedLine):
self._lines.append(line)
def get_lines(self) -> typing.List[IRCLine.ParsedLine]:
return self._lines
+class IRCSendBatch(IRCBatch):
+ def __init__(self, batch_type: str, args: typing.List[str],
+ tags: typing.Dict[str, str]=None):
+ IRCBatch.__init__(self, str(uuid.uuid4()), batch_type, args, tags)
+ def get_lines(self) -> typing.List[IRCLine.ParsedLine]:
+ lines = []
+ for line in self._lines:
+ line.add_tag("batch", self.identifier)
+ lines.append(line)
+
+ lines.insert(0, IRCLine.ParsedLine("BATCH",
+ ["+%s" % self.identifier, self.type]))
+ lines.append(IRCLine.ParsedLine("BATCH", ["-%s" % self.identifier]))
+ return lines
+
class Capability(object):
def __init__(self, name: typing.Optional[str], draft_name: str=None):
self._caps = set([name, draft_name])