Fixed RFE #828722 and removed Lookup's dependency on the Alias plugin.

This commit is contained in:
Jeremy Fincher 2003-12-01 23:02:31 +00:00
parent c8de1e8155
commit 602f92622c
2 changed files with 14 additions and 17 deletions

View File

@ -40,6 +40,7 @@ import plugins
import os import os
import re import re
import sys import sys
import types
import sqlite import sqlite
@ -104,9 +105,7 @@ class Lookup(callbacks.Privmsg):
try: try:
cursor.execute("""DROP TABLE %s""" % name) cursor.execute("""DROP TABLE %s""" % name)
db.commit() db.commit()
cb = irc.getCallback('Alias') delattr(self.__class__, name)
if cb is not None:
cb.removeAlias(name, evenIfLocked=True)
irc.reply(msg, conf.replySuccess) irc.reply(msg, conf.replySuccess)
except sqlite.DatabaseError: except sqlite.DatabaseError:
irc.error(msg, 'No such lookup exists.') irc.error(msg, 'No such lookup exists.')
@ -125,12 +124,7 @@ class Lookup(callbacks.Privmsg):
cursor = db.cursor() cursor = db.cursor()
try: try:
cursor.execute("""SELECT * FROM %s LIMIT 1""" % name) cursor.execute("""SELECT * FROM %s LIMIT 1""" % name)
cb = irc.getCallback('Alias') self.addCommand(name)
if cb is not None:
try:
cb.addAlias(irc, name, 'lookup %s @1' % name, lock=True)
except sys.modules[cb.__module__].AliasError, e:
pass
irc.reply(msg, conf.replySuccess) irc.reply(msg, conf.replySuccess)
except sqlite.DatabaseError: except sqlite.DatabaseError:
# Good, there's no such database. # Good, there's no such database.
@ -155,16 +149,19 @@ class Lookup(callbacks.Privmsg):
cursor.execute(sql, key, value) cursor.execute(sql, key, value)
cursor.execute("CREATE INDEX %s_keys ON %s (key)" % (name, name)) cursor.execute("CREATE INDEX %s_keys ON %s (key)" % (name, name))
db.commit() db.commit()
self.addCommand(name)
cb = irc.getCallback('Alias') cb = irc.getCallback('Alias')
if cb is not None:
try:
cb.addAlias(irc, name, 'lookup %s @1' % name, lock=True)
except sys.modules[cb.__module__].AliasError, e:
irc.error(msg, str(e))
return
irc.reply(msg, conf.replySuccess) irc.reply(msg, conf.replySuccess)
def lookup(self, irc, msg, args): def addCommand(self, name):
def f(self, irc, msg, args):
args.insert(0, name)
self._lookup(irc, msg, args)
f = types.FunctionType(f.func_code, f.func_globals,
f.func_name, closure=f.func_closure)
setattr(self.__class__, name, f)
def _lookup(self, irc, msg, args):
"""<name> <key> """<name> <key>
Looks up the value of <key> in the domain <name>. Looks up the value of <key> in the domain <name>.

View File

@ -42,7 +42,7 @@ import conf
if sqlite: if sqlite:
class LookupTestCase(PluginTestCase, PluginDocumentation): class LookupTestCase(PluginTestCase, PluginDocumentation):
plugins = ('Lookup', 'Alias') plugins = ('Lookup',)
d = { d = {
'foo': 'bar', 'foo': 'bar',
'bar': 'baz', 'bar': 'baz',