-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support IRCv3 CAP, Make SASL less hacky
- Loading branch information
Showing
8 changed files
with
99 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
from .client import Client | ||
from .connection import Socket | ||
from .config import IRCConfig | ||
from .ext.sasl import Sasl | ||
from .ext.proxy import * | ||
from .ext.fifo import Fifo | ||
from .caps import Caps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from .ext import sasl | ||
|
||
class Caps(object): | ||
def __init__(self, *args): | ||
self.caps = list(args) | ||
self.availablecaps = [] | ||
self.stringcaps = [] | ||
self.done = False | ||
for cap in self.caps: | ||
if not isinstance(cap, str): | ||
self.stringcaps.append(cap.name) | ||
else: | ||
self.stringcaps.append(cap) | ||
|
||
def handler(self,event): | ||
if event.arguments[0] == "LS": | ||
servcaps = event.arguments[1].split(' ') | ||
for c in servcaps: | ||
if c in self.stringcaps: | ||
self.availablecaps.append(c) | ||
if not self.availablecaps: | ||
self.bot.send("CAP END") | ||
else: | ||
self.bot.send("CAP REQ :"+" ".join(self.availablecaps)) | ||
elif event.arguments[0] == "ACK": | ||
for cap in self.caps: | ||
if hasattr(cap, "run"): | ||
cap.run(self.bot) | ||
|
||
def run(self, bot): | ||
self.bot = bot | ||
self.bot.listen(self.handler,"cap") | ||
self.bot.send("CAP LS") | ||
|
||
|
||
__call__ = run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from . import proxy | ||
from . import proxy, fifo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# SASL authentication for zirc | ||
|
||
import base64 | ||
from ..errors import SASLError | ||
|
||
class Sasl(object): | ||
name = "sasl" | ||
def __init__(self, username, password, method="plain"): | ||
self.username = username | ||
self.password = password | ||
self.method = method | ||
def run(self, bot): | ||
self.bot = bot | ||
bot.listen(self.on_authenticate,"authenticate") | ||
bot.listen(self.on_saslfailed,"saslfailed") | ||
bot.listen(self.on_saslsuccess,"saslsuccess") | ||
if self.method == "plain": | ||
bot.send("AUTHENTICATE PLAIN") | ||
else: | ||
raise SASLError("not implemented yet") | ||
|
||
def on_authenticate(self,event): | ||
if event.arguments[0] == "+": | ||
password = base64.b64encode("{0}\x00{0}\x00{1}".format(self.username, self.password).encode("UTF-8")).decode("UTF-8") | ||
self.bot.send("AUTHENTICATE {0}".format(password)) | ||
|
||
def on_saslfailed(self, event): | ||
raise SASLError("SASL authentication failed!") # do something else later, like try another method | ||
|
||
def on_saslsuccess(self, event): | ||
self.bot.send("CAP END") |