1
1
## monitor.py
2
2
# Online status monitoring support.
3
- from . import cap
3
+ from .. import isupport
4
4
5
5
6
- class MonitoringSupport (cap . CapabilityNegotiationSupport ):
6
+ class MonitoringSupport (isupport . ISUPPORTSupport ):
7
7
""" Support for monitoring the online/offline status of certain targets. """
8
8
9
9
## Internals.
@@ -36,23 +36,21 @@ def _destroy_user(self, nickname, channel=None, monitor_override=False):
36
36
37
37
## API.
38
38
39
- def monitor (self , target ):
39
+ async def monitor (self , target ):
40
40
""" 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 )
43
43
self ._monitoring .add (target )
44
44
return True
45
- else :
46
- return False
45
+ return False
47
46
48
- def unmonitor (self , target ):
47
+ async def unmonitor (self , target ):
49
48
""" 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 )
52
51
self ._monitoring .remove (target )
53
52
return True
54
- else :
55
- return False
53
+ return False
56
54
57
55
def is_monitoring (self , target ):
58
56
""" 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):
77
75
78
76
async def on_raw_730 (self , message ):
79
77
""" 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 )
82
81
await self .on_user_online (nickname )
83
82
84
83
async def on_raw_731 (self , message ):
85
84
""" 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 )
88
90
await self .on_user_offline (nickname )
89
91
90
92
async def on_raw_732 (self , message ):
91
93
""" 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 )
93
97
94
- on_raw_733 = cap . CapabilityNegotiationSupport ._ignored # End of MONITOR list.
98
+ on_raw_733 = isupport . ISUPPORTSupport ._ignored # End of MONITOR list.
95
99
96
100
async def on_raw_734 (self , message ):
97
101
""" Monitor list is full, can't add target. """
98
102
# 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 )
0 commit comments