Made last default to the current channel.

This commit is contained in:
Jeremy Fincher 2003-12-02 10:55:22 +00:00
parent f65b3cd8c0
commit b473532b4c

View File

@ -327,32 +327,40 @@ class Misc(callbacks.Privmsg):
Returns the last message matching the given criteria. --from requires Returns the last message matching the given criteria. --from requires
a nick from whom the message came; --in and --to require a channel the a nick from whom the message came; --in and --to require a channel the
message was sent to; --with requires some string that had to be in the message was sent to; --with requires some string that had to be in the
message; --regexp requires a regular expression the message must match message; --regexp requires a regular expression the message must
match. By default, the current channel is searched.
""" """
(optlist, rest) = getopt.getopt(args, '', ['from=', 'in=', 'to=', (optlist, rest) = getopt.getopt(args, '', ['from=', 'in=', 'to=',
'with=', 'regexp=']) 'with=', 'regexp='])
predicates = [] predicates = {}
if ircutils.isChannel(msg.args[0]):
predicates['in'] = lambda m: m.args[0] == msg.args[0]
for (option, arg) in optlist: for (option, arg) in optlist:
if option == '--from': if option == '--from':
predicates.append(lambda m, arg=arg: \ def f(m, arg=arg):
ircutils.hostmaskPatternEqual(arg, m.nick)) return ircutils.hostmaskPatternEqual(arg, m.nick)
predicates['from'] = f
elif option == '--in' or option == 'to': elif option == '--in' or option == 'to':
if not ircutils.isChannel(arg): def f(m, arg=arg):
irc.error(msg, 'Argument to --%s must be a channel.' % arg) return m.args[0] == arg
return predicates['in'] = f
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]) def f(m, arg=arg):
return arg in m.args[1]
predicates.setdefault('with', []).append(f)
elif option == '--regexp': elif option == '--regexp':
try: try:
r = utils.perlReToPythonRe(arg) r = utils.perlReToPythonRe(arg)
def f(m, r=r):
return r.search(m.args[1])
predicates.setdefault('regexp', []).append(f)
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]))
iterable = ifilter(self._validLastMsg, reviter(irc.state.history)) iterable = ifilter(self._validLastMsg, reviter(irc.state.history))
iterable.next() # Drop the first message. iterable.next() # Drop the first message.
predicates = list(utils.flatten(predicates.itervalues()))
for m in iterable: for m in iterable:
for predicate in predicates: for predicate in predicates:
if not predicate(m): if not predicate(m):