diff --git a/Bantracker/plugin.py b/Bantracker/plugin.py index 1d5f13a..27101fa 100644 --- a/Bantracker/plugin.py +++ b/Bantracker/plugin.py @@ -171,7 +171,7 @@ class Bantracker(callbacks.Plugin): def doQuit(self, irc, msg): for (channel, chan) in self.lastStates[irc].channels.iteritems(): if msg.nick in chan.users: - self.doLog(irc, channel, '*** %s has quit IRC\n' % msg.nick) + self.doLog(irc, channel, '*** %s has quit IRC (%s)\n' % (msg.nick, msg.args[0])) def outFilter(self, irc, msg): # Gotta catch my own messages *somehow* :) diff --git a/Bugtracker/plugin.py b/Bugtracker/plugin.py index 295fda4..eff48cf 100644 --- a/Bugtracker/plugin.py +++ b/Bugtracker/plugin.py @@ -327,7 +327,7 @@ class Bugtracker(callbacks.PluginRegexp): def oopsSnarfer(self, irc, msg, match): r"OOPS-(?P\d*[A-Z]\d+)" oopsid = match.group(1) - irc.reply("https://chinstrap.ubuntu.com/~jamesh/oops.cgi/%s" % oopsid, prefixNick=False) + irc.reply("https://devpad.canonical.com/~jamesh/oops.cgi/%s" % oopsid, prefixNick=False) def get_tracker(self,snarfurl,sfdata): for t in self.db.keys(): diff --git a/Encyclopedia/__init__.py b/Encyclopedia/__init__.py index 57867a4..3b40c1e 100644 --- a/Encyclopedia/__init__.py +++ b/Encyclopedia/__init__.py @@ -28,8 +28,7 @@ __contributors__ = {} __url__ = '' # 'http://supybot.com/Members/yourname/Factoid plugin/download' import config -import plugin -reload(plugin) # In case we're being reloaded. +reload(config) import plugin_ng reload(plugin_ng) # Add more reloads here if you add third-party modules and want them to be @@ -38,7 +37,6 @@ reload(plugin_ng) if world.testing: import test -Class = plugin.Class Class = plugin_ng.Class configure = config.configure diff --git a/Encyclopedia/config.py b/Encyclopedia/config.py index 8ebe274..8f81a58 100644 --- a/Encyclopedia/config.py +++ b/Encyclopedia/config.py @@ -23,6 +23,14 @@ Encyclopedia = conf.registerPlugin('Encyclopedia') # registry.Boolean(False, """Help for someConfigVariableName.""")) conf.registerChannelValue(Encyclopedia, 'database', registry.String('', 'Name of database to use')) +conf.registerGlobalValue(Encyclopedia, 'packagelookup', + registry.Boolean(True, "Whether to look up packages")) +conf.registerChannelValue(Encyclopedia, 'fallbackdb', + registry.String('ubuntu', 'Fallback database')) +conf.registerGlobalValue(Encyclopedia, 'fallbackchannel', + registry.String('#ubuntu', 'Fallback channel')) +conf.registerGlobalValue(Encyclopedia, 'relaychannel', + registry.String('#ubuntu-ops', 'Relay channel for unauthorized edits')) # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: diff --git a/Encyclopedia/factoids.cgi b/Encyclopedia/factoids.cgi index fa3f99a..2b4cee8 100755 --- a/Encyclopedia/factoids.cgi +++ b/Encyclopedia/factoids.cgi @@ -47,25 +47,43 @@ except: con = sqlite.connect('/home/dennis/ubugtu/data/facts/%s.db' % database) cur = con.cursor() -cur.execute("""SELECT COUNT(*) FROM facts WHERE value NOT LIKE '%%'""") -num = cur.fetchall()[0][0] -npages = int(ceil(num / float(NUM_PER_PAGE))) -out('·') -for i in range(npages): - out(' %d ·' % (database, order_by, i, i+1)) -out('
Order by
·') -out(' %s ·' % (database, 'name ASC', page, 'Name +')) -out(' %s ·' % (database, 'name DESC', page, 'Name -')) -out(' %s ·' % (database, 'popularity ASC', page, 'Popularity +')) -out(' %s ·' % (database, 'popularity DESC', page, 'Popularity -')) -out(' %s ·' % (database, 'added ASC', page, 'Date added +')) -out(' %s ·' % (database, 'added DESC', page, 'Date added -')) - +if 'search' not in form: + cur.execute("""SELECT COUNT(*) FROM facts WHERE value NOT LIKE '%%'""") + num = cur.fetchall()[0][0] + npages = int(ceil(num / float(NUM_PER_PAGE))) + out('·') + for i in range(npages): + out(' %d ·' % (database, order_by, i, i+1)) + out('
Order by
·') + out(' %s ·' % (database, 'name ASC', page, 'Name +')) + out(' %s ·' % (database, 'name DESC', page, 'Name -')) + out(' %s ·' % (database, 'popularity ASC', page, 'Popularity +')) + out(' %s ·' % (database, 'popularity DESC', page, 'Popularity -')) + out(' %s ·' % (database, 'added ASC', page, 'Date added +')) + out(' %s ·' % (database, 'added DESC', page, 'Date added -')) out('') -cur.execute("SELECT name, value, author, added, popularity FROM facts WHERE value NOT LIKE '%%' AND name NOT LIKE '%%-also' ORDER BY %s LIMIT %d, %d" % (order_by, page*NUM_PER_PAGE, NUM_PER_PAGE)) -factoids = cur.fetchall() +if 'search' in form: + keys = form['search'].value.split()[:5] + ret = {} + for k in keys: + k = k.replace("'","\'") + cur.execute("SELECT name, value, author, added, popularity FROM facts WHERE name LIKE '%%%s%%' OR VAlUE LIKE '%%%s%%'" % (k, k)) + res = cur.fetchall() + for r in res: + r0 = r[0] + try: + ret[r][1] += 1 + except: + ret[r0] = (r, 1) + keys = sorted(ret.keys(), lambda x, y: cmp(ret[x][1], ret[y][1])) + factoids = [] + for k in keys[:50]: + factoids.append(ret[k][0]) +else: + cur.execute("SELECT name, value, author, added, popularity FROM facts WHERE value NOT LIKE '%%' AND name NOT LIKE '%%-also' ORDER BY %s LIMIT %d, %d" % (order_by, page*NUM_PER_PAGE, NUM_PER_PAGE)) + factoids = cur.fetchall() i = 0 for f in factoids: f = list(f) diff --git a/Encyclopedia/factoids.tmpl b/Encyclopedia/factoids.tmpl index 0a91aef..62dc876 100644 --- a/Encyclopedia/factoids.tmpl +++ b/Encyclopedia/factoids.tmpl @@ -127,13 +127,17 @@ div.log { More help: wiki.ubuntu.com · help.ubuntu.com
More factoids: Ubuntu · -buntudot +buntudot · +GNewSense
+
+

