Fixed some bugs in some callCommands, as well as used some super calls where before we did it the wrong way.

This commit is contained in:
Jeremy Fincher 2004-09-01 04:55:08 +00:00
parent 6df7dd7bb7
commit 82791571c1
5 changed files with 67 additions and 18 deletions

View File

@ -89,7 +89,7 @@ class Amazon(callbacks.PrivmsgCommandAndRegexp):
def callCommand(self, method, irc, msg, *L, **kwargs): def callCommand(self, method, irc, msg, *L, **kwargs):
try: try:
callbacks.PrivmsgCommandAndRegexp.callCommand(self, method, irc, msg, *L, **kwargs) super(Amazon, self).callCommand(method, irc, msg, *L, **kwargs)
except amazon.NoLicenseKey, e: except amazon.NoLicenseKey, e:
irc.error('You must have a free Amazon web services license key ' irc.error('You must have a free Amazon web services license key '
'in order to use this command. You can get one at ' 'in order to use this command. You can get one at '

View File

@ -52,13 +52,14 @@ import supybot.ircmsgs as ircmsgs
import supybot.ircutils as ircutils import supybot.ircutils as ircutils
import supybot.privmsgs as privmsgs import supybot.privmsgs as privmsgs
import supybot.registry as registry import supybot.registry as registry
import supybot.webutils as webutils
import supybot.callbacks as callbacks import supybot.callbacks as callbacks
try: ## try:
import sqlite ## import sqlite
except ImportError: ## except ImportError:
raise callbacks.Error, 'You need to have PySQLite installed to use this ' \ ## raise callbacks.Error, 'You need to have PySQLite installed to use this ' \
'plugin. Download it at <http://pysqlite.sf.net/>' ## 'plugin. Download it at <http://pysqlite.sf.net/>'
conf.registerPlugin('Infobot') conf.registerPlugin('Infobot')
conf.registerGlobalValue(conf.supybot.plugins.Infobot, 'personality', conf.registerGlobalValue(conf.supybot.plugins.Infobot, 'personality',
@ -133,9 +134,12 @@ class PickleInfobotDB(object):
self._changes = 0 self._changes = 0
else: else:
try: try:
(self._is, self._are) = pickle.load(fd) try:
except cPickle.UnpicklingError, e: (self._is, self._are) = pickle.load(fd)
raise dbi.InvalidDBError, str(e) except cPickle.UnpicklingError, e:
raise dbi.InvalidDBError, str(e)
finally:
fd.close()
def flush(self): def flush(self):
fd = utils.transactionalFile(filename, 'wb') fd = utils.transactionalFile(filename, 'wb')
@ -363,7 +367,7 @@ class SqliteInfobotDB(object):
return areFacts + isFacts return areFacts + isFacts
def InfobotDB(): def InfobotDB():
return SqliteInfobotDB() return PickleInfobotDB()
class Dunno(Exception): class Dunno(Exception):
pass pass
@ -524,7 +528,7 @@ class Infobot(callbacks.PrivmsgCommandAndRegexp):
if payload.endswith(irc.nick): if payload.endswith(irc.nick):
self.addressed = True self.addressed = True
payload = payload[:-len(irc.nick)] payload = payload[:-len(irc.nick)]
payload = payload.strip(', ') # Strip punctuation separating nick. payload = payload.strip(', ') # Strip punctuation before nick.
payload += '?' # So doUnknown gets called. payload += '?' # So doUnknown gets called.
if not payload.strip(): if not payload.strip():
self.log.debug('Bailing since we received an empty msg.') self.log.debug('Bailing since we received an empty msg.')
@ -541,8 +545,7 @@ class Infobot(callbacks.PrivmsgCommandAndRegexp):
try: try:
self.irc = irc self.irc = irc
self.msg = msg self.msg = msg
callbacks.PrivmsgCommandAndRegexp.callCommand(self, f, irc, msg, super(Infobot, self).callCommand(f, irc, msg, *L, **kwargs)
*L, **kwargs)
finally: finally:
self.irc = None self.irc = None
self.msg = None self.msg = None
@ -699,6 +702,52 @@ class Infobot(callbacks.PrivmsgCommandAndRegexp):
except Dunno: except Dunno:
self.dunno() self.dunno()
def update(self, irc, msg, args):
"""{is,are} <url>
Updates the Infobot database using the dumped database at <url>. The
first argument should be "is" or "are", and determines whether the is
or are database is updated.
"""
(isAre, url) = privmsgs.getArgs(args, required=2)
isAre = isAre.lower()
if isAre == 'is':
add = self.db.setIs
elif isAre == 'are':
add = self.db.setAre
else:
raise callbacks.ArgumentError
count = 0
fd = webutils.getUrlFd(url)
for line in fd:
line = line.rstrip('\r\n')
try:
(key, value) = line.split(' => ', 1)
except ValueError: #unpack list of wrong size
self.log.debug('Invalid line: %r', line)
continue
else:
key = key.rstrip()
value = value.lstrip()
self.log.debug('Adding factoid %r with value %r.', key, value)
add(key, value)
count += 1
irc.replySuccess('%s added.' % utils.nItems('factoid', count))
update = privmsgs.checkCapability(update, 'owner')
def dump(self, irc, msg, args):
"""<filename>
Dumps the current Infobot database into a flatfile named <filename>.
<filename> is put in the data directory if no directory is specified.
"""
filename = privmsgs.getArgs(args)
if filename == os.path.basename(filename):
filename = conf.supybot.directories.data.dirize(filename)
fd = utils.transactionalFile(filename)
Class = Infobot Class = Infobot

View File

@ -84,9 +84,9 @@ class Weather(callbacks.Privmsg):
the name of 'weather' which should override this help.""" the name of 'weather' which should override this help."""
weatherCommands = ['ham', 'cnn', 'wunder'] weatherCommands = ['ham', 'cnn', 'wunder']
threaded = True threaded = True
def callCommand(self, method, irc, msg, *L): def callCommand(self, method, irc, msg, *L, **kwargs):
try: try:
callbacks.Privmsg.callCommand(self, method, irc, msg, *L) super(Weather, self).callCommand(method, irc, msg, *L, **kwargs)
except webutils.WebError, e: except webutils.WebError, e:
irc.error(str(e)) irc.error(str(e))

View File

@ -191,7 +191,7 @@ class WordStats(callbacks.Privmsg):
def callCommand(self, *args, **kwargs): def callCommand(self, *args, **kwargs):
self.queried = True self.queried = True
return callbacks.Privmsg.callCommand(self, *args, **kwargs) return super(WordStats, self).callCommand(*args, **kwargs)
def doPrivmsg(self, irc, msg): def doPrivmsg(self, irc, msg):
# This depends on the fact that it's called after the command. # This depends on the fact that it's called after the command.

View File

@ -133,10 +133,10 @@ class HangmanGame:
class Words(callbacks.Privmsg): class Words(callbacks.Privmsg):
def callCommand(self, command, irc, msg, args): def callCommand(self, command, irc, msg, args, *L, **kw):
# We'll catch the IOError here. # We'll catch the IOError here.
try: try:
callbacks.Privmsg.callCommand(self, command, irc, msg, args) super(Words, self).callCommand(command, irc, msg, args, *L, **kw)
except EnvironmentError, e: except EnvironmentError, e:
irc.error('I couldn\'t open the words file. This plugin expects ' irc.error('I couldn\'t open the words file. This plugin expects '
'a words file (i.e., a file with one word per line, in ' 'a words file (i.e., a file with one word per line, in '