diff options
| author | 2018-07-15 23:56:06 +0100 | |
|---|---|---|
| committer | 2018-07-15 23:56:06 +0100 | |
| commit | 2012a388dac6cbb31945ff04d31a11da19f6e4b0 (patch) | |
| tree | 4d5a8f5f7c8f87aa777ad828c957aeace7126e4e /modules/sasl.py | |
| parent | fix print_activity still using old EventManager priority location (diff) | |
| signature | ||
move sasl logic to it's own module
Diffstat (limited to 'modules/sasl.py')
| -rw-r--r-- | modules/sasl.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/modules/sasl.py b/modules/sasl.py new file mode 100644 index 00000000..afe48522 --- /dev/null +++ b/modules/sasl.py @@ -0,0 +1,33 @@ +import base64 + +class Module(object): + def __init__(self, bot): + self.bot = bot + bot.events.on("received").on("cap").hook(self.on_cap) + bot.events.on("received").on("authenticate").hook(self.on_authenticate) + bot.events.on("received").on("numeric").on( + "902", "903", "904", "905", "906", "907", "908").hook(self.on_90x) + + 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() + |
