2018-07-15 22:56:06 +00:00
|
|
|
import base64
|
|
|
|
|
|
|
|
class Module(object):
|
2018-09-02 18:54:45 +00:00
|
|
|
def __init__(self, bot, events, exports):
|
2018-07-15 22:56:06 +00:00
|
|
|
self.bot = bot
|
2018-08-31 11:55:52 +00:00
|
|
|
events.on("preprocess.connect").hook(self.preprocess_connect)
|
2018-09-03 10:14:27 +00:00
|
|
|
events.on("received.cap.ls").hook(self.on_cap)
|
|
|
|
events.on("received.cap.ack").hook(self.on_cap_ack)
|
2018-08-31 11:55:52 +00:00
|
|
|
events.on("received.authenticate").hook(self.on_authenticate)
|
2018-07-15 22:56:06 +00:00
|
|
|
|
2018-07-16 20:41:39 +00:00
|
|
|
def preprocess_connect(self, event):
|
|
|
|
sasl = event["server"].get_setting("sasl")
|
|
|
|
if sasl:
|
|
|
|
event["server"].send_capability_request("sasl")
|
|
|
|
|
2018-07-15 22:56:06 +00:00
|
|
|
def on_cap(self, event):
|
2018-09-03 11:38:51 +00:00
|
|
|
if "sasl" in event["capabilities"] and event["server"].get_setting(
|
|
|
|
"sasl", None):
|
2018-09-03 10:14:27 +00:00
|
|
|
event["server"].queue_capability("sasl")
|
|
|
|
def on_cap_ack(self, event):
|
|
|
|
if "sasl" in event["capabilities"]:
|
|
|
|
event["server"].send_authenticate("PLAIN")
|
|
|
|
event["server"].wait_for_capability("sasl")
|
2018-07-15 22:56:06 +00:00
|
|
|
|
|
|
|
def on_authenticate(self, event):
|
|
|
|
if event["message"] != "+":
|
|
|
|
event["server"].send_authenticate("*")
|
|
|
|
else:
|
|
|
|
sasl_nick, sasl_pass = event["server"].get_setting("sasl")
|
|
|
|
auth_text = "%s\0%s\0%s" % (
|
|
|
|
sasl_nick, sasl_nick, sasl_pass)
|
|
|
|
auth_text = base64.b64encode(auth_text.encode("utf8"))
|
|
|
|
auth_text = auth_text.decode("utf8")
|
|
|
|
event["server"].send_authenticate(auth_text)
|
2018-09-03 10:14:27 +00:00
|
|
|
event["server"].capability_done("sasl")
|