Skip to content
Merged
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
16 changes: 9 additions & 7 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import ssl
import threading
import irc.bot
import irc.client
import irc.connection
import tinyurl
Expand All @@ -15,23 +16,24 @@
from db import FeedDB
from config import Config

class IRCBot(irc.client.SimpleIRCClient):
class IRCBot(irc.bot.SingleServerIRCBot):
def __init__(self, config, db, on_connect_cb):
irc.client.SimpleIRCClient.__init__(self)
self.__config = config
self.__db = db
if self.__config.SSL:
ssl_factory = irc.connection.Factory(wrapper=ssl.wrap_socket)
self.connect(self.__config.HOST, self.__config.PORT, self.__config.NICK, connect_factory=ssl_factory)
else:
self.connect(self.__config.HOST, self.__config.PORT, self.__config.NICK)
self.__on_connect_cb = on_connect_cb
self.__servers = [irc.bot.ServerSpec(self.__config.HOST, self.__config.PORT, self.__config.PASSWORD)]
self.num_col = self.__config.num_col
self.date = self.__config.date
self.feedname = self.__config.feedname
self.shorturls = self.__config.shorturls
self.dateformat = self.__config.dateformat

if self.__config.SSL:
ssl_factory = irc.connection.Factory(wrapper=ssl.wrap_socket)
super(IRCBot, self).__init__(self.__servers, self.__config.NICK, self.__config.NICK, connect_factory=ssl_factory)
else:
super(IRCBot, self).__init__(self.__servers, self.__config.NICK, self.__config.NICK)

def on_welcome(self, connection, event):
"""Join the correct channel upon connecting"""
if irc.client.is_channel(self.__config.CHANNEL):
Expand Down
1 change: 1 addition & 0 deletions config.py.sample
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Config(object):
def __init__(self):
self.HOST = "irc.freenode.org"
self.PORT = 6667
self.PASSWORD = None
self.SSL = False
self.CHANNEL = "##YOURCHANNEL"
self.NICK = "YOURBOTNICK"
Expand Down