Accidentally commited earlier; just a few style changes and docstring improvements.

This commit is contained in:
Jeremy Fincher 2003-03-28 07:48:16 +00:00
parent 85e7e3ae05
commit b943dafd29
1 changed files with 19 additions and 17 deletions

View File

@ -37,26 +37,26 @@ import os.path
import sqlite import sqlite
import conf import conf
import debug
import ircdb import ircdb
import privmsgs import privmsgs
import callbacks
import ircutils import ircutils
import debug import callbacks
class Notes(callbacks.Privmsg): class Notes(callbacks.Privmsg):
def __init__(self): def __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')
self.converters = {'bool': bool}
if os.path.exists(self.filename): if os.path.exists(self.filename):
self.db = sqlite.connect(self.filename) self.db = sqlite.connect(self.filename, converters=self.converters)
self.cursor = self.db.cursor() self.cursor = self.db.cursor()
else: else:
self.makeDB() self.makeDB()
def makeDB(self): def makeDB(self):
"create Notes database and tables" "create Notes database and tables"
self.db = sqlite.connect(self.filename, converters={'bool': bool}) self.db = sqlite.connect(self.filename, converters=self.converters)
self.cursor = self.db.cursor() self.cursor = self.db.cursor()
self.cursor.execute("""CREATE TABLE users ( self.cursor.execute("""CREATE TABLE users (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
@ -76,7 +76,7 @@ class Notes(callbacks.Privmsg):
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 VALUES (NULL,%s)', username) self.cursor.execute('INSERT INTO users VALUES (NULL, %s)', username)
self.db.commit() self.db.commit()
def getUserID(self, username): def getUserID(self, username):
@ -90,10 +90,9 @@ class Notes(callbacks.Privmsg):
def getUserName(self, userid): def getUserName(self, userid):
self.cursor.execute('SELECT name FROM users WHERE id=%s', userid) self.cursor.execute('SELECT name FROM users WHERE id=%s', userid)
if self.cursor.rowcount != 0: if self.cursor.rowcount != 0:
results = self.cursor.fetchall() return self.cursor.fetchone()[0]
return results[0]
else: else:
raise KeyError raise KeyError, userid
# def setNoteUnread(self, irc, msg, args): # def setNoteUnread(self, irc, msg, args):
# "set a note as unread" # "set a note as unread"
@ -103,8 +102,10 @@ class Notes(callbacks.Privmsg):
# irc.reply(msg, conf.replySuccess) # irc.reply(msg, conf.replySuccess)
def sendnote(self, irc, msg, args): def sendnote(self, irc, msg, args):
"sends a new note to an IRC user" """<user> <text>
# sendnote <user> <text>
Sends a note to an IRC user.
"""
(name, note) = privmsgs.getArgs(args, needed=2) (name, note) = privmsgs.getArgs(args, needed=2)
sender = ircutils.nickFromHostmask(msg.prefix) sender = ircutils.nickFromHostmask(msg.prefix)
if ircdb.users.hasUser(name): if ircdb.users.hasUser(name):
@ -120,10 +121,6 @@ class Notes(callbacks.Privmsg):
public = 1 public = 1
else: else:
public = 0 public = 0
debug.printf(senderID)
debug.printf(recipID)
debug.printf(public)
debug.printf(note)
self.cursor.execute("""INSERT INTO notes VALUES self.cursor.execute("""INSERT INTO notes VALUES
(NULL, %s, %s, %s, %s, %s, %s)""", (NULL, %s, %s, %s, %s, %s, %s)""",
senderID, recipID, int(time.time()), senderID, recipID, int(time.time()),
@ -132,7 +129,10 @@ class Notes(callbacks.Privmsg):
irc.reply(msg, conf.replySuccess) irc.reply(msg, conf.replySuccess)
def getnote(self, irc, msg, args): def getnote(self, irc, msg, args):
"retrieves a single note by unique note id" """<id>
Retrieves a single note by unique number id
"""
# BLOODY HELL, THIS ACTUALLY WORKS!!! # BLOODY HELL, THIS ACTUALLY WORKS!!!
noteid = privmsgs.getArgs(args) noteid = privmsgs.getArgs(args)
sender = ircdb.users.getUserName(msg.prefix) sender = ircdb.users.getUserName(msg.prefix)
@ -183,7 +183,9 @@ class Notes(callbacks.Privmsg):
# irc.error(msg, 'Unable to delete note') # irc.error(msg, 'Unable to delete note')
def getnotes(self, irc, msg, args): def getnotes(self, irc, msg, args):
"takes no arguments gets all notes for sender" """takes no arguments
Gets all notes for sender."""
sender = ircdb.users.getUserName(msg.prefix) sender = ircdb.users.getUserName(msg.prefix)
senderID = self.getUserID(sender) senderID = self.getUserID(sender)
self.cursor.execute("""SELECT id, from_id FROM notes self.cursor.execute("""SELECT id, from_id FROM notes