|
28 | 28 | import datetime |
29 | 29 | import functools |
30 | 30 | import logging |
31 | | -from random import randint |
32 | 31 | import re |
33 | 32 | import sys |
34 | 33 | import time |
|
45 | 44 |
|
46 | 45 | LOGGER = logging.getLogger(__name__) |
47 | 46 |
|
| 47 | +CORE_QUERYTYPE = '999' |
| 48 | +"""WHOX querytype to indicate requests/responses from coretasks. |
| 49 | +
|
| 50 | +Other plugins should use a different querytype. |
| 51 | +""" |
| 52 | + |
48 | 53 | batched_caps = {} |
49 | | -who_reqs = {} # Keeps track of reqs coming from this plugin, rather than others |
50 | 54 |
|
51 | 55 |
|
52 | 56 | def setup(bot): |
@@ -698,14 +702,12 @@ def _remove_from_channel(bot, nick, channel): |
698 | 702 | def _send_who(bot, channel): |
699 | 703 | if 'WHOX' in bot.isupport: |
700 | 704 | # WHOX syntax, see http://faerion.sourceforge.net/doc/irc/whox.var |
701 | | - # Needed for accounts in WHO replies. The random integer is a param |
702 | | - # to identify the reply as one from this command, because if someone |
703 | | - # else sent it, we have no fucking way to know what the format is. |
704 | | - rand = str(randint(0, 999)) |
705 | | - while rand in who_reqs: |
706 | | - rand = str(randint(0, 999)) |
707 | | - who_reqs[rand] = channel |
708 | | - bot.write(['WHO', channel, 'a%nuachtf,' + rand]) |
| 705 | + # Needed for accounts in WHO replies. The `CORE_QUERYTYPE` parameter |
| 706 | + # for WHO is used to identify the reply from the server and confirm |
| 707 | + # that it has the requested format. WHO replies with different |
| 708 | + # querytypes in the response were initiated elsewhere and will be |
| 709 | + # ignored. |
| 710 | + bot.write(['WHO', channel, 'a%nuachtf,' + CORE_QUERYTYPE]) |
709 | 711 | else: |
710 | 712 | # We might be on an old network, but we still care about keeping our |
711 | 713 | # user list updated |
@@ -1243,8 +1245,9 @@ def account_notify(bot, trigger): |
1243 | 1245 | @plugin.priority('medium') |
1244 | 1246 | def recv_whox(bot, trigger): |
1245 | 1247 | """Track ``WHO`` responses when ``WHOX`` is enabled.""" |
1246 | | - if len(trigger.args) < 2 or trigger.args[1] not in who_reqs: |
| 1248 | + if len(trigger.args) < 2 or trigger.args[1] != CORE_QUERYTYPE: |
1247 | 1249 | # Ignored, some plugin probably called WHO |
| 1250 | + LOGGER.debug("Ignoring WHO reply for channel '%s'; not queried by coretasks", trigger.args[1]) |
1248 | 1251 | return |
1249 | 1252 | if len(trigger.args) != 8: |
1250 | 1253 | LOGGER.warning( |
@@ -1307,16 +1310,6 @@ def recv_who(bot, trigger): |
1307 | 1310 | _record_who(bot, channel, user, host, nick, away=away, modes=modes) |
1308 | 1311 |
|
1309 | 1312 |
|
1310 | | -@module.event(events.RPL_ENDOFWHO) |
1311 | | -@plugin.thread(False) |
1312 | | -@module.unblockable |
1313 | | -@plugin.priority('medium') |
1314 | | -def end_who(bot, trigger): |
1315 | | - """Handle the end of a response to a ``WHO`` command (if needed).""" |
1316 | | - if 'WHOX' in bot.isupport: |
1317 | | - who_reqs.pop(trigger.args[1], None) |
1318 | | - |
1319 | | - |
1320 | 1313 | @module.event('AWAY') |
1321 | 1314 | @module.thread(False) |
1322 | 1315 | @module.unblockable |
|
0 commit comments