From 51f56ef922db19b0cf34c2d8ec271bef4b642995 Mon Sep 17 00:00:00 2001 From: Sebastian Gehaxelt Date: Sun, 2 Oct 2016 22:02:01 +0200 Subject: [PATCH 1/2] Using SingleServerIRCBot for automatic reconnects --- bot.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bot.py b/bot.py index 35de048..67faf5c 100644 --- a/bot.py +++ b/bot.py @@ -3,6 +3,7 @@ import threading import irc.client +import irc.bot import tinyurl import time import re @@ -13,18 +14,18 @@ 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 - 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.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 + super(IRCBot, self).__init__(self.__servers, self.__config.NICK, self.__config.NICK) def on_welcome(self, connection, event): """Join the correct channel upon connecting""" From f16ee5a1597f53a68abde8c4d06926731475c1b1 Mon Sep 17 00:00:00 2001 From: Sebastian Gehaxelt Date: Sun, 2 Oct 2016 22:03:34 +0200 Subject: [PATCH 2/2] Added password option for password protected servers --- bot.py | 2 +- config.py.sample | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index 67faf5c..22acfb1 100644 --- a/bot.py +++ b/bot.py @@ -19,7 +19,7 @@ def __init__(self, config, db, on_connect_cb): self.__config = config self.__db = db self.__on_connect_cb = on_connect_cb - self.__servers = [irc.bot.ServerSpec(self.__config.HOST, self.__config.PORT)] + 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 diff --git a/config.py.sample b/config.py.sample index 50e37f3..afd2ac2 100644 --- a/config.py.sample +++ b/config.py.sample @@ -5,6 +5,7 @@ class Config(object): def __init__(self): self.HOST = "irc.freenode.org" self.PORT = 6667 + self.PASSWORD = None self.CHANNEL = "##YOURCHANNEL" self.NICK = "YOURBOTNICK" self.admin_nicks= ['YOURADMINNICK']