mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-23 10:34:19 +01:00
Replaced the last of the specific functions with the general getdb.
Fixed some sql statements and cleaned up some responses.
This commit is contained in:
parent
94e25c6c17
commit
0b6fce1e06
@ -146,24 +146,6 @@ class FunDB(callbacks.Privmsg):
|
|||||||
s = insult
|
s = insult
|
||||||
irc.queueMsg(ircmsgs.privmsg(means, s))
|
irc.queueMsg(ircmsgs.privmsg(means, s))
|
||||||
|
|
||||||
def getinsult(self, irc, msg, args):
|
|
||||||
"""<id>
|
|
||||||
|
|
||||||
Returns insult #<id>
|
|
||||||
"""
|
|
||||||
id = privmsgs.getArgs(args)
|
|
||||||
try:
|
|
||||||
id = int(id)
|
|
||||||
except ValueError:
|
|
||||||
irc.error(msg, 'The id must be an integer.')
|
|
||||||
return
|
|
||||||
cursor = self.db.cursor()
|
|
||||||
cursor.execute("""SELECT insult FROM insults WHERE id=%s""", id)
|
|
||||||
if cursor.rowcount == 0:
|
|
||||||
irc.error(msg, 'There is no such insult.')
|
|
||||||
else:
|
|
||||||
irc.reply(msg, cursor.fetchone()[0])
|
|
||||||
|
|
||||||
def crossword(self, irc, msg, args):
|
def crossword(self, irc, msg, args):
|
||||||
"""<word>
|
"""<word>
|
||||||
|
|
||||||
@ -194,24 +176,6 @@ class FunDB(callbacks.Privmsg):
|
|||||||
(id, excuse) = cursor.fetchone()
|
(id, excuse) = cursor.fetchone()
|
||||||
irc.reply(msg, '%s (#%s)' % (excuse, id))
|
irc.reply(msg, '%s (#%s)' % (excuse, id))
|
||||||
|
|
||||||
def getexcuse(self, irc, msg, args):
|
|
||||||
"""<id>
|
|
||||||
|
|
||||||
Gets the excuse with the id number <id>.
|
|
||||||
"""
|
|
||||||
id = privmsgs.getArgs(args)
|
|
||||||
try:
|
|
||||||
id = int(id)
|
|
||||||
except ValueError:
|
|
||||||
irc.error(msg, 'The id must be an integer.')
|
|
||||||
return
|
|
||||||
cursor = self.db.cursor()
|
|
||||||
cursor.execute("""SELECT excuse FROM excuses WHERE id=%s""", id)
|
|
||||||
if cursor.rowcount == 0:
|
|
||||||
irc.error(msg, 'There is no such excuse.')
|
|
||||||
else:
|
|
||||||
irc.reply(msg, cursor.fetchone()[0])
|
|
||||||
|
|
||||||
def adddb(self, irc, msg, args):
|
def adddb(self, irc, msg, args):
|
||||||
"""<lart|excuse|insult|praise> <text>
|
"""<lart|excuse|insult|praise> <text>
|
||||||
|
|
||||||
@ -225,11 +189,12 @@ class FunDB(callbacks.Privmsg):
|
|||||||
'somewhere.')
|
'somewhere.')
|
||||||
return
|
return
|
||||||
elif table not in self._tables:
|
elif table not in self._tables:
|
||||||
irc.error(msg, '"%s" is an invalid choice. Must be one of: '\
|
irc.error(msg, '"%s" is not valid. Valid values include %s' % \
|
||||||
'lart, excuse, insult, praise.' % table)
|
(table, utils.commaAndify(self._tables)))
|
||||||
return
|
return
|
||||||
cursor = self.db.cursor()
|
cursor = self.db.cursor()
|
||||||
cursor.execute("""INSERT INTO %s VALUES (NULL, %s)""", table+'s', s)
|
sql = """INSERT INTO %ss VALUES (NULL, %%s)""" % table
|
||||||
|
cursor.execute(sql, s)
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
irc.reply(msg, conf.replySuccess)
|
irc.reply(msg, conf.replySuccess)
|
||||||
|
|
||||||
@ -247,11 +212,12 @@ class FunDB(callbacks.Privmsg):
|
|||||||
irc.error(msg, 'You must give a numeric id.')
|
irc.error(msg, 'You must give a numeric id.')
|
||||||
return
|
return
|
||||||
if table not in self._tables:
|
if table not in self._tables:
|
||||||
irc.error(msg, '"%s" is an invalid choice. Must be one of: '\
|
irc.error(msg, '"%s" is not valid. Valid values include %s' % \
|
||||||
'lart, excuse, insult, praise.' % table)
|
(table, utils.commaAndify(self._tables)))
|
||||||
return
|
return
|
||||||
cursor = self.db.cursor()
|
cursor = self.db.cursor()
|
||||||
cursor.execute("""DELETE FROM %s WHERE id=%s""", table+'s', id)
|
sql = """DELETE FROM %ss WHERE id=%%s""" % table
|
||||||
|
cursor.execute(sql, id)
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
irc.reply(msg, conf.replySuccess)
|
irc.reply(msg, conf.replySuccess)
|
||||||
|
|
||||||
@ -264,11 +230,12 @@ class FunDB(callbacks.Privmsg):
|
|||||||
table = privmsgs.getArgs(args)
|
table = privmsgs.getArgs(args)
|
||||||
table = str.lower(table)
|
table = str.lower(table)
|
||||||
if table not in self._tables:
|
if table not in self._tables:
|
||||||
irc.error(msg, '"%s" is an invalid choice. Must be one of: '\
|
irc.error(msg, '"%s" is not valid. Valid values include %s' % \
|
||||||
'lart, excuse, insult, praise.' % table)
|
(table, utils.commaAndify(self._tables)))
|
||||||
return
|
return
|
||||||
cursor = self.db.cursor()
|
cursor = self.db.cursor()
|
||||||
cursor.execute('SELECT count(*) FROM %s', table+'s')
|
sql = """SELECT count(*) FROM %ss""" % table
|
||||||
|
cursor.execute(sql)
|
||||||
total = cursor.fetchone()[0]
|
total = cursor.fetchone()[0]
|
||||||
irc.reply(msg, 'There are currently %s %s in my database' %\
|
irc.reply(msg, 'There are currently %s %s in my database' %\
|
||||||
(total,table+'s'))
|
(total,table+'s'))
|
||||||
@ -293,7 +260,7 @@ class FunDB(callbacks.Privmsg):
|
|||||||
sql = """SELECT %s FROM %ss WHERE id=%%s""" % (table, table)
|
sql = """SELECT %s FROM %ss WHERE id=%%s""" % (table, table)
|
||||||
cursor.execute(sql, id)
|
cursor.execute(sql, id)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
irc.error(msg, 'There is no such %s.' % column)
|
irc.error(msg, 'There is no such %s.' % table)
|
||||||
else:
|
else:
|
||||||
irc.reply(msg, cursor.fetchone()[0])
|
irc.reply(msg, cursor.fetchone()[0])
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user