Allow preprocess.send callbacks to request a line not be sent at all
This commit is contained in:
parent
512d844a5a
commit
0fc03fd592
2 changed files with 17 additions and 8 deletions
|
@ -46,12 +46,18 @@ class ParsedLine(object):
|
||||||
self.args = IRCArgs(args)
|
self.args = IRCArgs(args)
|
||||||
self.source = source
|
self.source = source
|
||||||
self.tags = {} if tags == None else tags
|
self.tags = {} if tags == None else tags
|
||||||
|
self._valid = True
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "ParsedLine(%s)" % self.__str__()
|
return "ParsedLine(%s)" % self.__str__()
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.format()
|
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:
|
def _tag_str(self, tags: typing.Dict[str, str]) -> str:
|
||||||
tag_pieces = []
|
tag_pieces = []
|
||||||
for tag, value in tags.items():
|
for tag, value in tags.items():
|
||||||
|
|
|
@ -256,7 +256,8 @@ class Server(IRCObject.Object):
|
||||||
self.events.on("raw.send").call_unsafe(server=self,
|
self.events.on("raw.send").call_unsafe(server=self,
|
||||||
line=line.parsed_line)
|
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:
|
if not self.send_enabled:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -267,6 +268,7 @@ class Server(IRCObject.Object):
|
||||||
self.events.on("preprocess.send").call_unsafe(server=self,
|
self.events.on("preprocess.send").call_unsafe(server=self,
|
||||||
line=line_parsed, events=line_events)
|
line=line_parsed, events=line_events)
|
||||||
|
|
||||||
|
if line_parsed.valid():
|
||||||
line = line_parsed.format()
|
line = line_parsed.format()
|
||||||
line_obj = IRCLine.SentLine(line_events, datetime.datetime.utcnow(),
|
line_obj = IRCLine.SentLine(line_events, datetime.datetime.utcnow(),
|
||||||
self.hostmask(), line_parsed)
|
self.hostmask(), line_parsed)
|
||||||
|
@ -276,6 +278,7 @@ class Server(IRCObject.Object):
|
||||||
self.bot.trigger_write()
|
self.bot.trigger_write()
|
||||||
|
|
||||||
return line_obj
|
return line_obj
|
||||||
|
return None
|
||||||
def send_raw(self, line: str):
|
def send_raw(self, line: str):
|
||||||
return self.send(utils.irc.parse_line(line))
|
return self.send(utils.irc.parse_line(line))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue