diff --git a/plugins/Alias.py b/plugins/Alias.py index e6a41b06c..a1dbf08d1 100644 --- a/plugins/Alias.py +++ b/plugins/Alias.py @@ -127,7 +127,10 @@ def makeNewAlias(name, alias): return args[idx-1] alias_ = dollarRe.sub(replace, alias_) self.Proxy(irc, msg, callbacks.tokenize(alias_)) - f.__doc__ ='\n\nAlias for %r'%(biggestDollar,alias) + f.__doc__ ='\n\nAlias for %r' % \ + (biggestDollar, + utils.pluralize(biggestDollar, 'argument'), + alias) #f = new.function(f.func_code, f.func_globals, name) return f diff --git a/plugins/FunCommands.py b/plugins/FunCommands.py index 93441a475..45503bae7 100644 --- a/plugins/FunCommands.py +++ b/plugins/FunCommands.py @@ -461,13 +461,17 @@ class FunCommands(callbacks.Privmsg): childUser, childSystem, childUser + childSystem, (user+system+childUser+childSystem)/timeRunning, world.threadsSpawned, - world.threadsSpawned == 1 and 'thread' or 'threads', - activeThreads, world.commandsProcessed, - world.commandsProcessed == 1 and 'command' or 'commands') + utils.pluralize(world.threadsSpawned, 'thread'), + activeThreads, + world.commandsProcessed, + utils.pluralize(world.commandsProcessed, 'command')) irc.reply(msg, response) def uptime(self, irc, msg, args): - "takes no arguments" + """takes no arguments. + + Returns the amount of time the bot has been running. + """ response = 'I have been running for %s.' % \ utils.timeElapsed(time.time() - world.startedAt) irc.reply(msg, response) diff --git a/plugins/FunDB.py b/plugins/FunDB.py index 5fe83a970..602a3f190 100755 --- a/plugins/FunDB.py +++ b/plugins/FunDB.py @@ -81,7 +81,7 @@ def tableExists(db, table): try: cursor.execute("""SELECT * from %s LIMIT 1""" % table) return True - except DatabaseError: + except sqlite.DatabaseError: return False tableDict = { @@ -153,9 +153,13 @@ class FunDB(callbacks.Privmsg): cursor = self.db.cursor() started = int(world.startedAt) cursor.execute("""INSERT INTO uptime VALUES (%s, NULL)""", started) + self.db.commit() def f(): + db = makeDb(dbFilename) + cursor = db.cursor() cursor.execute("""UPDATE uptime SET ended=%s WHERE started=%s""", int(time.time()), started) + db.commit() atexit.register(f) def die(self): @@ -163,18 +167,6 @@ class FunDB(callbacks.Privmsg): self.db.close() del self.db - def _pluralize(self, string, count, verb=None): - if verb is None: - if count == 1: - return string - else: - return '%ss' % string - else: - if count == 1: - return ('is', string) - else: - return ('are', '%ss' % string) - def bestuptime(self, irc, msg, args): """takes no arguments. @@ -352,9 +344,8 @@ class FunDB(callbacks.Privmsg): total = int(cursor.fetchone()[0]) except ValueError: irc.error(msg, 'Unexpected response from database') - (verb, table) = self._pluralize(table, total, 1) - irc.reply(msg, 'There %s currently %s %s in my database' %\ - (verb, total, table)) + irc.reply(msg, 'There %s currently %s %s in my database' % \ + (utils.be(total), total, utils.pluralize(total, table))) def dbget(self, irc, msg, args): """ @@ -406,8 +397,9 @@ class FunDB(callbacks.Privmsg): else: (add,req,count) = cursor.fetchone() reply = '%s #%s: Created by %s. last requested by %s, requested '\ - ' a total of %s %s' % (table, id, add, req, count, - self._pluralize('time',count)) + ' a total of %s %s' % \ + (table, id, add, req, + count, utils.pluralize(count, 'time')) irc.reply(msg, reply) def lart(self, irc, msg, args): diff --git a/plugins/Notes.py b/plugins/Notes.py index eab8346f9..475845d5f 100644 --- a/plugins/Notes.py +++ b/plugins/Notes.py @@ -157,9 +157,9 @@ class Notes(callbacks.Privmsg): notes.to_id=users.id AND read=0""", name) unread = int(cursor.fetchone()[0]) - s = 'You have %s unread note%s ' \ + s = 'You have %s unread %s; ' \ '%s that I haven\'t told you about before now..' % \ - (unread, unread == 1 and ';' or 's;', unnotified) + (unread, utils.pluralize(unread, 'note'), unnotified) irc.queueMsg(ircmsgs.privmsg(msg.nick, s)) cursor.execute("""UPDATE notes SET notified=1 diff --git a/src/utils.py b/src/utils.py index 476b3bbf0..6535f8166 100755 --- a/src/utils.py +++ b/src/utils.py @@ -286,4 +286,20 @@ def wrapLines(s): L.append(textwrap.fill(line)) return '\n'.join(L) +plurals = {} +def pluralize(i, s): + if i == 1: + return s + else: + if s in plurals: + return plurals[s] + else: + return s + 's' + +def be(i): + if i == 1: + return 'is' + else: + return 'are' + # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: