Added getUserName.

This commit is contained in:
Jeremy Fincher 2004-12-02 05:33:29 +00:00
parent 2a0b9e645d
commit f7a3504a93
4 changed files with 19 additions and 27 deletions

View File

@ -61,21 +61,16 @@ class DbiNewsDB(plugins.DbiChannelDB):
def __str__(self):
format = conf.supybot.humanTimestampFormat()
try:
user = ircdb.users.getUser(int(self.by)).name
except ValueError:
user = self.by
except KeyError:
user = 'a user that is no longer registered'
if int(self.expires) == 0:
user = plugins.getUserName(self.by)
if self.expires == 0:
s = '%s (Subject: "%s", added by %s on %s)' % \
(self.text, self.subject, self.by,
time.strftime(format, time.localtime(int(self.at))))
time.strftime(format, time.localtime(self.at)))
else:
s = '%s (Subject: "%s", added by %s on %s, expires at %s)'
s = s % (self.text, self.subject, user,
time.strftime(format, time.localtime(int(self.at))),
time.strftime(format, time.localtime(int(self.expires))))
time.strftime(format, time.localtime(self.at)),
time.strftime(format, time.localtime(self.expires)))
return s
def __init__(self, filename):

View File

@ -71,12 +71,9 @@ class PollRecord(dbi.Record):
]
def __str__(self):
format = conf.supybot.humanTimestampFormat()
try:
user = ircdb.users.getUser(int(self.by)).name
except KeyError:
user = 'a user that is no longer registered'
user = plugins.getUserName(self.by)
if self.options:
options = 'Options: %s' % '; '.join(map(str, self.options))
options = 'Options: %s' % '; '.join(self.options)
else:
options = 'The poll has no options, yet'
if self.status:
@ -84,8 +81,7 @@ class PollRecord(dbi.Record):
else:
status = 'closed'
return 'Poll #%s: %s started by %s. %s. Poll is %s.' % \
(self.id, utils.quoted(self.question), user,
options, status)
(self.id, utils.quoted(self.question), user, options, status)
class SqlitePollDB(object):
def __init__(self, filename):

View File

@ -63,12 +63,7 @@ class QuoteRecord(dbi.Record):
]
def __str__(self):
format = conf.supybot.humanTimestampFormat()
try:
user = ircdb.users.getUser(int(self.by)).name
except ValueError:
user = self.by
except KeyError:
user = 'a user that is no longer registered'
user = plugins.getUserName(self.by)
return 'Quote %s added by %s at %s.' % \
(utils.quoted(self.text), user,
time.strftime(format, time.localtime(float(self.at))))

View File

@ -355,6 +355,15 @@ class ChannelUserDB(ChannelUserDictionary):
raise NotImplementedError
def getUserName(id):
if isinstance(id, int):
try:
return ircdb.users.getUser(id).name
except KeyError:
return 'a user that is no longer registered'
else:
return id
class ChannelIdDatabasePlugin(callbacks.Privmsg):
class DB(DbiChannelDB):
class DB(dbi.DB):
@ -470,10 +479,7 @@ class ChannelIdDatabasePlugin(callbacks.Privmsg):
additional(rest('glob'))])
def showRecord(self, record):
try:
name = ircdb.users.getUser(record.by).name
except KeyError:
name = 'a user that is no longer registered'
name = getUserName(record.by)
at = time.localtime(record.at)
timeS = time.strftime(conf.supybot.humanTimestampFormat(), at)
return '%s #%s: %s (added by %s at %s)' % \