mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Made randomfactoid more useful and fixed a bug in unlearn.
This commit is contained in:
parent
60c598be87
commit
2c2031e167
@ -43,6 +43,7 @@ import sqlite
|
|||||||
|
|
||||||
import conf
|
import conf
|
||||||
import ircdb
|
import ircdb
|
||||||
|
import ircutils
|
||||||
import privmsgs
|
import privmsgs
|
||||||
import callbacks
|
import callbacks
|
||||||
|
|
||||||
@ -93,11 +94,11 @@ class Factoids(ChannelDBHandler, callbacks.Privmsg):
|
|||||||
factoid = ' '.join(args[i:])
|
factoid = ' '.join(args[i:])
|
||||||
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 LIKE %s", key)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
cursor.execute("""INSERT INTO keys VALUES (NULL, %s, 0)""", key)
|
cursor.execute("""INSERT INTO keys VALUES (NULL, %s, 0)""", key)
|
||||||
db.commit()
|
db.commit()
|
||||||
cursor.execute("""SELECT id, locked FROM keys WHERE key=%s""", key)
|
cursor.execute("SELECT id, locked FROM keys WHERE key LIKE %s",key)
|
||||||
(id, locked) = map(int, cursor.fetchone())
|
(id, locked) = map(int, cursor.fetchone())
|
||||||
capability = ircdb.makeChannelCapability(channel, 'factoids')
|
capability = ircdb.makeChannelCapability(channel, 'factoids')
|
||||||
if not locked:
|
if not locked:
|
||||||
@ -128,7 +129,7 @@ class Factoids(ChannelDBHandler, callbacks.Privmsg):
|
|||||||
db = self.getDb(channel)
|
db = self.getDb(channel)
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute("""SELECT factoids.fact FROM factoids, keys WHERE
|
cursor.execute("""SELECT factoids.fact FROM factoids, keys WHERE
|
||||||
keys.key=%s AND factoids.key_id=keys.id
|
keys.key LIKE %s AND factoids.key_id=keys.id
|
||||||
ORDER BY factoids.id
|
ORDER BY factoids.id
|
||||||
LIMIT 20""", key)
|
LIMIT 20""", key)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
@ -160,7 +161,7 @@ class Factoids(ChannelDBHandler, callbacks.Privmsg):
|
|||||||
capability = ircdb.makeChannelCapability(channel, 'factoids')
|
capability = ircdb.makeChannelCapability(channel, 'factoids')
|
||||||
if ircdb.checkCapability(msg.prefix, capability):
|
if ircdb.checkCapability(msg.prefix, capability):
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute("""UPDATE keys SET locked = 1 WHERE key=%s""", key)
|
cursor.execute("UPDATE keys SET locked=1 WHERE key LIKE %s", key)
|
||||||
db.commit()
|
db.commit()
|
||||||
irc.reply(msg, conf.replySuccess)
|
irc.reply(msg, conf.replySuccess)
|
||||||
else:
|
else:
|
||||||
@ -179,7 +180,7 @@ class Factoids(ChannelDBHandler, callbacks.Privmsg):
|
|||||||
capability = ircdb.makeChannelCapability(channel, 'factoids')
|
capability = ircdb.makeChannelCapability(channel, 'factoids')
|
||||||
if ircdb.checkCapability(msg.prefix, capability):
|
if ircdb.checkCapability(msg.prefix, capability):
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute("""UPDATE keys SET locked = 0 WHERE key=%s""", key)
|
cursor.execute("UPDATE keys SET locked=0 WHERE key LIKE %s",key)
|
||||||
db.commit()
|
db.commit()
|
||||||
irc.reply(msg, conf.replySuccess)
|
irc.reply(msg, conf.replySuccess)
|
||||||
else:
|
else:
|
||||||
@ -194,7 +195,7 @@ class Factoids(ChannelDBHandler, callbacks.Privmsg):
|
|||||||
the message isn't sent in the channel itself.
|
the message isn't sent in the channel itself.
|
||||||
"""
|
"""
|
||||||
channel = privmsgs.getChannel(msg, args)
|
channel = privmsgs.getChannel(msg, args)
|
||||||
if args[-1].isdigit:
|
if args[-1].isdigit():
|
||||||
number = int(args.pop())
|
number = int(args.pop())
|
||||||
else:
|
else:
|
||||||
number = None
|
number = None
|
||||||
@ -205,14 +206,14 @@ class Factoids(ChannelDBHandler, callbacks.Privmsg):
|
|||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute("""SELECT keys.id, factoids.id
|
cursor.execute("""SELECT keys.id, factoids.id
|
||||||
FROM keys, factoids
|
FROM keys, factoids
|
||||||
WHERE key=%s AND
|
WHERE key LIKE %s AND
|
||||||
factoids.key_id=keys.id""", key)
|
factoids.key_id=keys.id""", key)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
irc.error(msg, 'There is no such factoid.')
|
irc.error(msg, 'There is no such factoid.')
|
||||||
elif cursor.rowcount == 1:
|
elif cursor.rowcount == 1:
|
||||||
(id, _) = cursor.fetchone()
|
(id, _) = cursor.fetchone()
|
||||||
cursor.execute("""DELETE FROM factoids WHERE key_id=%s""", id)
|
cursor.execute("""DELETE FROM factoids WHERE key_id=%s""", id)
|
||||||
cursor.execute("""DELETE FROM keys WHERE key=%s""", key)
|
cursor.execute("""DELETE FROM keys WHERE key LIKE %s""", key)
|
||||||
db.commit()
|
db.commit()
|
||||||
irc.reply(msg, conf.replySuccess)
|
irc.reply(msg, conf.replySuccess)
|
||||||
else:
|
else:
|
||||||
@ -244,12 +245,14 @@ class Factoids(ChannelDBHandler, callbacks.Privmsg):
|
|||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute("""SELECT fact, key_id FROM factoids
|
cursor.execute("""SELECT fact, key_id FROM factoids
|
||||||
ORDER BY random()
|
ORDER BY random()
|
||||||
LIMIT 1""")
|
LIMIT 10""")
|
||||||
if cursor.rowcount != 0:
|
if cursor.rowcount != 0:
|
||||||
(factoid, keyId) = cursor.fetchone()
|
L = []
|
||||||
cursor.execute("""SELECT key FROM keys WHERE id=%s""", keyId)
|
for (factoid, id) in cursor.fetchall():
|
||||||
key = cursor.fetchone()[0]
|
cursor.execute("""SELECT key FROM keys WHERE id=%s""", id)
|
||||||
irc.reply(msg, '%s: %s' % (key, factoid))
|
(key,) = cursor.fetchone()
|
||||||
|
L.append('"%s": %s' % (ircutils.bold(key), factoid))
|
||||||
|
irc.reply(msg, ircutils.privmsgPayload(L, '; ', 400))
|
||||||
else:
|
else:
|
||||||
irc.error(msg, 'I couldn\'t find a factoid.')
|
irc.error(msg, 'I couldn\'t find a factoid.')
|
||||||
|
|
||||||
@ -264,7 +267,7 @@ class Factoids(ChannelDBHandler, callbacks.Privmsg):
|
|||||||
key = privmsgs.getArgs(args)
|
key = privmsgs.getArgs(args)
|
||||||
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 LIKE %s", key)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
irc.error(msg, 'No factoid matches that key.')
|
irc.error(msg, 'No factoid matches that key.')
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user