add very basic autojoin support
This commit is contained in:
parent
ce2338e4db
commit
cdad0895e1
2 changed files with 17 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
||||||
from typing import Optional
|
from typing import List, Optional
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass, field
|
||||||
|
|
||||||
class SASLParams(object):
|
class SASLParams(object):
|
||||||
mechanism: str
|
mechanism: str
|
||||||
|
@ -47,3 +47,5 @@ class ConnectionParams(object):
|
||||||
resume: Optional[ResumePolicy] = None
|
resume: Optional[ResumePolicy] = None
|
||||||
|
|
||||||
reconnect: int = 10 # seconds
|
reconnect: int = 10 # seconds
|
||||||
|
|
||||||
|
autojoin: List[str] = field(default_factory=list)
|
||||||
|
|
|
@ -170,6 +170,9 @@ class Server(IServer):
|
||||||
await self.send(build("WHO", [self.nickname]))
|
await self.send(build("WHO", [self.nickname]))
|
||||||
self.set_throttle(THROTTLE_RATE, THROTTLE_TIME)
|
self.set_throttle(THROTTLE_RATE, THROTTLE_TIME)
|
||||||
|
|
||||||
|
if self.params.autojoin:
|
||||||
|
await self._batch_joins(self.params.autojoin)
|
||||||
|
|
||||||
elif emit.command == "CAP":
|
elif emit.command == "CAP":
|
||||||
if emit.subcommand == "NEW":
|
if emit.subcommand == "NEW":
|
||||||
await self._cap_ls(emit)
|
await self._cap_ls(emit)
|
||||||
|
@ -190,6 +193,16 @@ class Server(IServer):
|
||||||
|
|
||||||
await self.line_read(line)
|
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):
|
async def _serial_who(self):
|
||||||
while self._pending_who:
|
while self._pending_who:
|
||||||
next = self._pending_who.popleft()
|
next = self._pending_who.popleft()
|
||||||
|
|
Loading…
Reference in a new issue