diff --git a/src/IRCLine.py b/src/IRCLine.py index e22a79ad..9e1d85fb 100644 --- a/src/IRCLine.py +++ b/src/IRCLine.py @@ -46,12 +46,18 @@ class ParsedLine(object): self.args = IRCArgs(args) self.source = source self.tags = {} if tags == None else tags + self._valid = True def __repr__(self): return "ParsedLine(%s)" % self.__str__() def __str__(self): return self.format() + def valid(self) -> bool: + return self._valid + def invalidate(self): + self._valid = False + def _tag_str(self, tags: typing.Dict[str, str]) -> str: tag_pieces = [] for tag, value in tags.items(): diff --git a/src/IRCServer.py b/src/IRCServer.py index 39d0817b..a5c4c34c 100644 --- a/src/IRCServer.py +++ b/src/IRCServer.py @@ -256,7 +256,8 @@ class Server(IRCObject.Object): self.events.on("raw.send").call_unsafe(server=self, line=line.parsed_line) - def send(self, line_parsed: IRCLine.ParsedLine, immediate: bool=False): + def send(self, line_parsed: IRCLine.ParsedLine, immediate: bool=False + ) -> typing.Optional[IRCLine.SentLine]: if not self.send_enabled: return None @@ -267,15 +268,17 @@ class Server(IRCObject.Object): self.events.on("preprocess.send").call_unsafe(server=self, line=line_parsed, events=line_events) - line = line_parsed.format() - line_obj = IRCLine.SentLine(line_events, datetime.datetime.utcnow(), - self.hostmask(), line_parsed) - self.socket.send(line_obj, immediate=immediate) + if line_parsed.valid(): + line = line_parsed.format() + line_obj = IRCLine.SentLine(line_events, datetime.datetime.utcnow(), + self.hostmask(), line_parsed) + self.socket.send(line_obj, immediate=immediate) - if immediate: - self.bot.trigger_write() + if immediate: + self.bot.trigger_write() - return line_obj + return line_obj + return None def send_raw(self, line: str): return self.send(utils.irc.parse_line(line))