diff options
author | makefu <github@syntax-fehler.de> | 2014-03-19 11:34:32 +0100 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2014-03-19 11:34:32 +0100 |
commit | c7f8dc8adfd52f7ba562438c8609d15840d905a1 (patch) | |
tree | 3c74f1bac18188b27968dd2b0d88567cc9a7cab2 /news/newsbot.py | |
parent | fdac73b61318c49b068e8ea6a771bb68a49f1272 (diff) | |
parent | 8a40327409632f0de7a3167a1f935d1345725522 (diff) |
Merge branch 'master' of ssh://github.com/krebscode/painload
Diffstat (limited to 'news/newsbot.py')
-rw-r--r-- | news/newsbot.py | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/news/newsbot.py b/news/newsbot.py index 8834851d..2f8bf635 100644 --- a/news/newsbot.py +++ b/news/newsbot.py @@ -17,7 +17,7 @@ from time import sleep ## Newsbot Controller Class class NewsBot(asybot): - def __init__(self, name, channels=['#test'], server='ire', port=6667, timeout=60, loglevel=logging.ERROR, url_shortener='http://wall'): + def __init__(self, name, channels=['#test'], server='ire', port=6667, timeout=60, loglevel=logging.ERROR, url_shortener='http://localhost'): asybot.__init__(self, server, port, name, channels, loglevel=loglevel) self.to = timeout self.url_shortener = url_shortener @@ -140,7 +140,9 @@ class RssBot(asybot): self.lastnew = datetime.now() self.url_shortener = url_shortener self.retry = True - self.on_nickinuse = lambda: None + + def on_nickinuse(*bla): + pass def start_rss(self): self.upd_loop = threading.Thread(target=self.updateloop) @@ -203,19 +205,19 @@ class RssBot(asybot): def send_msg(self, target, string): if self.connected: for line in string.split('\n'): - if len(line) < 450: - self.PRIVMSG(target, line) - else: - space = 0 - for x in range(math.ceil(len(line)/400)): - oldspace = space - space = line.find(" ", (x+1)*400, (x+1)*400+50) - self.PRIVMSG(target, line[oldspace:space]) + while len(line)>0: + if len(line) < 450: + self.PRIVMSG(target, line) + line = '' + else: + space = line.rfind(" ", 1, 450) + self.PRIVMSG(target, line[:space]) + line=line[space:] else: self.reconnect() while not self.connected: - sleep(10) print(self.nickname + ' waiting for reconnect') + sleep(10) self.send_msg(target, string) def on_invite(self, prefix, command, params, rest): @@ -223,12 +225,16 @@ class RssBot(asybot): self.push('JOIN ' + chan) self.channels.append(chan) + def on_welcome(self, prefix, command, params, rest): + asybot.on_welcome(self, prefix, command, params, rest) + self.push('MODE ' + self.nickname + ' +D') + feedfile = 'new_feeds' -url_shortener = 'http://wall' +url_shortener = 'http://go' init_channels = ['#news'] bots = {} -knews = NewsBot('knews', init_channels) +knews = NewsBot('knews', init_channels, url_shortener=url_shortener) #config file reading F = open(feedfile, "r") |