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.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():
|
||||
|
|
|
@ -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,6 +268,7 @@ class Server(IRCObject.Object):
|
|||
self.events.on("preprocess.send").call_unsafe(server=self,
|
||||
line=line_parsed, events=line_events)
|
||||
|
||||
if line_parsed.valid():
|
||||
line = line_parsed.format()
|
||||
line_obj = IRCLine.SentLine(line_events, datetime.datetime.utcnow(),
|
||||
self.hostmask(), line_parsed)
|
||||
|
@ -276,6 +278,7 @@ class Server(IRCObject.Object):
|
|||
self.bot.trigger_write()
|
||||
|
||||
return line_obj
|
||||
return None
|
||||
def send_raw(self, line: str):
|
||||
return self.send(utils.irc.parse_line(line))
|
||||
|
||||
|
|
Loading…
Reference in a new issue