From 5915b89847c0fe30b0ef46d10ecf511ff0a1659f Mon Sep 17 00:00:00 2001 From: tcki Date: Tue, 16 Apr 2013 07:04:50 +0000 Subject: [PATCH 1/6] rss tweaks, tcki's modules --- willie/modules/join.py | 16 +++ willie/modules/raw.py | 22 ++++ willie/modules/rss.py | 255 +++++++++++++++++++---------------------- 3 files changed, 154 insertions(+), 139 deletions(-) create mode 100644 willie/modules/join.py create mode 100644 willie/modules/raw.py diff --git a/willie/modules/join.py b/willie/modules/join.py new file mode 100644 index 0000000000..b7b81f6ce0 --- /dev/null +++ b/willie/modules/join.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +""" +join.py - Channel Join Module +http://github.com/tcki +""" + +def join(willie, trigger): + """.join - joins specified channel""" + if trigger.admin: + willie.write(['JOIN'], trigger.group(2)) +join.commands = ['join'] +join.example = '.join #channel' +join.priority = 'medium' + +if __name__ == '__main__': + print __doc__.strip() diff --git a/willie/modules/raw.py b/willie/modules/raw.py new file mode 100644 index 0000000000..81826995d8 --- /dev/null +++ b/willie/modules/raw.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +""" +raw.py - Raw Command Module +http://github.com/tcki +""" + +def raw(willie, trigger): + """.raw - Sends specified text to server""" + if trigger.admin: + command = willie.safe(trigger.group(2))[:510] + '\r\n' + try: + willie.writing_lock.acquire() + willie.log_raw(command) + willie.send(command) + finally: + willie.writing_lock.release() +raw.commands = ['raw'] +raw.example = '.raw COMMAND' +raw.priority = 'high' + +if __name__ == '__main__': + print __doc__.strip() diff --git a/willie/modules/rss.py b/willie/modules/rss.py index 87fde5b0b5..8855d48ee4 100644 --- a/willie/modules/rss.py +++ b/willie/modules/rss.py @@ -13,95 +13,129 @@ import time DEBUG = False -socket.setdefaulttimeout(10) -INTERVAL = 10 # seconds between checking for new updates +socket.setdefaulttimeout(10) # seconds before giving up on the feed until next cycle +INTERVAL = 10 # seconds between checking for new updates STOP = False -#This is reset in setup(). SUB = ('%s',) - def checkdb(cursor): - cursor.execute("CREATE TABLE IF NOT EXISTS rss ( channel text, site_name text, site_url text, fg text, bg text)") + cursor.execute("CREATE TABLE IF NOT EXISTS rss ( channel text, site_title text, site_url text, fg text, bg text)") def setup(willie): global SUB SUB = (willie.db.substitution,) def manage_rss(willie, trigger): - """ .rss operation channel site_name url -- operation can be either 'add', 'del', or 'list' no further operators needed if 'list' used """ + """ .rss [list|add|edit|del|start] <#channel> <url> - no arguments needed with list or start, no url needed with delete (title optional). """ if not trigger.admin: - willie.reply("Sorry, you need to be an admin to modify the RSS feeds.") + willie.reply("Sorry, you need to be an admin to modify or start the RSS feed.") return - conn = willie.db.connect() - c = conn.cursor() - checkdb(c) - conn.commit() - text = trigger.group().split() - if len(text) < 2: - willie.reply("Proper usage: '.rss add ##channel Site_Name URL', '.rss del ##channel Site_Name URL', '.rss del ##channel'") - elif len(text) > 2: - channel = text[2].lower() - - if len(text) > 4 and text[1] == 'add': - fg_colour = str() - bg_colour = str() - temp = trigger.group().split('"') - if len(temp) == 1: - site_name = text[3] - site_url = text[4] - if len(text) >= 6: - # .rss add ##yano ScienceDaily http://sciencedaily.com/ 03 - fg_colour = str(text[5]) - if len(text) == 7: - # .rss add ##yano ScienceDaily http://sciencedaily.com/ 03 00 - bg_colour = str(text[6]) - elif temp[-1].split(): - site_name = temp[1] - ending = temp[-1].split() - site_url = ending[0] - if len(ending) >= 2: - fg_colour = ending[1] - if len(ending) == 3: - bg_colour = ending[2] + if text[1] == 'start': + global first_run, restarted, DEBUG, INTERVAL, STOP + DEBUG = False + query = trigger.group(3) + if query == '-v': + DEBUG = True + STOP = False + willie.reply("Debugging enabled.") + elif query == '-q': + DEBUG = False + STOP = False + willie.reply("Debugging disabled.") + elif query == '-i': + INTERVAL = trigger.group(4) + willie.reply("INTERVAL updated to: %s" % (str(INTERVAL))) + elif query == '--stop': + STOP = True + willie.reply("Stop parameter updated.") + if first_run: + if DEBUG: + willie.say("Okay, I'll start rss fetching...") + first_run = False else: - willie.reply("Not enough parameters specified.") - return - if fg_colour: - fg_colour = fg_colour.zfill(2) - if bg_colour: - bg_colour = bg_colour.zfill(2) - c.execute('INSERT INTO rss VALUES ("%s","%s","%s","%s","%s")' % sub*5, (channel, site_name, site_url, fg_colour, bg_colour)) - conn.commit() - c.close() - willie.reply("Successfully added values to database.") - elif len(text) == 3 and text[1] == 'del': - # .rss del ##channel - c.execute('DELETE FROM rss WHERE channel = "%s"' % SUB, channel) - conn.commit() - c.close() - willie.reply("Successfully removed values from database.") - elif len(text) >= 4 and text[1] == 'del': - # .rss del ##channel Site_Name - c.execute('DELETE FROM rss WHERE channel = "%s" and site_name = "%s"' % SUB*2, (channel, " ".join(text[3:]))) - conn.commit() - c.close() - willie.reply("Successfully removed the site from the given channel.") - elif len(text) == 2 and text[1] == 'list': - c.execute("SELECT * FROM rss") - k = 0 - for row in c: - k += 1 - willie.say("list: " + unicode(row)) - if k == 0: - willie.reply("No entries in database") + restarted = True + if DEBUG: + willie.say("Okay, I'll re-start rss...") + if not STOP: + while True: + if STOP: + willie.reply("STOPPED") + first_run = False + STOP = False + break + if DEBUG: + willie.say("Rechecking feeds") + read_feeds(willie) + time.sleep(INTERVAL) + if DEBUG: + willie.say("Stopped checking") else: - willie.reply("Incorrect parameters specified.") - conn.close() + conn = willie.db.connect() + c = conn.cursor() + checkdb(c) + conn.commit() + if len(text) < 2: + willie.reply("Proper usage: '.rss add #channel title url', '.rss del #channel title', '.rss del #channel'") + elif len(text) > 2: + channel = "#"+text[2].lower() + if len(text) > 4 and text[1] == 'add': + fg_colour = str() + bg_colour = str() + temp = trigger.group().split('"') + if len(temp) == 1: + site_title = text[3] + site_url = text[4] + if len(text) >= 6: + fg_colour = str(text[5]) + if len(text) == 7: + bg_colour = str(text[6]) + elif temp[-1].split(): + site_title = temp[1] + ending = temp[-1].split() + site_url = ending[0] + if len(ending) >= 2: + fg_colour = ending[1] + if len(ending) == 3: + bg_colour = ending[2] + else: + willie.reply("Not enough parameters specified.") + return + if fg_colour: + fg_colour = fg_colour.zfill(2) + if bg_colour: + bg_colour = bg_colour.zfill(2) + args = tuple([channel, site_title, site_url, fg_colour, bg_colour]) + c.execute('INSERT INTO rss VALUES ("%s","%s","%s","%s","%s")' % args) + conn.commit() + c.close() + willie.reply("Successfully added values to database.") + elif len(text) == 3 and text[1] == 'del': + args = tuple([channel]) + c.execute('DELETE FROM rss WHERE channel = "%s"' % args) + conn.commit() + c.close() + willie.reply("Successfully removed values from database.") + elif len(text) >= 4 and text[1] == 'del': + args = tuple([channel, " ".join(text[3:])]) + c.execute('DELETE FROM rss WHERE channel = "%s" and site_title = "%s"' % args) + conn.commit() + c.close() + willie.reply("Successfully removed the site from the given channel.") + elif len(text) == 2 and text[1] == 'list': + c.execute("SELECT * FROM rss") + k = 0 + for row in c: + k += 1 + willie.say("list: " + unicode(row)) + if k == 0: + willie.reply("No entries in database") + else: + willie.reply("Incorrect parameters specified.") + conn.close() manage_rss.commands = ['rss'] manage_rss.priority = 'low' - class Feed(object): modified = '' @@ -109,11 +143,9 @@ class Feed(object): restarted = False feeds = dict() - def read_feeds(willie): global restarted global STOP - restarted = False conn = willie.db.connect() cur = conn.cursor() @@ -123,12 +155,11 @@ def read_feeds(willie): STOP = True willie.say("No RSS feeds found in database. Please add some rss feeds.") - cur.execute("CREATE TABLE IF NOT EXISTS recent ( channel text, site_name text, article_title text, article_url text )") + cur.execute("CREATE TABLE IF NOT EXISTS recent ( channel text, site_title text, article_title text, article_url text )") cur.execute("SELECT * FROM rss") - for row in cur: feed_channel = row[0] - feed_site_name = row[1] + feed_site_title = row[1] feed_url = row[2] feed_fg = row[3] feed_bg = row[4] @@ -137,13 +168,12 @@ def read_feeds(willie): except IOError, E: willie.say("Can't parse, " + str(E)) entry = fp.entries[0] - if not feed_fg and not feed_bg: - site_name_effect = "[\x02%s\x02]" % (feed_site_name) + site_title_effect = "[\x02%s\x02]" % (feed_site_title) elif feed_fg and not feed_bg: - site_name_effect = "[\x02\x03%s%s\x03\x02]" % (feed_fg, feed_site_name) + site_title_effect = "[\x02\x03%s%s\x03\x02]" % (feed_fg, feed_site_title) elif feed_fg and feed_bg: - site_name_effect = "[\x02\x03%s,%s%s\x03\x02]" % (feed_fg, feed_bg, feed_site_name) + site_title_effect = "[\x02\x03%s,%s%s\x03\x02]" % (feed_fg, feed_bg, feed_site_title) if hasattr(entry, 'id'): article_url = entry.id @@ -151,76 +181,23 @@ def read_feeds(willie): article_url = entry.feedburner_origlink else: article_url = entry.links[0].href - - # only print if new entry - sql_text = (feed_channel, feed_site_name, entry.title, article_url) - cur.execute('SELECT * FROM recent WHERE channel = "%s" AND site_name = "%s" and article_title = "%s" AND article_url = "%s"' % SUB*4, sql_text) + args = tuple([feed_channel, feed_site_title, entry.title, article_url]) + cur.execute('SELECT * FROM recent WHERE channel = "%s" AND site_title = "%s" and article_title = "%s" AND article_url = "%s"' % args) if len(cur.fetchall()) < 1: - response = site_name_effect + " %s \x02%s\x02" % (entry.title, article_url) + response = site_title_effect + " %s \x02%s\x02" % (entry.title, article_url) if entry.updated: response += " - %s" % (entry.updated) willie.msg(feed_channel, response) - t = (feed_channel, feed_site_name, entry.title, article_url,) - cur.execute('INSERT INTO recent VALUES ("%s", "%s", "%s", "%s")' % SUB*4, t) + args = tuple([feed_channel, feed_site_title, entry.title, article_url]) + cur.execute('INSERT INTO recent VALUES ("%s", "%s", "%s", "%s")' % args) conn.commit() else: if DEBUG: - willie.msg(feed_channel, u"Skipping previously read entry: %s %s" % (site_name_effect, entry.title)) + willie.msg(feed_channel, u"Skipping previously read entry: %s %s" % (site_title_effect, entry.title)) conn.close() - -def startrss(willie, trigger): - """ Begin reading RSS feeds """ - if not trigger.admin: - willie.reply("You must be an admin to start up the RSS feeds.") - return - global first_run, restarted, DEBUG, INTERVAL, STOP - DEBUG = False - - query = trigger.group(2) - if query == '-v': - DEBUG = True - STOP = False - willie.reply("Debugging enabled.") - elif query == '-q': - DEBUG = False - STOP = False - willie.reply("Debugging disabled.") - elif query == '-i': - INTERVAL = trigger.group(3) - willie.reply("INTERVAL updated to: %s" % (str(INTERVAL))) - elif query == '--stop': - STOP = True - willie.reply("Stop parameter updated.") - - if first_run: - if DEBUG: - willie.say("Okay, I'll start rss fetching...") - first_run = False - else: - restarted = True - if DEBUG: - willie.say("Okay, I'll re-start rss...") - - if not STOP: - while True: - if STOP: - willie.reply("STOPPED") - first_run = False - STOP = False - break - if DEBUG: - willie.say("Rechecking feeds") - read_feeds(willie) - time.sleep(INTERVAL) - - if DEBUG: - willie.say("Stopped checking") -startrss.commands = ['startrss'] -startrss.priority = 'high' - if __name__ == '__main__': print __doc__.strip() From c1d3950c086f0a80090d932f4bf4afc1f75501ab Mon Sep 17 00:00:00 2001 From: tcki <teckie@game-proz.com> Date: Tue, 16 Apr 2013 21:26:21 +0000 Subject: [PATCH 2/6] rss rewrite and more tweaks --- willie/db.py | 0 willie/irc.py | 2 +- willie/modules/ping.py | 0 willie/modules/rss.py | 273 ++++++++++++++++------------------------- willie/modules/twit.py | 0 5 files changed, 106 insertions(+), 169 deletions(-) mode change 100755 => 100644 willie/db.py mode change 100755 => 100644 willie/modules/ping.py mode change 100755 => 100644 willie/modules/twit.py diff --git a/willie/db.py b/willie/db.py old mode 100755 new mode 100644 diff --git a/willie/irc.py b/willie/irc.py index d2716c9b9e..bcbb7628a9 100644 --- a/willie/irc.py +++ b/willie/irc.py @@ -314,7 +314,7 @@ def _ssl_recv(self, buffer_size): """ Replacement for self.recv() during SSL connections. From: http://evanfosmark.com/2010/09/ssl-support-in-asynchatasync_chat """ try: - data = self.read(buffer_size) + data = self.socket.read(buffer_size) if not data: self.handle_close() return '' diff --git a/willie/modules/ping.py b/willie/modules/ping.py old mode 100755 new mode 100644 diff --git a/willie/modules/rss.py b/willie/modules/rss.py index 8855d48ee4..e2b86fc8e4 100644 --- a/willie/modules/rss.py +++ b/willie/modules/rss.py @@ -8,196 +8,133 @@ """ import feedparser +import mechanize import socket import sys import time -DEBUG = False -socket.setdefaulttimeout(10) # seconds before giving up on the feed until next cycle -INTERVAL = 10 # seconds between checking for new updates -STOP = False -SUB = ('%s',) - -def checkdb(cursor): - cursor.execute("CREATE TABLE IF NOT EXISTS rss ( channel text, site_title text, site_url text, fg text, bg text)") - -def setup(willie): - global SUB - SUB = (willie.db.substitution,) def manage_rss(willie, trigger): - """ .rss [list|add|edit|del|start] <#channel> <title> <url> - no arguments needed with list or start, no url needed with delete (title optional). """ + """ .rss [list|add|del|start|stop|auth] <#channel> <title> <url> """ if not trigger.admin: - willie.reply("Sorry, you need to be an admin to modify or start the RSS feed.") return + DEBUG = False + INTERVAL = 10 + STOP = False + COOKIE = '' text = trigger.group().split() - if text[1] == 'start': - global first_run, restarted, DEBUG, INTERVAL, STOP - DEBUG = False - query = trigger.group(3) - if query == '-v': - DEBUG = True - STOP = False - willie.reply("Debugging enabled.") - elif query == '-q': - DEBUG = False - STOP = False - willie.reply("Debugging disabled.") - elif query == '-i': - INTERVAL = trigger.group(4) - willie.reply("INTERVAL updated to: %s" % (str(INTERVAL))) - elif query == '--stop': - STOP = True - willie.reply("Stop parameter updated.") - if first_run: + if DEBUG: + willie.reply(unicode(text)) + conn = willie.db.connect() + db = conn.cursor() + db.execute('CREATE TABLE IF NOT EXISTS feeds(channel text,title text,url text)') + db.execute('CREATE TABLE IF NOT EXISTS entries(channel text,url text)') + conn.commit() + if text[1] == 'list': + feeds = 0 + query = 'SELECT * FROM feeds' + if DEBUG: + willie.reply(query) + db.execute(query) + for row in db: + feeds += 1 + willie.reply('Feed: ' + unicode(row)) + if feeds == 0: + willie.reply('No feeds in database.') + elif text[1] == 'add': + query = 'INSERT INTO feeds VALUES("%s","%s","%s")' % (text[2], text[3], text[4]) + if DEBUG: + willie.reply(query) + db.execute(query) + conn.commit() + willie.reply('Successfully added feed to database.') + elif text[1] == 'del': + if len(text) == 3: + query = 'DELETE FROM feeds WHERE channel="%s"' % (text[2]) if DEBUG: - willie.say("Okay, I'll start rss fetching...") - first_run = False - else: - restarted = True + willie.reply(query) + db.execute(query) + conn.commit() + willie.reply('Successfully removed channel from database.') + elif len(text) > 3: + query = 'DELETE FROM feeds WHERE channel="%s" and title="%s"' % (text[2], text[3]) if DEBUG: - willie.say("Okay, I'll re-start rss...") + willie.reply(query) + db.execute(query) + conn.commit() + willie.reply('Successfully removed the feed from the given channel.') + elif text[1] == 'start': if not STOP: while True: + rows = 0 if STOP: - willie.reply("STOPPED") - first_run = False STOP = False break if DEBUG: - willie.say("Rechecking feeds") - read_feeds(willie) + willie.reply('Sync...') + db.execute('SELECT * FROM feeds') + for row in db: + rows += 1 + feed = { + 'channel': row[0], + 'title': row[1], + 'url': row[2] + } + try: + fp = feedparser.parse(feed['url']) + #extra_headers={'Cookie': COOKIE} + except IOError, E: + willie.reply('Invalid entry: ' + str(E)) + entry = fp.entries[0] + if hasattr(entry, 'id'): + entry_url = entry.id + else: + entry_url = entry.links[0].href + db.execute('SELECT * FROM entries WHERE channel="%s" AND url="%s"' % (feed['channel'], entry_url)) + if len(db.fetchall()) < 1: + message = '[\x02%s\x02] %s \x02%s\x02' % (feed['title'], entry.title, entry_url) + willie.msg(feed['channel'], message) + if DEBUG: + willie.reply('New entry: ' + message) + db.execute('INSERT INTO entries VALUES("%s","%s")' % (feed['channel'], entry_url)) + conn.commit() + else: + if DEBUG: + willie.reply('Old entry: ' + message) + if rows == 0: + STOP = True + willie.reply('No feeds in database.') + if DEBUG: + willie.reply('Done.') time.sleep(INTERVAL) if DEBUG: - willie.say("Stopped checking") - else: - conn = willie.db.connect() - c = conn.cursor() - checkdb(c) - conn.commit() - if len(text) < 2: - willie.reply("Proper usage: '.rss add #channel title url', '.rss del #channel title', '.rss del #channel'") - elif len(text) > 2: - channel = "#"+text[2].lower() - if len(text) > 4 and text[1] == 'add': - fg_colour = str() - bg_colour = str() - temp = trigger.group().split('"') - if len(temp) == 1: - site_title = text[3] - site_url = text[4] - if len(text) >= 6: - fg_colour = str(text[5]) - if len(text) == 7: - bg_colour = str(text[6]) - elif temp[-1].split(): - site_title = temp[1] - ending = temp[-1].split() - site_url = ending[0] - if len(ending) >= 2: - fg_colour = ending[1] - if len(ending) == 3: - bg_colour = ending[2] - else: - willie.reply("Not enough parameters specified.") - return - if fg_colour: - fg_colour = fg_colour.zfill(2) - if bg_colour: - bg_colour = bg_colour.zfill(2) - args = tuple([channel, site_title, site_url, fg_colour, bg_colour]) - c.execute('INSERT INTO rss VALUES ("%s","%s","%s","%s","%s")' % args) - conn.commit() - c.close() - willie.reply("Successfully added values to database.") - elif len(text) == 3 and text[1] == 'del': - args = tuple([channel]) - c.execute('DELETE FROM rss WHERE channel = "%s"' % args) - conn.commit() - c.close() - willie.reply("Successfully removed values from database.") - elif len(text) >= 4 and text[1] == 'del': - args = tuple([channel, " ".join(text[3:])]) - c.execute('DELETE FROM rss WHERE channel = "%s" and site_title = "%s"' % args) - conn.commit() - c.close() - willie.reply("Successfully removed the site from the given channel.") - elif len(text) == 2 and text[1] == 'list': - c.execute("SELECT * FROM rss") - k = 0 - for row in c: - k += 1 - willie.say("list: " + unicode(row)) - if k == 0: - willie.reply("No entries in database") - else: - willie.reply("Incorrect parameters specified.") - conn.close() -manage_rss.commands = ['rss'] -manage_rss.priority = 'low' - -class Feed(object): - modified = '' - -first_run = True -restarted = False -feeds = dict() - -def read_feeds(willie): - global restarted - global STOP - restarted = False - conn = willie.db.connect() - cur = conn.cursor() - checkdb(cur) - cur.execute("SELECT * FROM rss") - if not cur.fetchall(): + willie.reply('Stopped.') + elif text[1] == 'stop': STOP = True - willie.say("No RSS feeds found in database. Please add some rss feeds.") - - cur.execute("CREATE TABLE IF NOT EXISTS recent ( channel text, site_title text, article_title text, article_url text )") - cur.execute("SELECT * FROM rss") - for row in cur: - feed_channel = row[0] - feed_site_title = row[1] - feed_url = row[2] - feed_fg = row[3] - feed_bg = row[4] - try: - fp = feedparser.parse(feed_url) - except IOError, E: - willie.say("Can't parse, " + str(E)) - entry = fp.entries[0] - if not feed_fg and not feed_bg: - site_title_effect = "[\x02%s\x02]" % (feed_site_title) - elif feed_fg and not feed_bg: - site_title_effect = "[\x02\x03%s%s\x03\x02]" % (feed_fg, feed_site_title) - elif feed_fg and feed_bg: - site_title_effect = "[\x02\x03%s,%s%s\x03\x02]" % (feed_fg, feed_bg, feed_site_title) - - if hasattr(entry, 'id'): - article_url = entry.id - elif hasattr(entry, 'feedburner_origlink'): - article_url = entry.feedburner_origlink - else: - article_url = entry.links[0].href - args = tuple([feed_channel, feed_site_title, entry.title, article_url]) - cur.execute('SELECT * FROM recent WHERE channel = "%s" AND site_title = "%s" and article_title = "%s" AND article_url = "%s"' % args) - if len(cur.fetchall()) < 1: - - response = site_title_effect + " %s \x02%s\x02" % (entry.title, article_url) - if entry.updated: - response += " - %s" % (entry.updated) - - willie.msg(feed_channel, response) - - args = tuple([feed_channel, feed_site_title, entry.title, article_url]) - cur.execute('INSERT INTO recent VALUES ("%s", "%s", "%s", "%s")' % args) - conn.commit() - else: + willie.reply('Stopping...') + elif text[1] == 'auth': + response = mechanize.urlopen(mechanize.Request('http://alphachat.net/forums')) + forms = mechanize.ParseResponse(response, backwards_compat=False) + response.close() + forms[0]['login'] = 'tckibot' + forms[0]['password'] = '******' + response2 = mechanize.urlopen(forms[0].click()) + for name, value in response2.info().items(): if DEBUG: - willie.msg(feed_channel, u"Skipping previously read entry: %s %s" % (site_title_effect, entry.title)) + willie.reply('%s: %s' % (name.title(), value)) + if name.title() == 'Set-Cookie': + COOKIE = value + if COOKIE != '': + willie.reply('Authenticated successfully.') + else: + willie.reply('Failed to authenticate.') + response2.close() + else: + willie.reply('Incorrect parameters.') + db.close() conn.close() +manage_rss.commands = ['rss'] +manage_rss.priority = 'low' if __name__ == '__main__': print __doc__.strip() diff --git a/willie/modules/twit.py b/willie/modules/twit.py old mode 100755 new mode 100644 From 9a78e69296c950da6cb67d9b55a8cd7984ff81e4 Mon Sep 17 00:00:00 2001 From: tcki <teckie@game-proz.com> Date: Tue, 16 Apr 2013 21:49:10 +0000 Subject: [PATCH 3/6] ai tweaks --- willie/modules/ai.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/willie/modules/ai.py b/willie/modules/ai.py index e6f6d51a24..72f231589f 100644 --- a/willie/modules/ai.py +++ b/willie/modules/ai.py @@ -28,7 +28,7 @@ def ty(willie, trigger): mystr = str(mystr) if (mystr.find(" no ") == -1) and (mystr.find("no ") == -1) and (mystr.find(" no") == -1): willie.reply("You're welcome.") -ty.rule = '(?i).*(thank).*(you).*(willie|$nickname).*$' +ty.rule = '(?i).*(thank).*(you).*($nickname).*$' ty.priority = 'high' ty.rate = 30 @@ -41,7 +41,7 @@ def ty2(willie, trigger): def ty4(willie, trigger): ty(willie, trigger) -ty4.rule = '(?i).*(thanks).*(willie|$nickname).*' +ty4.rule = '(?i).*(thanks).*($nickname).*' ty4.rate = 40 @@ -55,7 +55,7 @@ def yesno(willie, trigger): willie.reply("no") elif text[0] == 'no': willie.reply("yes") -yesno.rule = '(willie|$nickname)\:\s+(yes|no)$' +yesno.rule = '($nickname)\:\s+(yes|no)$' yesno.rate = 15 @@ -64,25 +64,25 @@ def ping_reply(willie, trigger): text = text[1].split() if text[0] == 'PING' or text[0] == 'ping': willie.reply("PONG") -ping_reply.rule = '(?i)($nickname|willie)\:\s+(ping)\s*' +ping_reply.rule = '(?i)($nickname)\:\s+(ping)\s*' ping_reply.rate = 30 def love(willie, trigger): willie.reply("I love you too.") -love.rule = '(?i)i.*love.*(willie|$nickname).*' +love.rule = '(?i)i.*love.*($nickname).*' love.rate = 30 def love2(willie, trigger): willie.reply("I love you too.") -love2.rule = '(?i)(willie|$nickname)\:\si.*love.*' +love2.rule = '(?i)($nickname)\:\si.*love.*' love2.rate = 30 def love3(willie, trigger): willie.reply("I love you too.") -love3.rule = '(?i)(willie|$nickname)\,\si.*love.*' +love3.rule = '(?i)($nickname)\,\si.*love.*' love3.rate = 30 @@ -93,7 +93,7 @@ def f_lol(willie, trigger): randtime = random.uniform(0, 9) time.sleep(randtime) willie.say(random.choice(respond)) -f_lol.rule = '(haha!?|lol!?)$' +#f_lol.rule = '(haha!?|lol!?)$' f_lol.priority = 'high' From 8e80a6636275329f0bc94b63483efb6d15a8567d Mon Sep 17 00:00:00 2001 From: tcki <teckie@game-proz.com> Date: Tue, 16 Apr 2013 21:56:39 +0000 Subject: [PATCH 4/6] rss cleanup --- willie/modules/rss.py | 86 +++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/willie/modules/rss.py b/willie/modules/rss.py index e2b86fc8e4..ac99dd516b 100644 --- a/willie/modules/rss.py +++ b/willie/modules/rss.py @@ -64,49 +64,49 @@ def manage_rss(willie, trigger): conn.commit() willie.reply('Successfully removed the feed from the given channel.') elif text[1] == 'start': - if not STOP: - while True: - rows = 0 - if STOP: - STOP = False - break - if DEBUG: - willie.reply('Sync...') - db.execute('SELECT * FROM feeds') - for row in db: - rows += 1 - feed = { - 'channel': row[0], - 'title': row[1], - 'url': row[2] - } - try: - fp = feedparser.parse(feed['url']) - #extra_headers={'Cookie': COOKIE} - except IOError, E: - willie.reply('Invalid entry: ' + str(E)) - entry = fp.entries[0] - if hasattr(entry, 'id'): - entry_url = entry.id - else: - entry_url = entry.links[0].href - db.execute('SELECT * FROM entries WHERE channel="%s" AND url="%s"' % (feed['channel'], entry_url)) - if len(db.fetchall()) < 1: - message = '[\x02%s\x02] %s \x02%s\x02' % (feed['title'], entry.title, entry_url) - willie.msg(feed['channel'], message) - if DEBUG: - willie.reply('New entry: ' + message) - db.execute('INSERT INTO entries VALUES("%s","%s")' % (feed['channel'], entry_url)) - conn.commit() - else: - if DEBUG: - willie.reply('Old entry: ' + message) - if rows == 0: - STOP = True - willie.reply('No feeds in database.') - if DEBUG: - willie.reply('Done.') - time.sleep(INTERVAL) + willie.reply('Started.') + while True: + rows = 0 + if STOP: + STOP = False + break + if DEBUG: + willie.reply('Sync...') + db.execute('SELECT * FROM feeds') + for row in db: + rows += 1 + feed = { + 'channel': row[0], + 'title': row[1], + 'url': row[2] + } + try: + fp = feedparser.parse(feed['url']) + #extra_headers={'Cookie': COOKIE} + except IOError, E: + willie.reply('Invalid entry: ' + str(E)) + entry = fp.entries[0] + if hasattr(entry, 'id'): + entry_url = entry.id + else: + entry_url = entry.links[0].href + db.execute('SELECT * FROM entries WHERE channel="%s" AND url="%s"' % (feed['channel'], entry_url)) + if len(db.fetchall()) < 1: + message = '[\x02%s\x02] %s \x02%s\x02' % (feed['title'], entry.title, entry_url) + willie.msg(feed['channel'], message) + if DEBUG: + willie.reply('New entry: ' + message) + db.execute('INSERT INTO entries VALUES("%s","%s")' % (feed['channel'], entry_url)) + conn.commit() + else: + if DEBUG: + willie.reply('Old entry: ' + message) + if rows == 0: + STOP = True + willie.reply('No feeds in database.') + if DEBUG: + willie.reply('Done.') + time.sleep(INTERVAL) if DEBUG: willie.reply('Stopped.') elif text[1] == 'stop': From eb44c794cbc54a3be8582ca2dfc547f30b8d0b4b Mon Sep 17 00:00:00 2001 From: tcki <teckie@game-proz.com> Date: Tue, 16 Apr 2013 22:21:03 +0000 Subject: [PATCH 5/6] rss debug argument, auth config, tweaks --- willie/modules/rss.py | 57 +++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/willie/modules/rss.py b/willie/modules/rss.py index ac99dd516b..8d2bf0c055 100644 --- a/willie/modules/rss.py +++ b/willie/modules/rss.py @@ -13,18 +13,31 @@ import sys import time +COOKIE = '' +DEBUG = False +INTERVAL = 10 +STOP = False + +def checkConfig(willie): + if not willie.config.has_option('rss', 'auth_url') or not willie.config.has_option('rss', 'auth_user') or not willie.config.has_option('rss', 'auth_pass'): + return False + else: + return [willie.config.rss.auth_url, willie.config.rss.auth_user, willie.config.rss.auth_pass] + +def configure(config): + chunk = '' + if config.option('Configuring RSS module', False): + config.interactive_add('rss', 'auth_url', 'RSS authentication page', '') + config.interactive_add('rss', 'auth_user', 'RSS authentication user', '') + config.interactive_add('rss', 'auth_pass', 'RSS authentication password', '') + return chunk def manage_rss(willie, trigger): - """ .rss [list|add|del|start|stop|auth] <#channel> <title> <url> """ + """ .rss [list|add|del|start|stop|auth|debug] <#channel> <title> <url> """ if not trigger.admin: return - DEBUG = False - INTERVAL = 10 - STOP = False - COOKIE = '' + global COOKIE, DEBUG, INTERVAL, STOP text = trigger.group().split() - if DEBUG: - willie.reply(unicode(text)) conn = willie.db.connect() db = conn.cursor() db.execute('CREATE TABLE IF NOT EXISTS feeds(channel text,title text,url text)') @@ -71,7 +84,7 @@ def manage_rss(willie, trigger): STOP = False break if DEBUG: - willie.reply('Sync...') + willie.reply('Synchronizing...') db.execute('SELECT * FROM feeds') for row in db: rows += 1 @@ -81,8 +94,10 @@ def manage_rss(willie, trigger): 'url': row[2] } try: - fp = feedparser.parse(feed['url']) - #extra_headers={'Cookie': COOKIE} + if COOKIE != '': + fp = feedparser.parse(feed['url'], extra_headers={'Cookie': COOKIE}) + else: + fp = feedparser.parse(feed['url']) except IOError, E: willie.reply('Invalid entry: ' + str(E)) entry = fp.entries[0] @@ -102,22 +117,32 @@ def manage_rss(willie, trigger): if DEBUG: willie.reply('Old entry: ' + message) if rows == 0: - STOP = True willie.reply('No feeds in database.') + STOP = True if DEBUG: - willie.reply('Done.') + willie.reply('Synchronized.') time.sleep(INTERVAL) if DEBUG: willie.reply('Stopped.') elif text[1] == 'stop': - STOP = True willie.reply('Stopping...') + STOP = True + elif text[1] == 'debug': + if DEBUG: + willie.reply('Stopping debug.') + DEBUG = False + else: + willie.reply('Starting debug.') + DEBUG = True elif text[1] == 'auth': - response = mechanize.urlopen(mechanize.Request('http://alphachat.net/forums')) + if DEBUG: + willie.reply('Authenticating as %s on %s...' % (cfg[1], cfg[0])) + cfg = checkConfig(willie) + response = mechanize.urlopen(mechanize.Request(cfg[0])) forms = mechanize.ParseResponse(response, backwards_compat=False) response.close() - forms[0]['login'] = 'tckibot' - forms[0]['password'] = '******' + forms[0]['login'] = cfg[1] + forms[0]['password'] = cfg[2] response2 = mechanize.urlopen(forms[0].click()) for name, value in response2.info().items(): if DEBUG: From 06c45da23cbc5bf945f1b7702f1b5ea71d4045ae Mon Sep 17 00:00:00 2001 From: tcki <teckie@game-proz.com> Date: Tue, 16 Apr 2013 22:25:49 +0000 Subject: [PATCH 6/6] message & config bugfixes --- willie/modules/rss.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/willie/modules/rss.py b/willie/modules/rss.py index 8d2bf0c055..d5afc61d66 100644 --- a/willie/modules/rss.py +++ b/willie/modules/rss.py @@ -106,8 +106,8 @@ def manage_rss(willie, trigger): else: entry_url = entry.links[0].href db.execute('SELECT * FROM entries WHERE channel="%s" AND url="%s"' % (feed['channel'], entry_url)) + message = '[\x02%s\x02] %s \x02%s\x02' % (feed['title'], entry.title, entry_url) if len(db.fetchall()) < 1: - message = '[\x02%s\x02] %s \x02%s\x02' % (feed['title'], entry.title, entry_url) willie.msg(feed['channel'], message) if DEBUG: willie.reply('New entry: ' + message) @@ -135,9 +135,9 @@ def manage_rss(willie, trigger): willie.reply('Starting debug.') DEBUG = True elif text[1] == 'auth': + cfg = checkConfig(willie) if DEBUG: willie.reply('Authenticating as %s on %s...' % (cfg[1], cfg[0])) - cfg = checkConfig(willie) response = mechanize.urlopen(mechanize.Request(cfg[0])) forms = mechanize.ParseResponse(response, backwards_compat=False) response.close()