Remove IRCSendBatch, fix some batch-related type hints

This commit is contained in:
jesopo 2019-06-02 10:13:51 +01:00
parent ccf863a8a7
commit f9f637e084
3 changed files with 8 additions and 27 deletions

View file

@ -21,7 +21,7 @@ class Module(ModuleManager.BaseModule):
def handle_raw(self, event):
if ("batch" in event["line"].tags and
event["line"].tags["batch"] in event["server"].batches):
event["server"].batches[event["line"].tags["batch"]].lines.append(
event["server"].batches[event["line"].tags["batch"]].add_line(
event["line"])
else:
self._handle(event["server"], event["line"])
@ -182,8 +182,7 @@ class Module(ModuleManager.BaseModule):
if modifier == "+":
batch_type = event["args"][1]
batch = utils.irc.IRCRecvBatch(identifier, batch_type,
event["tags"])
batch = utils.irc.IRCBatch(identifier, batch_type, event["tags"])
event["server"].batches[identifier] = batch
self.events.on("received.batch.start").call(batch=batch,

View file

@ -31,7 +31,7 @@ class Server(IRCObject.Object):
self._capabilities_waiting = set([]) # type: typing.Set[str]
self.agreed_capabilities = set([]) # type: typing.Set[str]
self.server_capabilities = {} # type: typing.Dict[str, str]
self.batches = {} # type: typing.Dict[str, IRCLine.ParsedLine]
self.batches = {} # type: typing.Dict[str, utils.irc.IRCBatch]
self.cap_started = False
self.users = {} # type: typing.Dict[str, IRCUser.User]
@ -362,15 +362,3 @@ class Server(IRCObject.Object):
def send_whox(self, mask: str, filter: str, fields: str, label: str=None
) -> IRCLine.SentLine:
return self.send(utils.irc.protocol.whox(mask, filter, fields, label))
def make_batch(self, identifier: str, batch_type: str,
tags: typing.Dict[str, str]={}) -> utils.irc.IRCSendBatch:
return utils.irc.IRCSendBatch(identifier, batch_type, tags)
def send_batch(self, batch: utils.irc.IRCSendBatch) -> IRCLine.SentLine:
self.send(utils.irc.protocol.batch_start(batch.id, batch.type,
batch.tags))
for line in batch.lines:
self.send(line)
return self.send(utils.irc.protocol.batch_end(batch.id))

View file

@ -263,17 +263,11 @@ class IRCBatch(object):
self.id = identifier
self.type = batch_type
self.tags = tags
self.lines = [] # type: typing.List[IRCLine.ParsedLine]
class IRCRecvBatch(IRCBatch):
pass
class IRCSendBatch(IRCBatch):
def _add_line(self, line: IRCLine.ParsedLine):
line.tags["batch"] = self.id
self.lines.append(line)
def message(self, target: str, message: str, tags: dict={}):
self._add_line(utils.irc.protocol.message(target, message, tags))
def notice(self, target: str, message: str, tags: dict={}):
self._add_line(utils.irc.protocol.notice(target, message, tags))
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 Capability(object):
def __init__(self, name, draft_name=None):