Changed last to be slightly more effiicent; changed a map to an imap.

This commit is contained in:
Jeremy Fincher 2003-11-15 03:21:34 +00:00
parent 0e01a1dee8
commit a8f31360e6

View File

@ -38,7 +38,7 @@ import fix
import os import os
import sys import sys
import getopt import getopt
from itertools import ifilter from itertools import imap, ifilter
import conf import conf
import debug import debug
@ -173,13 +173,13 @@ class Misc(callbacks.Privmsg):
hostmask of the person giving the command. hostmask of the person giving the command.
""" """
nick = privmsgs.getArgs(args, required=0, optional=1) nick = privmsgs.getArgs(args, required=0, optional=1)
try: if nick:
if nick: try:
irc.reply(msg, irc.state.nickToHostmask(nick)) irc.reply(msg, irc.state.nickToHostmask(nick))
else: except KeyError:
irc.reply(msg, msg.prefix) irc.error(msg, 'I haven\'t seen anyone named %r' % nick)
except KeyError: else:
irc.error(msg, 'I haven\'t seen anyone named %r' % nick) irc.reply(msg, msg.prefix)
def version(self, irc, msg, args): def version(self, irc, msg, args):
"""takes no arguments """takes no arguments
@ -214,7 +214,7 @@ class Misc(callbacks.Privmsg):
if file.endswith('.log'): if file.endswith('.log'):
stats = os.stat(os.path.join(conf.logDir, file)) stats = os.stat(os.path.join(conf.logDir, file))
result.append((file, str(stats.st_size))) result.append((file, str(stats.st_size)))
irc.reply(msg, ', '.join(map(': '.join, result))) irc.reply(msg, ', '.join(imap(': '.join, result)))
def getprefixchar(self, irc, msg, args): def getprefixchar(self, irc, msg, args):
"""takes no arguments """takes no arguments
@ -286,29 +286,26 @@ class Misc(callbacks.Privmsg):
predicates = [] predicates = []
for (option, arg) in optlist: for (option, arg) in optlist:
option = option.strip('-') if option == '--from':
if option == 'from':
predicates.append(lambda m, arg=arg: \ predicates.append(lambda m, arg=arg: \
ircutils.hostmaskPatternEqual(arg, m.nick)) ircutils.hostmaskPatternEqual(arg, m.nick))
elif option == 'in' or option == 'to': elif option == '--in' or option == 'to':
if not ircutils.isChannel(arg): if not ircutils.isChannel(arg):
irc.error(msg, 'Argument to --%s must be a channel.' % arg) irc.error(msg, 'Argument to --%s must be a channel.' % arg)
return return
predicates.append(lambda m, arg=arg: m.args[0] == arg) predicates.append(lambda m, arg=arg: m.args[0] == arg)
elif option == 'with': elif option == '--with':
predicates.append(lambda m, arg=arg: arg in m.args[1]) predicates.append(lambda m, arg=arg: arg in m.args[1])
elif option == 'regexp': elif option == '--regexp':
try: try:
r = utils.perlReToPythonRe(arg) r = utils.perlReToPythonRe(arg)
except ValueError, e: except ValueError, e:
irc.error(msg, str(e)) irc.error(msg, str(e))
return return
predicates.append(lambda m: r.search(m.args[1])) predicates.append(lambda m: r.search(m.args[1]))
first = True iterable = ifilter(self._validLastMsg, reviter(irc.state.history))
for m in ifilter(self._validLastMsg, reviter(irc.state.history)): iterable.next() # Drop the first message.
if first: for m in iterable:
first = False
continue
for predicate in predicates: for predicate in predicates:
if not predicate(m): if not predicate(m):
break break