Don't enable write throttling until we get 005

This commit is contained in:
jesopo 2018-11-19 10:12:52 +00:00
parent 9cdc37ce72
commit 5d813175a1
2 changed files with 5 additions and 1 deletions

View file

@ -65,6 +65,7 @@ class Module(ModuleManager.BaseModule):
# first numeric line the server sends
@utils.hook("raw.received.001", default_event=True)
def handle_001(self, event):
event["server"].set_write_throttling(True)
event["server"].name = event["prefix"].nickname
event["server"].set_own_nickname(event["args"][0])
event["server"].send_whois(event["server"].nickname)

View file

@ -30,6 +30,7 @@ class Server(IRCObject.Object):
self.write_buffer = b""
self.buffered_lines = [] # type: typing.List[bytes]
self._write_throttling = False
self.read_buffer = b""
self.recent_sends = [] # type: typing.List[float]
self.cached_fileno = None # type: typing.Optional[int]
@ -290,7 +291,7 @@ class Server(IRCObject.Object):
def throttle_done(self):
return self.send_throttle_timeout() == 0
def send_throttle_timeout(self):
if len(self.write_buffer):
if len(self.write_buffer) or not self._write_throttling:
return 0
now = time.monotonic()
@ -307,6 +308,8 @@ class Server(IRCObject.Object):
time_left = self.recent_sends[0]+THROTTLE_SECONDS
time_left = time_left-now
return time_left
def set_write_throttling(self, is_on: bool):
self._write_throttling = is_on
def send_user(self, username: str, realname: str):
self.send("USER %s 0 * :%s" % (username, realname))