Skip to content
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

monitor support fixes #144

Merged
merged 5 commits into from
Nov 22, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions pydle/features/ircv3/monitor.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
## monitor.py
# Online status monitoring support.
from . import cap
from .. import isupport


class MonitoringSupport(cap.CapabilityNegotiationSupport):
class MonitoringSupport(isupport.ISUPPORTSupport):
""" Support for monitoring the online/offline status of certain targets. """

## Internals.
Expand Down Expand Up @@ -36,19 +36,19 @@ def _destroy_user(self, nickname, channel=None, monitor_override=False):

## API.

def monitor(self, target):
async def monitor(self, target):
""" Start monitoring the online status of a user. Returns whether or not the server supports monitoring. """
if 'monitor-notify' in self._capabilities and not self.is_monitoring(target):
yield from self.rawmsg('MONITOR', '+', target)
if 'MONITOR' in self._isupport and not self.is_monitoring(target):
await self.rawmsg('MONITOR', '+', target)
self._monitoring.add(target)
return True
else:
return False

def unmonitor(self, target):
async def unmonitor(self, target):
""" Stop monitoring the online status of a user. Returns whether or not the server supports monitoring. """
if 'monitor-notify' in self._capabilities and self.is_monitoring(target):
yield from self.rawmsg('MONITOR', '-', target)
if 'MONITOR' in self._isupport and self.is_monitoring(target):
await self.rawmsg('MONITOR', '-', target)
self._monitoring.remove(target)
return True
else:
Expand Down Expand Up @@ -77,23 +77,33 @@ async def on_capability_monitor_notify_available(self, value):

async def on_raw_730(self, message):
""" Someone we are monitoring just came online. """
for nick in message.params[1].split(','):
self._create_user(nick)
for target in message.params[1].split(','):
nickname, metadata = self._parse_user(target)
self._sync_user(nickname, metadata)
await self.on_user_online(nickname)

async def on_raw_731(self, message):
""" Someone we are monitoring got offline. """
for nick in message.params[1].split(','):
self._destroy_user(nick, monitor_override=True)
for target in message.params[1].split(','):
nickname, metadata = self._parse_user(target)
# May be monitoring a user we haven't seen yet
if nickname in self.users:
self._destroy_user(nickname, monitor_override=True)
await self.on_user_offline(nickname)

async def on_raw_732(self, message):
""" List of users we're monitoring. """
self._monitoring.update(message.params[1].split(','))
for target in message.params[1].split(','):
nickname, metadata = self._parse_user(target)
self._monitoring.add(nickname)

on_raw_733 = cap.CapabilityNegotiationSupport._ignored # End of MONITOR list.
on_raw_733 = isupport.ISUPPORTSupport._ignored # End of MONITOR list.

async def on_raw_734(self, message):
""" Monitor list is full, can't add target. """
# Remove from monitoring list, not much else we can do.
self._monitoring.difference_update(message.params[1].split(','))
to_remove = set()
for target in message.params[1].split(','):
nickname, metadata = self._parse_user(target)
to_remove.add(nickname)
self._monitoring.difference_update(to_remove)
3 changes: 3 additions & 0 deletions pydle/features/isupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ async def on_isupport_modes(self, value):
""" Maximum number of variable modes to change in a single MODE command. """
self._mode_limit = int(value)

async def on_isupport_monitor(self, value):
self._monitor_limit = int(value)

async def on_isupport_namesx(self, value):
""" Let the server know we do in fact support NAMESX. Effectively the same as CAP multi-prefix. """
await self.rawmsg('PROTOCTL', 'NAMESX')
Expand Down