add very basic autojoin support

This commit is contained in:
jesopo 2020-09-25 18:03:02 +00:00
parent ce2338e4db
commit cdad0895e1
2 changed files with 17 additions and 2 deletions

View File

@ -1,5 +1,5 @@
from typing import Optional
from dataclasses import dataclass
from typing import List, Optional
from dataclasses import dataclass, field
class SASLParams(object):
mechanism: str
@ -47,3 +47,5 @@ class ConnectionParams(object):
resume: Optional[ResumePolicy] = None
reconnect: int = 10 # seconds
autojoin: List[str] = field(default_factory=list)

View File

@ -170,6 +170,9 @@ class Server(IServer):
await self.send(build("WHO", [self.nickname]))
self.set_throttle(THROTTLE_RATE, THROTTLE_TIME)
if self.params.autojoin:
await self._batch_joins(self.params.autojoin)
elif emit.command == "CAP":
if emit.subcommand == "NEW":
await self._cap_ls(emit)
@ -190,6 +193,16 @@ class Server(IServer):
await self.line_read(line)
async def _batch_joins(self,
channels: List[str],
batch_n: int=10):
#TODO: do as many JOINs in one line as we can fit
#TODO: channel keys
for i in range(0, len(channels), batch_n):
batch = channels[i:i+batch_n]
await self.send(build("JOIN", [",".join(batch)]))
async def _serial_who(self):
while self._pending_who:
next = self._pending_who.popleft()