QuoteGrabs: Add support for +draft/reply to point to the message to grab.

This commit is contained in:
Valentin Lorentz 2020-05-15 18:17:34 +02:00
parent a54db1034f
commit 6f4e3a2dbd
2 changed files with 41 additions and 0 deletions

View File

@ -287,7 +287,13 @@ class QuoteGrabs(callbacks.Plugin):
raise callbacks.ArgumentError
if ircutils.nickEqual(nick, msg.nick):
irc.error(_('You can\'t quote grab yourself.'), Raise=True)
if conf.supybot.protocols.irc.experimentalExtensions():
msgid = msg.server_tags.get('+draft/reply')
else:
msgid = None
for m in reversed(irc.state.history):
if msgid and m.server_tags.get('msgid') != msgid:
continue
if m.command == 'PRIVMSG' and ircutils.nickEqual(m.nick, nick) \
and ircutils.strEqual(m.args[0], chan):
# TODO: strip statusmsg prefix for comparison? Must be careful

View File

@ -51,6 +51,41 @@ class QuoteGrabsTestCase(ChannelPluginTestCase):
self.assertNotError('grab foo')
self.assertResponse('quote foo', '* foo moos')
def testQuoteGrabReplyDisabled(self):
testPrefix = 'foo!bar@baz'
prefixChar = conf.supybot.reply.whenAddressedBy.chars()[0]
self.irc.feedMsg(ircmsgs.IrcMsg(
server_tags={'msgid': 'aaaa'}, prefix=testPrefix,
command='PRIVMSG', args=(self.channel, 'something')))
self.irc.feedMsg(ircmsgs.IrcMsg(
server_tags={'msgid': 'bbbb'}, prefix=testPrefix,
command='PRIVMSG', args=(self.channel, 'something else')))
# supybot.protocols.irc.experimentalExtensions is not enabled, so
# +draft/reply is ignored.
self.irc.feedMsg(ircmsgs.IrcMsg(
server_tags={'+draft/reply': 'aaaa'}, prefix=self.prefix,
command='PRIVMSG', args=(self.channel, prefixChar+'grab foo')))
self.assertResponse(' ', 'The operation succeeded.')
self.assertResponse('quote foo', '<foo> something else')
def testQuoteGrabReply(self):
testPrefix = 'foo!bar@baz'
prefixChar = conf.supybot.reply.whenAddressedBy.chars()[0]
self.irc.feedMsg(ircmsgs.IrcMsg(
server_tags={'msgid': 'aaaa'}, prefix=testPrefix,
command='PRIVMSG', args=(self.channel, 'something')))
self.irc.feedMsg(ircmsgs.IrcMsg(
server_tags={'msgid': 'bbbb'}, prefix=testPrefix,
command='PRIVMSG', args=(self.channel, 'something else')))
with conf.supybot.protocols.irc.experimentalExtensions.context(True):
self.irc.feedMsg(ircmsgs.IrcMsg(
server_tags={'+draft/reply': 'aaaa'}, prefix=self.prefix,
command='PRIVMSG', args=(self.channel, prefixChar+'grab foo')))
self.assertResponse(' ', 'The operation succeeded.')
self.assertResponse('quote foo', '<foo> something')
def testUngrab(self):
testPrefix = 'foo!bar@baz'
# nothing yet