Skip to content

Commit f11dca5

Browse files
committed
coretasks: fix bad WHO loop, update querytype
who_reqs, which is used to track WHO requests to the server, had flipped keys/values and was never getting cleared upon RPL_ENDOFWHO. Eventually, this would lead to an endless loop while the bot tried to get an unused "querytype" (randint) in order to track WHO replies. This unneccessary loop/check to ensure unique values for the query type was removed. A RPL_WHOREPLY includes the channel name in the response, so confirming that the querytype for a channel matched is sufficient. querytype should be unique _per purpose_. So, now a constant querytype is used for `coretasks` WHO(X) requests. Notes: According to [the closest thing to] official specs: ircv3/ircv3-specifications#81 (comment) querytypes should be useful to: > simplify scripting, in example one could pass a certain value in the query > and have that value "signal" back what is to be done with those replies. Also see: https://github.com/quakenet/snircd/blob/17c92003d376c70db674821e92f2880ba1587132/doc/readme.who#L154 https://github.com/quakenet/snircd/blob/17c92003d376c70db674821e92f2880ba1587132/doc/readme.who#L105
1 parent e2d8439 commit f11dca5

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

sopel/coretasks.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import datetime
2929
import functools
3030
import logging
31-
from random import randint
3231
import re
3332
import sys
3433
import time
@@ -45,8 +44,13 @@
4544

4645
LOGGER = logging.getLogger(__name__)
4746

47+
CORE_QUERYTYPE = '999'
48+
"""WHOX querytype to indicate requests/responses from coretasks.
49+
50+
Other plugins should use a different querytype.
51+
"""
52+
4853
batched_caps = {}
49-
who_reqs = {} # Keeps track of reqs coming from this plugin, rather than others
5054

5155

5256
def setup(bot):
@@ -698,14 +702,12 @@ def _remove_from_channel(bot, nick, channel):
698702
def _send_who(bot, channel):
699703
if 'WHOX' in bot.isupport:
700704
# 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])
709711
else:
710712
# We might be on an old network, but we still care about keeping our
711713
# user list updated
@@ -1243,8 +1245,9 @@ def account_notify(bot, trigger):
12431245
@plugin.priority('medium')
12441246
def recv_whox(bot, trigger):
12451247
"""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:
12471249
# Ignored, some plugin probably called WHO
1250+
LOGGER.debug("Ignoring WHO reply for channel '%s'; not queried by coretasks", trigger.args[1])
12481251
return
12491252
if len(trigger.args) != 8:
12501253
LOGGER.warning(
@@ -1307,16 +1310,6 @@ def recv_who(bot, trigger):
13071310
_record_who(bot, channel, user, host, nick, away=away, modes=modes)
13081311

13091312

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-
13201313
@module.event('AWAY')
13211314
@module.thread(False)
13221315
@module.unblockable

0 commit comments

Comments
 (0)