%s

Ubuntu factoid database file
Buntudot factoid database file
+GNewSense factoid database file
©2006 Dennis Kaarsemaker

diff --git a/Encyclopedia/plugin_ng.py b/Encyclopedia/plugin_ng.py index 87bf6be..00128b9 100644 --- a/Encyclopedia/plugin_ng.py +++ b/Encyclopedia/plugin_ng.py @@ -18,14 +18,12 @@ from email import FeedParser import re, os, fcntl, time apt_pkg.init() -fallback = ('ubuntu', '#ubuntu') datadir = '/home/dennis/ubugtu/data/facts' aptdir = '/home/dennis/ubugtu/data/apt' -relaychannel = '#ubuntu-ops' distros = ('dapper','breezy','edgy','hoary','warty','dapper-commercial','dapper-seveas','breezy-seveas','dapper-imbrandon','edgy-imbrandon') -# Keep 'earchistros' in search order! -searchdistros = ('dapper','dapper-commercial','dapper-seveas','dapper-imbrandon') defaultdistro = 'dapper' +# Keep 'searchistros' in search order! +searchdistros = ('dapper','dapper-commercial','dapper-seveas','dapper-imbrandon') # Simple wrapper class for factoids class Factoid: @@ -127,28 +125,29 @@ class Encyclopedia(callbacks.Plugin): # XXX these 3 belong in a different plugin, but hey if text.lower()[:4] in ('info','seen','find'): text = text.lower() - if text.startswith('info '): - irc.reply(pkginfo(text[5:].strip())) - return - if text.startswith('find '): - irc.reply(findpkg(text[5:].strip())) - return - if text.startswith('seen '): - self.seens[text[5:].strip()] = (target, time.time()) - queue(irc, 'seenserv', "seen %s" % text[5:].strip()) - return + if self.registryValue('packagelookup'): + if text.startswith('info '): + queue(irc, target, pkginfo(text[5:].strip())) + return + if text.startswith('find '): + queue(irc, target, findpkg(text[5:].strip())) + return + if text.startswith('seen '): + self.seens[text[5:].strip()] = (target, time.time()) + queue(irc, 'seenserv', "seen %s" % text[5:].strip()) + return # Factoid manipulation db = self.registryValue('database',channel) if not db: - db,channel = fallback + db,channel = self.registryValue('fallbackdb'), self.registryValue('fallbackchannel') if channel not in self.databases: self.databases[channel] = sqlite.connect(os.path.join(datadir, '%s.db' % db)) self.databases[channel].name = db db = self.databases[channel] if text.lower().startswith('search '): - irc.reply(searchfactoid(text[7:].strip().lower())) + irc.reply(searchfactoid(db, text[7:].strip().lower())) return do_new = False if text.lower().startswith('forget '): @@ -165,7 +164,7 @@ class Encyclopedia(callbacks.Plugin): text = text.replace('is ','=~',1) if ' is ' in text and '=~' not in text: do_new = True - if text.lower().startswith('no '): + if text.lower()[:3] in ('no ','no,'): do_new = False text = text[3:].strip() if text.startswith('is '): @@ -186,8 +185,8 @@ class Encyclopedia(callbacks.Plugin): if '=~' in text: # Editing if not capab(msg.prefix, 'editfactoids'): - irc.queueMsg(ircmsgs.privmsg(relaychannel, "In %s, %s said: %s" % (msg.args[0], msg.nick, msg.args[1]))) - irc.reply("Your edit request has been forwarded to #ubuntu-ops. Thank you for your attention to detail",private=True) + irc.queueMsg(ircmsgs.privmsg(self.registryValue('relaychannel'), "In %s, %s said: %s" % (msg.args[0], msg.nick, msg.args[1]))) + irc.reply("Your edit request has been forwarded to %s. Thank you for your attention to detail",self.registryValue('relaychannel'),private=True) lfd = open('/home/dennis/public_html/botlogs/lock','a') fcntl.lockf(lfd, fcntl.LOCK_EX) fd = open('/home/dennis/public_html/botlogs/%s.log' % datetime.date.today().strftime('%Y-%m-%d'),'a') @@ -318,9 +317,12 @@ class Encyclopedia(callbacks.Plugin): break else: if not replied: - i = pkginfo(text) - if not i.startswith('Package'): - queue(irc, target, i) + if self.registryValue('packagelookup'): + i = pkginfo(text) + if not i.startswith('Package'): + queue(irc, target, i) + else: + irc.reply("Sorry, I don't know anything about %s - try searching on http://bots.ubuntulinux.nl/factoids.cgi" % text) else: irc.reply("Sorry, I don't know anything about %s - try searching on http://bots.ubuntulinux.nl/factoids.cgi" % text) for key in ('channel_secondary', 'global_secondary'): @@ -486,6 +488,22 @@ def get_factoids(db, name, channel, resolve = True, info = False): factoids.channel_secondary = factoid_info(db, factoids.channel_secondary, channel) return factoids +def searchfactoid(db, factoid): + keys = factoid.split()[:5] + cur = db.cursor() + ret = {} + for k in keys: + k = k.replace("'","\'") + cur.execute("SELECT name FROM facts WHERE name LIKE '%%%s%%' OR VAlUE LIKE '%%%s%%'" % (k, k)) + res = cur.fetchall() + for r in res: + r = r[0] + try: + ret[r] += 1 + except: + ret[r] = 1 + return 'Found: %s' % ','.join(sorted(ret.keys(), lambda x, y: cmp(ret[x], ret[y]))[:10]) + def factoid_info(db,factoid,channel): if factoid: if not factoid.value.startswith(''): diff --git a/Webcal/plugin.py b/Webcal/plugin.py index e316870..fd7b198 100644 --- a/Webcal/plugin.py +++ b/Webcal/plugin.py @@ -207,6 +207,10 @@ class Webcal(callbacks.Plugin): now = wrap(now, [additional('text')]) time = now + def subscribe(self, irc, msg, args, meeting): + print meeting + subscribe = wrap(subscribe, ['text']) + # Warn people that you manage the topic def doTopic(self, irc, msg): if not self.registryValue('doTopic'):
FactoidValueAuthor