Properly handle CAP LS lines with name=value items in them
This commit is contained in:
parent
cdcc65c9b8
commit
08a81fbc09
@ -243,31 +243,34 @@ def connect_callback(cli):
|
|||||||
supported_caps = set()
|
supported_caps = set()
|
||||||
|
|
||||||
@hook("cap")
|
@hook("cap")
|
||||||
def on_cap(cli, svr, mynick, cmd, caps, star=None):
|
def on_cap(cli, svr, mynick, cmd, *caps):
|
||||||
|
# caps is a star because we might receive multiline in LS
|
||||||
if cmd == "LS":
|
if cmd == "LS":
|
||||||
if caps == "*":
|
for item in caps[-1].split(): # First item may or may not be *, for multiline
|
||||||
# Multi-line LS
|
supported_caps.add(item.split("=")[0]) # If there's any value, we just don't care
|
||||||
supported_caps.update(star.split())
|
|
||||||
else:
|
if caps[0] == "*": # Multiline, don't continue yet
|
||||||
supported_caps.update(caps.split())
|
return
|
||||||
|
|
||||||
if botconfig.SASL_AUTHENTICATION and "sasl" not in supported_caps:
|
if botconfig.SASL_AUTHENTICATION and "sasl" not in supported_caps:
|
||||||
alog("Server does not support SASL authentication")
|
alog("Server does not support SASL authentication")
|
||||||
cli.quit()
|
cli.quit()
|
||||||
|
raise ValueError("Server does not support SASL authentication")
|
||||||
|
|
||||||
common_caps = request_caps & supported_caps
|
common_caps = request_caps & supported_caps
|
||||||
|
|
||||||
if common_caps:
|
if common_caps:
|
||||||
cli.send("CAP REQ " ":{0}".format(" ".join(common_caps)))
|
cli.send("CAP REQ " ":{0}".format(" ".join(common_caps)))
|
||||||
|
|
||||||
elif cmd == "ACK":
|
elif cmd == "ACK":
|
||||||
if "sasl" in caps:
|
if "sasl" in caps[0]:
|
||||||
cli.send("AUTHENTICATE PLAIN")
|
cli.send("AUTHENTICATE PLAIN")
|
||||||
else:
|
else:
|
||||||
cli.send("CAP END")
|
cli.send("CAP END")
|
||||||
elif cmd == "NAK":
|
elif cmd == "NAK":
|
||||||
# This isn't supposed to happen. The server claimed to support a
|
# This isn't supposed to happen. The server claimed to support a
|
||||||
# capability but now claims otherwise.
|
# capability but now claims otherwise.
|
||||||
alog("Server refused capabilities: {0}".format(" ".join(caps)))
|
alog("Server refused capabilities: {0}".format(" ".join(caps[0])))
|
||||||
|
|
||||||
if botconfig.SASL_AUTHENTICATION:
|
if botconfig.SASL_AUTHENTICATION:
|
||||||
@hook("authenticate")
|
@hook("authenticate")
|
||||||
|
Loading…
Reference in New Issue
Block a user