Skip to content

Commit

Permalink
[shizmob#166] First Pass Implementation
Browse files Browse the repository at this point in the history
A basic lifting of the HalpyBOT List Handler (from @rik079) to Pydle
  • Loading branch information
Rixxan committed May 30, 2022
1 parent 30f8143 commit 53e14fa
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions pydle/features/rfc1459/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 53e14fa

Please sign in to comment.