Skip to content

Commit b4a5641

Browse files
authored
Merge pull request #144 from ZeroKnight/fix-143
`monitor` support fixes
2 parents 4ec52da + 339b3c0 commit b4a5641

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

pydle/features/ircv3/monitor.py

+27-19
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
## monitor.py
22
# Online status monitoring support.
3-
from . import cap
3+
from .. import isupport
44

55

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

99
## Internals.
@@ -36,23 +36,21 @@ def _destroy_user(self, nickname, channel=None, monitor_override=False):
3636

3737
## API.
3838

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

48-
def unmonitor(self, target):
47+
async def unmonitor(self, target):
4948
""" Stop monitoring the online status of a user. Returns whether or not the server supports monitoring. """
50-
if 'monitor-notify' in self._capabilities and self.is_monitoring(target):
51-
yield from self.rawmsg('MONITOR', '-', target)
49+
if 'MONITOR' in self._isupport and self.is_monitoring(target):
50+
await self.rawmsg('MONITOR', '-', target)
5251
self._monitoring.remove(target)
5352
return True
54-
else:
55-
return False
53+
return False
5654

5755
def is_monitoring(self, target):
5856
""" Return whether or not we are monitoring the target's online status. """
@@ -77,23 +75,33 @@ async def on_capability_monitor_notify_available(self, value):
7775

7876
async def on_raw_730(self, message):
7977
""" Someone we are monitoring just came online. """
80-
for nick in message.params[1].split(','):
81-
self._create_user(nick)
78+
for target in message.params[1].split(','):
79+
nickname, metadata = self._parse_user(target)
80+
self._sync_user(nickname, metadata)
8281
await self.on_user_online(nickname)
8382

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

9092
async def on_raw_732(self, message):
9193
""" List of users we're monitoring. """
92-
self._monitoring.update(message.params[1].split(','))
94+
for target in message.params[1].split(','):
95+
nickname, metadata = self._parse_user(target)
96+
self._monitoring.add(nickname)
9397

94-
on_raw_733 = cap.CapabilityNegotiationSupport._ignored # End of MONITOR list.
98+
on_raw_733 = isupport.ISUPPORTSupport._ignored # End of MONITOR list.
9599

96100
async def on_raw_734(self, message):
97101
""" Monitor list is full, can't add target. """
98102
# Remove from monitoring list, not much else we can do.
99-
self._monitoring.difference_update(message.params[1].split(','))
103+
to_remove = set()
104+
for target in message.params[1].split(','):
105+
nickname, metadata = self._parse_user(target)
106+
to_remove.add(nickname)
107+
self._monitoring.difference_update(to_remove)

pydle/features/isupport.py

+3
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ async def on_isupport_modes(self, value):
179179
""" Maximum number of variable modes to change in a single MODE command. """
180180
self._mode_limit = int(value)
181181

182+
async def on_isupport_monitor(self, value):
183+
self._monitor_limit = int(value)
184+
182185
async def on_isupport_namesx(self, value):
183186
""" Let the server know we do in fact support NAMESX. Effectively the same as CAP multi-prefix. """
184187
await self.rawmsg('PROTOCTL', 'NAMESX')

0 commit comments

Comments
 (0)