45 lines
2.2 KiB
Python
45 lines
2.2 KiB
Python
# -*- coding: utf-8 -*- ########################################################## SOF
|
|
import irc3
|
|
import base64
|
|
######################################################################################
|
|
BOT_SASL_USERNAME='not_maple'
|
|
BOT_SASL_PASSWORD='CHANGEYOURPASSWORD'
|
|
######################################################################################
|
|
@irc3.plugin
|
|
class MAPLESASL:
|
|
##################################################################################
|
|
def __init__(self, bot):
|
|
print('[ maplesasl initiated ]')
|
|
self.bot=bot
|
|
self.auth=(f'{BOT_SASL_USERNAME}\0{BOT_SASL_USERNAME}\0{BOT_SASL_PASSWORD}')
|
|
self.auth=base64.encodebytes(self.auth.encode('utf8'))
|
|
self.auth=self.auth.decode('utf8').rstrip('\n')
|
|
self.events = [
|
|
irc3.event(r'^:\S+ CAP \S+ LS :(?P<data>.*)', self.cap_ls),
|
|
irc3.event(r'^:\S+ CAP \S+ ACK sasl', self.cap_ack),
|
|
irc3.event(r'AUTHENTICATE +', self.authenticate),
|
|
irc3.event(r'^:\S+ 903 \S+ :Authentication successful',self.cap_end),
|
|
]
|
|
##################################################################################
|
|
def connection_ready(self, *args, **kwargs):
|
|
self.bot.send('CAP LS\r\n')
|
|
self.bot.attach_events(*self.events)
|
|
##################################################################################
|
|
def cap_ls(self, data=None, **kwargs):
|
|
if 'sasl' in data.lower():
|
|
self.bot.send_line('CAP REQ :sasl')
|
|
else:
|
|
self.cap_end()
|
|
##################################################################################
|
|
def cap_ack(self, **kwargs):
|
|
self.bot.send_line('AUTHENTICATE PLAIN')
|
|
##################################################################################
|
|
def authenticate(self, **kwargs):
|
|
self.bot.send_line(f'AUTHENTICATE {self.auth}\n')
|
|
##################################################################################
|
|
def cap_end(self, **kwargs):
|
|
self.bot.send_line('CAP END\r\n')
|
|
self.bot.detach_events(*self.events)
|
|
##################################################################################
|
|
################################################################################## EOF
|