diff options
Diffstat (limited to 'ircbot/rssbot.py')
-rwxr-xr-x | ircbot/rssbot.py | 48 |
1 files changed, 19 insertions, 29 deletions
diff --git a/ircbot/rssbot.py b/ircbot/rssbot.py index 40c4554a..5d2beedc 100755 --- a/ircbot/rssbot.py +++ b/ircbot/rssbot.py @@ -17,6 +17,7 @@ class RssBot(irc.bot.SingleServerIRCBot): self.to = timeout self.oldnews = [] self.sendqueue = [] + self.loop = True for entry in self.feed.entries: try: self.sendqueue.append(entry.title + " " + entry.link + " com: " + entry.comments) @@ -28,10 +29,14 @@ class RssBot(irc.bot.SingleServerIRCBot): def start(self): self.upd_thread = _thread.start_new_thread(self.updateloop, ()) self.bot = _thread.start_new_thread(irc.bot.SingleServerIRCBot.start, (self,)) - + + + def stop(self): + self.loop = False + self.disconnect() def updateloop(self): - while True: + while self.loop: sleep(self.to) self.feed = feedparser.parse(self.url) for entry in self.feed.entries: @@ -48,34 +53,19 @@ class RssBot(irc.bot.SingleServerIRCBot): self.send(self.sendqueue.pop()) def send(self, string): - if len(string) < 450: - self.connection.privmsg(self.chan, string) + if self.connection.connected: + if len(string) < 450: + self.connection.privmsg(self.chan, string) + else: + space = 0 + for x in range(math.ceil(len(string)/400)): + oldspace = space + space = string.find(" ", (x+1)*400, (x+1)*400+50) + self.connection.privmsg(self.chan, string[oldspace:space]) + sleep(1) else: - space = 0 - for x in range(math.ceil(len(string)/400)): - oldspace = space - space = string.find(" ", (x+1)*400, (x+1)*400+50) - self.connection.privmsg(self.chan, string[oldspace:space]) - sleep(1) - + self.connection.reconnect() + self.send(string) def on_welcome(self, connection, event): connection.join(self.chan) - -# def on_privmsg(self, connection, event): -# print event.source().split('!')[0], event.arguments() - -#F = open("feeds", "r") -#lines = F.readlines() -#F.close() -# -#botarray = [] -#for line in lines: -# lineArray = line.split('|') -# bot = TestBot(lineArray[1], lineArray[0]) -# #bot.start() -# botarray.append(bot) -# -#def startall(): -# for bot in botarray: -# bot.start() |