diff --git a/ircrobots/params.py b/ircrobots/params.py index 269687e..2462790 100644 --- a/ircrobots/params.py +++ b/ircrobots/params.py @@ -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) diff --git a/ircrobots/server.py b/ircrobots/server.py index 1623876..458ef70 100644 --- a/ircrobots/server.py +++ b/ircrobots/server.py @@ -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()