Skip to content

Commit

Permalink
add ssl-sasl example
Browse files Browse the repository at this point in the history
  • Loading branch information
rmblau committed Jul 13, 2024
1 parent c6c909a commit 4bc4f14
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions scripts/sasl-ssl-cat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#! /usr/bin/env python3
#
# Example program using irc.client.
#
# This program is free without restrictions; do anything you like with
# it.
# IMPORTANT: sasl_login must equal your nickserv account name
#
# Matthew Blau <[email protected]>

import functools
import ssl
import sys

import irc.client
import irc


class IRCCat(irc.client.SimpleIRCClient):
def __init__(self, target):
irc.client.SimpleIRCClient.__init__(self)
self.target = target

def on_welcome(self, connection, event):
if irc.client.is_channel(self.target):
connection.join(self.target)
else:
self.send_it()

def on_login_failed(self, connection, event):
print(event)


def on_join(self, connection, event):
self.send_it()

def on_disconnect(self, connection, event):
sys.exit(0)

def send_it(self):
while 1:
line = sys.stdin.readline().strip()
if not line:
break
self.connection.privmsg(self.target, line)
self.connection.quit("Using irc.client.py")


def main():
server ="irc.libera.chat"
port = 6697
nickname = "nickname"
account_name="username"
target = "##channel"
password = ""

c = IRCCat(target)
try:
context = ssl.create_default_context()
wrapper = functools.partial(context.wrap_socket, server_hostname=server)

c.connect(server, port, nickname, password,sasl_login=account_name, username=account_name, connect_factory=irc.connection.Factory(wrapper=wrapper))
except irc.client.ServerConnectionError as x:
print(x)
sys.exit(1)
c.start()


if __name__ == "__main__":
main()

0 comments on commit 4bc4f14

Please sign in to comment.