Add .assure()
to ParsedLine, to make it immune from .valid()
This commit is contained in:
parent
0fc03fd592
commit
6c5dc958d0
4 changed files with 27 additions and 12 deletions
|
@ -14,6 +14,10 @@ class Out(object):
|
||||||
self._text = ""
|
self._text = ""
|
||||||
self.written = False
|
self.written = False
|
||||||
self._tags = tags
|
self._tags = tags
|
||||||
|
self._assured = False
|
||||||
|
|
||||||
|
def assure(self):
|
||||||
|
self._assured = True
|
||||||
|
|
||||||
def write(self, text):
|
def write(self, text):
|
||||||
self._text += text
|
self._text += text
|
||||||
|
@ -27,15 +31,20 @@ class Out(object):
|
||||||
prefix = utils.consts.RESET + "[%s] " % self.prefix()
|
prefix = utils.consts.RESET + "[%s] " % self.prefix()
|
||||||
|
|
||||||
full_text = "%s%s" % (prefix, self._text)
|
full_text = "%s%s" % (prefix, self._text)
|
||||||
|
line_factory = None
|
||||||
if method == "PRIVMSG":
|
if method == "PRIVMSG":
|
||||||
line = self.server.send_message(self._target_str, full_text,
|
line_factory = utils.irc.protocol.privmsg
|
||||||
tags=self._tags)
|
|
||||||
elif method == "NOTICE":
|
elif method == "NOTICE":
|
||||||
line = self.server.send_notice(self._target_str, full_text,
|
line_factory = utils.irc.protocol.notice
|
||||||
tags=self._tags)
|
|
||||||
else:
|
else:
|
||||||
raise ValueError("Unknown command method '%s'" % method)
|
raise ValueError("Unknown command method '%s'" % method)
|
||||||
|
|
||||||
|
line = line_factory(self._target_str, full_text, tags=self._tags)
|
||||||
|
if self._assured:
|
||||||
|
line.assure()
|
||||||
|
sent_line = self.server.send(line)
|
||||||
|
|
||||||
|
if sent_line:
|
||||||
line.truncate_marker = STR_MORE
|
line.truncate_marker = STR_MORE
|
||||||
if line.truncated():
|
if line.truncated():
|
||||||
self._text = "%s%s" % (STR_CONTINUED, line.truncated())
|
self._text = "%s%s" % (STR_CONTINUED, line.truncated())
|
||||||
|
|
|
@ -47,6 +47,7 @@ class ParsedLine(object):
|
||||||
self.source = source
|
self.source = source
|
||||||
self.tags = {} if tags == None else tags
|
self.tags = {} if tags == None else tags
|
||||||
self._valid = True
|
self._valid = True
|
||||||
|
self._assured = False
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "ParsedLine(%s)" % self.__str__()
|
return "ParsedLine(%s)" % self.__str__()
|
||||||
|
@ -58,6 +59,11 @@ class ParsedLine(object):
|
||||||
def invalidate(self):
|
def invalidate(self):
|
||||||
self._valid = False
|
self._valid = False
|
||||||
|
|
||||||
|
def assured(self) -> bool:
|
||||||
|
return self._assured
|
||||||
|
def assure(self):
|
||||||
|
self._assured = True
|
||||||
|
|
||||||
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():
|
||||||
|
|
|
@ -268,7 +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():
|
if line_parsed.valid() or line_parsed.assured():
|
||||||
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)
|
||||||
|
@ -352,7 +352,7 @@ class Server(IRCObject.Object):
|
||||||
|
|
||||||
def send_message(self, target: str, message: str, tags: dict={}
|
def send_message(self, target: str, message: str, tags: dict={}
|
||||||
) -> IRCLine.SentLine:
|
) -> IRCLine.SentLine:
|
||||||
return self.send(utils.irc.protocol.message(target, message, tags))
|
return self.send(utils.irc.protocol.privmsg(target, message, tags))
|
||||||
|
|
||||||
def send_notice(self, target: str, message: str, tags: dict={}
|
def send_notice(self, target: str, message: str, tags: dict={}
|
||||||
) -> IRCLine.SentLine:
|
) -> IRCLine.SentLine:
|
||||||
|
|
|
@ -33,7 +33,7 @@ def part(channel_name: str, reason: str=None) -> IRCLine.ParsedLine:
|
||||||
def quit(reason: str=None) -> IRCLine.ParsedLine:
|
def quit(reason: str=None) -> IRCLine.ParsedLine:
|
||||||
return IRCLine.ParsedLine("QUIT", [reason] if reason else [])
|
return IRCLine.ParsedLine("QUIT", [reason] if reason else [])
|
||||||
|
|
||||||
def message(target: str, message: str, tags: typing.Dict[str, str]={}
|
def privmsg(target: str, message: str, tags: typing.Dict[str, str]={}
|
||||||
) -> IRCLine.ParsedLine:
|
) -> IRCLine.ParsedLine:
|
||||||
return IRCLine.ParsedLine("PRIVMSG", [target, message], tags=tags)
|
return IRCLine.ParsedLine("PRIVMSG", [target, message], tags=tags)
|
||||||
def notice(target: str, message: str, tags: typing.Dict[str, str]={}
|
def notice(target: str, message: str, tags: typing.Dict[str, str]={}
|
||||||
|
|
Loading…
Reference in a new issue