2019-02-10 14:18:33 +00:00
|
|
|
import datetime, typing
|
2019-02-10 18:43:04 +00:00
|
|
|
from src import IRCObject, utils
|
|
|
|
|
|
|
|
LINE_CUTOFF = 450
|
2019-02-10 14:18:33 +00:00
|
|
|
|
|
|
|
class Line(IRCObject.Object):
|
2019-02-10 18:43:04 +00:00
|
|
|
def __init__(self, send_time: datetime.datetime, line: str):
|
|
|
|
self._line = line
|
2019-02-10 14:18:33 +00:00
|
|
|
self.send_time = send_time
|
2019-02-10 18:43:04 +00:00
|
|
|
|
|
|
|
data, truncated = utils.encode_truncate(line, "utf8", LINE_CUTOFF)
|
|
|
|
|
|
|
|
self._data = data
|
|
|
|
self._truncated = truncated
|
2019-02-10 14:18:33 +00:00
|
|
|
|
|
|
|
self._on_send = [] # type: typing.List[typing.Callable[[], None]]
|
|
|
|
|
|
|
|
def __repr__(self) -> str:
|
|
|
|
return "IRCLine.Line(%s)" % self.__str__()
|
|
|
|
def __str__(self) -> str:
|
2019-02-10 18:43:04 +00:00
|
|
|
return self._data
|
2019-02-10 14:18:33 +00:00
|
|
|
|
|
|
|
def on_send(self, func: typing.Callable[[], None]):
|
|
|
|
self._on_send.append(func)
|
|
|
|
def sent(self):
|
|
|
|
for func in self._on_send[:]:
|
|
|
|
func()
|
2019-02-10 18:43:04 +00:00
|
|
|
|
|
|
|
def data(self) -> bytes:
|
|
|
|
return b"%s\r\n" % self._data
|