bitbot-3.11-fork/src/IRCLine.py

31 lines
823 B
Python
Raw Normal View History

2019-02-10 14:18:33 +00:00
import datetime, typing
from src import IRCObject, utils
LINE_CUTOFF = 450
2019-02-10 14:18:33 +00:00
class Line(IRCObject.Object):
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
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:
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()
def data(self) -> bytes:
return b"%s\r\n" % self._data