diff options
author | lassulus <lassulus@googlemail.com> | 2014-01-04 15:05:23 +0100 |
---|---|---|
committer | lassulus <lassulus@googlemail.com> | 2014-01-04 15:05:23 +0100 |
commit | 79ea1e311ae6d1015c8cffe7855b23bdabf5ea6a (patch) | |
tree | 9628f5e02efd53d9d67f14ba78ef7da6bb8bd9f6 /ircbot | |
parent | 366f912a3771a1c5b92441ef7efed52541b33827 (diff) |
ircbot: del now working
Diffstat (limited to 'ircbot')
-rwxr-xr-x | ircbot/contoller.py | 14 | ||||
-rw-r--r-- | ircbot/new_feeds | 5 | ||||
-rwxr-xr-x | ircbot/rssbot.py | 48 |
3 files changed, 31 insertions, 36 deletions
diff --git a/ircbot/contoller.py b/ircbot/contoller.py index 5750551f..fcd839b5 100755 --- a/ircbot/contoller.py +++ b/ircbot/contoller.py @@ -1,10 +1,6 @@ import irc.bot import _thread import rssbot -# -#def startall(): -# for bot in botarray: -# bot.start() class NewsBot(irc.bot.SingleServerIRCBot): def __init__(self, name, server='ire', port=6667, chan='#news', timeout=60): @@ -53,10 +49,12 @@ class NewsBot(irc.bot.SingleServerIRCBot): bots[args[1]] = bot bot.start() return "bot " + args[1] + " added" + elif args[0] == 'del': - bots[args[1]].die() - del bots[args1] + bots[args[1]].stop() + del bots[args[1]] return "bot " + args[1] + " deleted" + elif args[0] == 'save': output_buffer = '' for bot in bots: @@ -67,7 +65,8 @@ class NewsBot(irc.bot.SingleServerIRCBot): F.close() return "bots saved to " + feedfile - + elif args[0] == 'caps': + return "add del save caps" else: return "unknown command" @@ -86,6 +85,7 @@ lines = F.readlines() F.close() for line in lines: + line = line.strip('\n') linear = line.split('|') bot = rssbot.RssBot(linear[1], linear[0]) bot.start() diff --git a/ircbot/new_feeds b/ircbot/new_feeds index 4931f3fd..cc3bad6f 100644 --- a/ircbot/new_feeds +++ b/ircbot/new_feeds @@ -1,2 +1,7 @@ fefe|http://blog.fefe.de/rss.xml HN|http://news.ycombinator.com/rss +lisp|http://planet.lisp.org/rss20.xml +LtU|http://lambda-the-ultimate.org/rss.xml +antirez|http://antirez.com/rss +coinspotting|http://coinspotting.com/rss +xkcd|https://xkcd.com/rss.xml 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() |