-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#166] Add LIST Support #172
base: develop
Are you sure you want to change the base?
Changes from all commits
7d4852f
c8e500f
c88ba07
5fab2b8
0223667
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
import datetime | ||
import ipaddress | ||
import itertools | ||
|
||
import asyncio | ||
from pydle.client import BasicClient, NotInChannel, AlreadyInChannel | ||
from . import parsing, protocol | ||
|
||
|
@@ -59,6 +59,24 @@ def _reset_attributes(self): | |
self.channels = parsing.NormalizingDict(self.channels, case_mapping=self._case_mapping) | ||
self.users = parsing.NormalizingDict(self.users, case_mapping=self._case_mapping) | ||
|
||
# List. | ||
self.all_channels = [] | ||
self._list_client = [] | ||
self._list_channel = [] | ||
self._list_count = [] | ||
self._list_topic = [] | ||
self._list_query = asyncio.Queue() | ||
|
||
async def channel_list(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing return type annotation. |
||
await self.rawmsg("LIST") | ||
future = asyncio.get_running_loop().create_future() | ||
await self._list_query.put(future) | ||
Comment on lines
+71
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This future should be enqueued prior to emitting the |
||
try: | ||
await future | ||
return self.all_channels | ||
except asyncio.CancelledError: | ||
pass | ||
Comment on lines
+77
to
+78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should likely propagate up the cancellation error, right now it unexpectedly returns |
||
|
||
def _reset_connection_attributes(self): | ||
super()._reset_connection_attributes() | ||
self.password = None | ||
|
@@ -869,6 +887,41 @@ async def on_raw_319(self, message): | |
if nickname in self._pending['whois']: | ||
self._whois_info[nickname].update(info) | ||
|
||
async def on_raw_321(self, message): | ||
"""RPL_LISTSTART, an OPTIONAL indication a LIST is starting.""" | ||
... | ||
|
||
async def on_raw_322(self, message): | ||
"""RPL_LIST, the list of channels from the server""" | ||
# The * channel doesn't exist but some IRCds return * as the server itself. | ||
if message.params[1] != "*": | ||
self._list_client.append(message.params[0]) | ||
self._list_channel.append(message.params[1]) | ||
self._list_count.append(message.params[2]) | ||
self._list_topic.append(message.params[3]) | ||
|
||
async def on_raw_323(self, message): | ||
"""RPL_LISTEND, end of the channel list""" | ||
self.all_channels = [] | ||
|
||
for counter, channel in enumerate(self._list_channel): | ||
channel_dict = { | ||
"client": self._list_client[counter], | ||
"channel": self._list_channel[counter], | ||
"client_count": self._list_count[counter], | ||
"topic": self._list_topic[counter], | ||
} | ||
self.all_channels.append(channel_dict) | ||
|
||
# Clear the supporting lists | ||
self._list_client.clear() | ||
self._list_channel.clear() | ||
self._list_count.clear() | ||
self._list_topic.clear() | ||
if not self._list_query.empty(): | ||
future = await self._list_query.get() | ||
future.set_result(self.all_channels) | ||
|
||
async def on_raw_324(self, message): | ||
""" Channel mode. """ | ||
target, channel = message.params[:2] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should get some type annotations.