diff --git a/pydle/features/rfc1459/client.py b/pydle/features/rfc1459/client.py index 48581d1..362dedb 100644 --- a/pydle/features/rfc1459/client.py +++ b/pydle/features/rfc1459/client.py @@ -7,12 +7,34 @@ from pydle.client import BasicClient, NotInChannel, AlreadyInChannel from . import parsing, protocol +from typing import List, Optional +import asyncio class RFC1459Support(BasicClient): """ Basic RFC1459 client. """ DEFAULT_QUIT_MESSAGE = 'Quitting' + def __init__( + self, + nickname: str = "HalpyLISTener", + fallback: Optional[List] = None, + username=None, + realname=None, + eventloop=None, + **kwargs, + ): + super().__init__( + nickname, + fallback if fallback is not None else [], + username, + realname, + eventloop, + **kwargs, + ) + self._pending_query = asyncio.Queue() + self._channellist = set() + ## Internals. def _reset_attributes(self): @@ -869,6 +891,31 @@ async def on_raw_319(self, message): if nickname in self._pending['whois']: self._whois_info[nickname].update(info) + async def all_channels(self) -> List[str]: + await self.rawmsg("LIST") + # Create future + future = asyncio.get_event_loop().create_future() + await self._pending_query.put(future) + try: + channels = await future + return list(channels) + except asyncio.CancelledError: + # We don't care if it's cancelled as this should only happen on shutdown + pass + + async def on_raw_321(self, *args): + # Results incoming, empty channel list + self._channellist.clear() + + async def on_raw_322(self, message): + # Called by Pydle when we get a new channel, add to list + self._channellist.add(message.params[1]) + + async def on_raw_323(self, *args): + # Set results + future = await self._pending_query.get() + future.set_result(self._channellist) + async def on_raw_324(self, message): """ Channel mode. """ target, channel = message.params[:2]