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
14 changes: 10 additions & 4 deletions bot.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import ssl
import threading
import irc.client
import irc.connection
import tinyurl
import time
import re
Expand All @@ -18,7 +20,11 @@ def __init__(self, config, db, on_connect_cb):
irc.client.SimpleIRCClient.__init__(self)
self.__config = config
self.__db = db
self.connect(self.__config.HOST, self.__config.PORT, self.__config.NICK)
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.num_col = self.__config.num_col
self.date = self.__config.date
Expand Down Expand Up @@ -55,7 +61,7 @@ def __handle_msg(self, msg):
news_count = self.__db.get_news_count()
answer = "Feeds: " + Colours(self.num_col,str(feeds_count)).get() + ", News: " + Colours(self.num_col,str(news_count)).get()

# Print last 25 news.
# Print last 25 news.
elif msg == "!last":
answer = ""
for entry in self.__db.get_latest_news()[::-1]:
Expand Down Expand Up @@ -100,7 +106,7 @@ def on_pubmsg(self, connection, event):
# Get the message. We are only interested in "!help"
msg = event.arguments[0].lower().strip()

# Send the answer as a private message
# Send the answer as a private message
if msg == "!help":
self.send_msg(event.source.nick, self.__help_msg())

Expand Down Expand Up @@ -210,4 +216,4 @@ def __fetch_feed(self, feed_info):
print "Failed: " + feed_info[1]

# sleep frequency minutes
time.sleep(int(feed_info[3])*60)
time.sleep(int(feed_info[3])*60)
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.SSL = False
self.CHANNEL = "##YOURCHANNEL"
self.NICK = "YOURBOTNICK"
self.admin_nicks= ['YOURADMINNICK']
Expand Down