2018-07-15 22:56:06 +00:00
|
|
|
import base64
|
|
|
|
|
|
|
|
class Module(object):
|
|
|
|
def __init__(self, bot):
|
|
|
|
self.bot = bot
|
2018-07-16 20:41:39 +00:00
|
|
|
bot.events.on("preprocess.connect").hook(self.preprocess_connect)
|
|
|
|
bot.events.on("received.cap").hook(self.on_cap)
|
|
|
|
bot.events.on("received.authenticate").hook(self.on_authenticate)
|
|
|
|
bot.events.on("received.numeric").on(
|
2018-07-15 22:56:06 +00:00
|
|
|
"902", "903", "904", "905", "906", "907", "908").hook(self.on_90x)
|
|
|
|
|
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):
|
|
|
|
if event["subcommand"] == "NAK":
|
|
|
|
event["server"].send_capability_end()
|
|
|
|
elif event["subcommand"] == "ACK":
|
|
|
|
if not "sasl" in event["capabilities"]:
|
|
|
|
event["server"].send_capability_end()
|
|
|
|
else:
|
|
|
|
event["server"].send_authenticate("PLAIN")
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
def on_90x(self, event):
|
|
|
|
event["server"].send_capability_end()
|
2018-08-31 09:51:47 +00:00
|
|
|
|