mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-21 08:01:00 +01:00
Changed last/lastfrom to the new method as per RFE 798374.
This commit is contained in:
parent
9256468885
commit
0791d9cbea
@ -47,6 +47,7 @@ import sha
|
|||||||
import time
|
import time
|
||||||
import math
|
import math
|
||||||
import cmath
|
import cmath
|
||||||
|
import getopt
|
||||||
import socket
|
import socket
|
||||||
import string
|
import string
|
||||||
import random
|
import random
|
||||||
@ -620,54 +621,50 @@ class FunCommands(callbacks.Privmsg):
|
|||||||
irc.reply(msg, response)
|
irc.reply(msg, response)
|
||||||
|
|
||||||
def last(self, irc, msg, args):
|
def last(self, irc, msg, args):
|
||||||
"""[<channel>] <message number>
|
"""[--{from,in,to,with,regexp}] <args>
|
||||||
|
|
||||||
Gets message number <message number> from the bot's history.
|
Returns the last message matching the given criteria. --from requires
|
||||||
<message number> defaults to 1, the last message prior to this command
|
a nick from whom the message came; --in and --to require a channel the
|
||||||
itself. <channel> is only necessary if the message isn't sent in the
|
message was sent to; --with requires some string that had to be in the
|
||||||
channel itself.
|
message; --regexp requires a regular expression the message must match
|
||||||
"""
|
"""
|
||||||
channel = privmsgs.getChannel(msg, args)
|
|
||||||
n = privmsgs.getArgs(args, needed=0, optional=1)
|
(optlist, rest) = getopt.getopt(args, '', ['from=', 'in=', 'to=',
|
||||||
if n == '':
|
'with=', 'regexp='])
|
||||||
n = 1
|
undecorated = False
|
||||||
else:
|
predicates = []
|
||||||
|
for (option, arg) in optlist:
|
||||||
|
option = option.strip('-')
|
||||||
|
if option == 'from':
|
||||||
|
predicates.append(lambda m: m.nick == arg)
|
||||||
|
elif option == 'in' or option == 'to':
|
||||||
|
if not ircutils.isChannel(argument):
|
||||||
|
irc.error(msg, 'Argument to --%s must be a channel.' % arg)
|
||||||
|
return
|
||||||
|
predicates.append(lambda m: m.args[0] == arg)
|
||||||
|
elif option == 'with':
|
||||||
|
predicates.append(lambda m: arg in m.args[1])
|
||||||
|
elif option == 'regexp':
|
||||||
try:
|
try:
|
||||||
n = int(n)
|
r = utils.perlReToPythonRe(arg)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
irc.error(msg, '<message number> must be an integer.')
|
irc.error(msg, str(e))
|
||||||
return
|
return
|
||||||
n += 1 # To remove the last question asked.
|
predicates.append(lambda m: r.search(m.args[1]))
|
||||||
for msg in reviter(irc.state.history):
|
first = True
|
||||||
if msg.command == 'PRIVMSG' and msg.args[0] == channel and n == 1:
|
|
||||||
irc.reply(msg, msg.args[1])
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
n -= 1
|
|
||||||
if n > 1:
|
|
||||||
s = 'I don\'t have a history of that many messages.'
|
|
||||||
irc.error(msg, s)
|
|
||||||
|
|
||||||
def lastfrom(self, irc, msg, args):
|
|
||||||
"""[<channel>] <nick>
|
|
||||||
|
|
||||||
Returns the last message in <channel> from <nick>. <channel> is only
|
|
||||||
necessary if the message isn't sent in the channel itself.
|
|
||||||
"""
|
|
||||||
channel = privmsgs.getChannel(msg, args)
|
|
||||||
nick = privmsgs.getArgs(args)
|
|
||||||
for m in reviter(irc.state.history):
|
for m in reviter(irc.state.history):
|
||||||
if m.command == 'PRIVMSG' and \
|
if first:
|
||||||
m.nick == nick and \
|
first = False
|
||||||
m.args[0] == channel:
|
continue
|
||||||
if ircmsgs.isAction(m):
|
if m.command != 'PRIVMSG':
|
||||||
irc.reply(msg, '* %s %s' % (nick, ircmsgs.unAction(m)))
|
continue
|
||||||
return
|
if all(bool, [f(m) for f in predicates]):
|
||||||
|
if undecorated:
|
||||||
|
irc.reply(msg, m.args[1])
|
||||||
else:
|
else:
|
||||||
irc.reply(msg, '<%s> %s' % (nick, m.args[1]))
|
irc.reply(msg, ircmsgs.prettyPrint(m))
|
||||||
return
|
return
|
||||||
return
|
irc.error(msg, 'I couldn\'t find a message matching that criteria.')
|
||||||
irc.error(msg, 'I don\'t remember a message from that person.')
|
|
||||||
|
|
||||||
def levenshtein(self, irc, msg, args):
|
def levenshtein(self, irc, msg, args):
|
||||||
"""<string1> <string2>
|
"""<string1> <string2>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user