Started trying to make factoids useful.

This commit is contained in:
Jeremy Fincher 2003-04-29 13:25:40 +00:00
parent 737f35c99d
commit b1e95f8b64
1 changed files with 14 additions and 8 deletions

View File

@ -67,7 +67,7 @@ class Factoids(ChannelDBHandler, callbacks.Privmsg):
cursor = db.cursor() cursor = db.cursor()
cursor.execute("""CREATE TABLE keys ( cursor.execute("""CREATE TABLE keys (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
key TEXT, key TEXT UNIQUE ON CONFLICT IGNORE,
locked BOOLEAN locked BOOLEAN
)""") )""")
cursor.execute("""CREATE TABLE factoids ( cursor.execute("""CREATE TABLE factoids (
@ -86,10 +86,16 @@ class Factoids(ChannelDBHandler, callbacks.Privmsg):
db.commit() db.commit()
return db return db
def addfactoid(self, irc, msg, args): def add(self, irc, msg, args):
"[<channel>] (If not sent in the channel itself) <key> <value>" """[<channel>] <key> as <value>
Associates <key> with <value>. <channel> is only necessary if the
message isn't sent on the channel itself.
"""
channel = privmsgs.getChannel(msg, args) channel = privmsgs.getChannel(msg, args)
(key, factoid) = privmsgs.getArgs(args, needed=2) (key, as, factoid) = privmsgs.getArgs(args, needed=3)
if as != 'as':
raise callbacks.ArgumentError
db = self.getDb(channel) db = self.getDb(channel)
cursor = db.cursor() cursor = db.cursor()
cursor.execute("""SELECT id, locked FROM keys WHERE key=%s""", key) cursor.execute("""SELECT id, locked FROM keys WHERE key=%s""", key)
@ -115,7 +121,7 @@ class Factoids(ChannelDBHandler, callbacks.Privmsg):
else: else:
irc.error(msg, 'That factoid is locked.') irc.error(msg, 'That factoid is locked.')
def lookupfactoid(self, irc, msg, args): def lookup(self, irc, msg, args):
"[<channel>] (If not sent in the channel itself) <key> [<number>]" "[<channel>] (If not sent in the channel itself) <key> [<number>]"
channel = privmsgs.getChannel(msg, args) channel = privmsgs.getChannel(msg, args)
(key, number) = privmsgs.getArgs(args, optional=1) (key, number) = privmsgs.getArgs(args, optional=1)
@ -136,7 +142,7 @@ class Factoids(ChannelDBHandler, callbacks.Privmsg):
factoid = results[number][0] factoid = results[number][0]
irc.reply(msg, '%s/%s: %s' % (key, number, factoid)) irc.reply(msg, '%s/%s: %s' % (key, number, factoid))
def lockfactoid(self, irc, msg, args): def lock(self, irc, msg, args):
"[<channel>] (If not sent in the channel itself) <key>" "[<channel>] (If not sent in the channel itself) <key>"
channel = privmsgs.getChannel(msg, args) channel = privmsgs.getChannel(msg, args)
key = privmsgs.getArgs(args) key = privmsgs.getArgs(args)
@ -150,7 +156,7 @@ class Factoids(ChannelDBHandler, callbacks.Privmsg):
else: else:
irc.error(msg, conf.replyNoCapability % capability) irc.error(msg, conf.replyNoCapability % capability)
def unlockfactoid(self, irc, msg, args): def unlock(self, irc, msg, args):
"[<channel>] (If not sent in the channel itself) <key>" "[<channel>] (If not sent in the channel itself) <key>"
channel = privmsgs.getChannel(msg, args) channel = privmsgs.getChannel(msg, args)
key = privmsgs.getArgs(args) key = privmsgs.getArgs(args)
@ -164,7 +170,7 @@ class Factoids(ChannelDBHandler, callbacks.Privmsg):
else: else:
irc.error(msg, conf.replyNoCapability % capability) irc.error(msg, conf.replyNoCapability % capability)
def removefactoid(self, irc, msg, args): def remove(self, irc, msg, args):
"[<channel>] (If not sent in the channel itself) <key>" "[<channel>] (If not sent in the channel itself) <key>"
channel = privmsgs.getChannel(msg, args) channel = privmsgs.getChannel(msg, args)
key = privmsgs.getArgs(args) key = privmsgs.getArgs(args)