diff --git a/plugins/core_sieve.py b/plugins/core_sieve.py index a80fc35..ff9ed23 100755 --- a/plugins/core_sieve.py +++ b/plugins/core_sieve.py @@ -61,7 +61,6 @@ def sieve_suite(bot, input, func, kind, args): group_users = bot.config.get("permissions", {}).get(group, [])["users"] group_users = [_mask.lower() for _mask in group_users] for pattern in group_users: - print mask + pattern if fnmatch(mask, pattern): return input diff --git a/plugins/horoscope.py b/plugins/horoscope.py index d683f39..edacb23 100644 --- a/plugins/horoscope.py +++ b/plugins/horoscope.py @@ -2,11 +2,41 @@ from util import hook, http -@hook.command -def horoscope(inp): +db_ready = False + + +def db_init(db): + "check to see that our db has the horoscope table and return a connection." + db.execute("create table if not exists horoscope(nick primary key, sign)") + db.commit() + db_ready = True + + +@hook.command(autohelp=False) +def horoscope(inp, db=None, notice=None, nick=None): "horoscope -- Get your horoscope." - url = "http://my.horoscope.com/astrology/free-daily-horoscope-%s.html" % inp + if not db_ready: + db_init(db) + + # check if the user asked us not to save his details + dontsave = inp.endswith(" dontsave") + if dontsave: + sign = inp[:-9].strip().lower() + else: + sign = inp + + db.execute("create table if not exists horoscope(nick primary key, sign)") + + if not sign: + sign = db.execute("select sign from horoscope where nick=lower(?)", + (nick,)).fetchone() + if not sign: + notice(horoscope.__doc__) + return + sign = sign[0] + + url = "http://my.horoscope.com/astrology/free-daily-horoscope-%s.html" % sign soup = http.get_soup(url) title = soup.find_all('h1', {'class': 'h1b'})[1] @@ -18,4 +48,9 @@ def horoscope(inp): if not title: return "Could not get the horoscope for %s." % inp + if inp and not dontsave: + db.execute("insert or replace into horoscope(nick, sign) values (?,?)", + (nick.lower(), sign)) + db.commit() + return result \ No newline at end of file