mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-10-18 18:07:25 +02:00
and we're STILL fixing syntaxproblems
This commit is contained in:
parent
bce7b6fcd8
commit
5f77c05cad
@ -42,20 +42,16 @@ import privmsgs
|
|||||||
import callbacks
|
import callbacks
|
||||||
import ircutils
|
import ircutils
|
||||||
|
|
||||||
class Notes(DBHandler, callbacks.Privmsg):
|
class Notes(callbacks.Privmsg):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
DBHandler.__init__(self)
|
|
||||||
callbacks.Privmsg.__init__(self)
|
callbacks.Privmsg.__init__(self)
|
||||||
self.filename = os.path.join(conf.dataDir, 'Notes.db')
|
self.filename = os.path.join(conf.dataDir, 'Notes.db')
|
||||||
if os.path.exists(self.filename):
|
if os.path.exists(self.filename):
|
||||||
self.db = sqlite.connect(self.filename)
|
self.db = sqlite.connect(self.filename)
|
||||||
self.cursor = self.db.cursor()
|
self.cursor = self.db.cursor()
|
||||||
print "makeDB not called"
|
|
||||||
else:
|
else:
|
||||||
self.makeDB()
|
self.makeDB()
|
||||||
print "makeDB called"
|
|
||||||
|
|
||||||
|
|
||||||
def makeDB(self):
|
def makeDB(self):
|
||||||
"create Notes database and tables"
|
"create Notes database and tables"
|
||||||
@ -74,28 +70,24 @@ class Notes(DBHandler, callbacks.Privmsg):
|
|||||||
public BOOLEAN,
|
public BOOLEAN,
|
||||||
note TEXT
|
note TEXT
|
||||||
)""")
|
)""")
|
||||||
self.cursor.execute("""CREATE INDEX users_username
|
self.cursor.execute("""CREATE INDEX users_username ON users (name)""")
|
||||||
ON users (name)""")
|
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
|
|
||||||
def _addUser(self, username):
|
def _addUser(self, username):
|
||||||
"not callable from channel, used to add users to database"
|
"not callable from channel, used to add users to database"
|
||||||
self.cursor.execute("""INSERT INTO users
|
self.cursor.execute('INSERT INTO users VALUES (NULL,%s)' % username)
|
||||||
VALUES (NULL,'%s')""" % username)
|
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
|
|
||||||
def getUserID(self, username):
|
def getUserID(self, username):
|
||||||
self.cursor.execute("""SELECT id FROM users
|
self.cursor.execute('SELECT id FROM users where name=%s' % username)
|
||||||
where name='%s'""" % username)
|
|
||||||
if self.cursor.rowcount != 0:
|
if self.cursor.rowcount != 0:
|
||||||
results = self.cursor.fetchall()
|
results = self.cursor.fetchall()
|
||||||
return results[0]
|
return results[0]
|
||||||
else: # this should NEVER happen
|
else: # this should NEVER happen
|
||||||
return "ERROR LOOKING UP USERID"
|
assert False
|
||||||
|
|
||||||
def getUserName(self, userid):
|
def getUserName(self, userid):
|
||||||
self.cursor.execute("""SELECT name FROM users
|
self.cursor.execute('SELECT name FROM users WHERE id=%s' % userid)
|
||||||
WHERE id=%d""" % userid)
|
|
||||||
if self.cursor.rowcount != 0:
|
if self.cursor.rowcount != 0:
|
||||||
results = self.cursor.fetchall()
|
results = self.cursor.fetchall()
|
||||||
return results[0]
|
return results[0]
|
||||||
@ -105,9 +97,7 @@ class Notes(DBHandler, callbacks.Privmsg):
|
|||||||
def setNoteUnread(self, irc, msg, args):
|
def setNoteUnread(self, irc, msg, args):
|
||||||
"set a note as unread"
|
"set a note as unread"
|
||||||
noteid = privmsgs.getArgs(args)
|
noteid = privmsgs.getArgs(args)
|
||||||
self.cursor.execute("""UPDATE notes
|
self.cursor.execute('UPDATE notes SET read=False where id=%s'% noteid)
|
||||||
SET read='False'
|
|
||||||
where id = %d""" % int(noteid))
|
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
irc.reply(msg, conf.replySuccess)
|
irc.reply(msg, conf.replySuccess)
|
||||||
|
|
||||||
@ -122,15 +112,19 @@ class Notes(DBHandler, callbacks.Privmsg):
|
|||||||
n = irc.state.nickToHostmask(name)
|
n = irc.state.nickToHostmask(name)
|
||||||
recipient = ircdb.users.getUserName(n)
|
recipient = ircdb.users.getUserName(n)
|
||||||
self._addUser(sender)
|
self._addUser(sender)
|
||||||
|
print "added sender: %s" % sender
|
||||||
self._addUser(recipient)
|
self._addUser(recipient)
|
||||||
|
print "added recipient: %s" % recipient
|
||||||
senderID = self.getUserID(sender)
|
senderID = self.getUserID(sender)
|
||||||
|
print "senderID: %s" % senderID
|
||||||
recipID = self.getUserID(recipient)
|
recipID = self.getUserID(recipient)
|
||||||
if ircutils.isChannel(msg.args[0]): public = "True"
|
print "recipID: %s" % recipID
|
||||||
else: public = "False"
|
if ircutils.isChannel(msg.args[0]): public = True
|
||||||
|
else: public = False
|
||||||
self.cursor.execute("""INSERT INTO notes VALUES
|
self.cursor.execute("""INSERT INTO notes VALUES
|
||||||
(NULL, %d, %d, %d, %s, %s, %s)""",
|
(NULL, %s, %s, %s, %s, %s, %s)""",
|
||||||
int(senderID), int(recipID), time.time(),
|
senderID, recipID, int(time.time()),
|
||||||
'False', public, note)
|
False, public, note)
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
irc.reply(msg, conf.replySuccess)
|
irc.reply(msg, conf.replySuccess)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user