Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions examplebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,17 @@ def endMOTD(sender, headers, message):
bot.say(chanName, "The underlying framework is in no way limited to the above functions.")
bot.say(chanName, "This is merely an example of the framework's usage")

def useSSL(argv):
return len (argv) == 6 and argv[5] == "ssl"

# Main program begins here
if __name__ == "__main__":
if len(sys.argv) == 5:
if len(sys.argv) == 5 or useSSL(sys.argv):
server = sys.argv[1]
port = int(sys.argv[2])
owner = sys.argv[3]
chanName = "#" + sys.argv[4]
bot = ircBot(server, port, "ExampleBot", "An example bot written with the new IRC bot framework")
bot = ircBot(server, port, "ExampleBot", "An example bot written with the new IRC bot framework", ssl=useSSL(sys.argv))
bot.bind("PRIVMSG", privmsg)
bot.bind("ACTION", actionmsg)
bot.bind("376", endMOTD)
Expand All @@ -80,6 +83,6 @@ def endMOTD(sender, headers, message):
bot.stop()
bot.join()
else:
print "Usage: python examplebot.py <server> <port> <your IRC nick> <irc channel (no '#' character please)>"
print "Usage: python examplebot.py <server> <port> <your IRC nick> <irc channel (no '#' character please)> <ssl (optional)>"


6 changes: 5 additions & 1 deletion ircbotframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import threading
import re
import time
import ssl

class ircOutputBuffer:
# Delays consecutive messages by at least 1 second.
Expand Down Expand Up @@ -73,13 +74,14 @@ def getLine(self):
return str(line)

class ircBot(threading.Thread):
def __init__(self, network, port, name, description):
def __init__(self, network, port, name, description, ssl=False):
threading.Thread.__init__(self)
self.keepGoing = True
self.name = name
self.desc = description
self.network = network
self.port = port
self.ssl = ssl
self.identifyNickCommands = []
self.identifyLock = False
self.binds = []
Expand Down Expand Up @@ -179,6 +181,8 @@ def connect(self):
self.__debugPrint("Connecting...")
self.irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.irc.connect((self.network, self.port))
if self.ssl:
self.irc = ssl.wrap_socket(self.irc)
self.inBuf = ircInputBuffer(self.irc)
self.outBuf = ircOutputBuffer(self.irc)
self.outBuf.sendBuffered("NICK " + self.name)
Expand Down