Later: Add support for hostmasks.

This commit is contained in:
Valentin Lorentz 2018-07-05 19:48:43 +02:00
parent 50c41f5862
commit 00b8b6b51e
2 changed files with 35 additions and 31 deletions

View File

@ -102,29 +102,11 @@ class Later(callbacks.Plugin):
notes.append((at, whence, text))
except KeyError:
self._notes[nick] = [(at, whence, text)]
if '?' in nick or '*' in nick and nick not in self.wildcards:
if set('?*!@') & set(nick):
if nick not in self.wildcards:
self.wildcards.append(nick)
self._flushNotes()
def _validateNick(self, irc, nick):
"""Validate nick according to the IRC RFC 2812 spec.
Reference: http://tools.ietf.org/rfcmarkup?doc=2812#section-2.3.1
Some irc clients' tab-completion feature appends 'address' characters
to nick, such as ':' or ','. We try correcting for that by trimming
a char off the end.
If nick incorrigibly invalid, return False, otherwise,
return (possibly trimmed) nick.
"""
if not irc.isNick(nick):
if not irc.isNick(nick[:-1]):
return False
else:
return nick[:-1]
return nick
def _deleteExpired(self):
expiry = self.registryValue('messageExpiry')
curtime = time.time()
@ -164,12 +146,7 @@ class Later(callbacks.Plugin):
if ircutils.strEqual(nick, irc.nick):
irc.error(_('I can\'t send notes to myself.'))
return
validnick = self._validateNick(irc, nick)
if validnick is False:
irc.error(_('%s is an invalid IRC nick. Please check your '
'input.' % nick))
return
validnicks.append(validnick)
validnicks.append(nick)
full_queues = []
for validnick in validnicks:
try:
@ -182,7 +159,7 @@ class Later(callbacks.Plugin):
full_queues))
else:
irc.replySuccess()
tell = wrap(tell, [commalist('somethingWithoutSpaces'), 'text'])
tell = wrap(tell, [commalist(first('nick', 'hostmask')), 'text'])
@internationalizeDocstring
def notes(self, irc, msg, args, nick):
@ -250,7 +227,7 @@ class Later(callbacks.Plugin):
# Let's try wildcards.
removals = []
for wildcard in self.wildcards:
if ircutils.hostmaskPatternEqual(wildcard, msg.nick):
if ircutils.hostmaskPatternEqual(wildcard, msg.prefix):
removals.append(wildcard)
notes.extend(self._notes.pop(wildcard))
for removal in removals:

View File

@ -57,10 +57,37 @@ class LaterTestCase(ChannelPluginTestCase):
conf.supybot.protocols.irc.strictRfc.setValue('True')
self.assertError('later tell 1foo bar')
self.assertError('later tell foo$moo zoob')
self.assertNotError('later tell foo: baz')
self.assertRegexp('later notes', 'foo\.')
conf.supybot.protocols.irc.strictRfc.setValue(origconf)
def testWildcard(self):
self.assertNotError('later tell foo* stuff')
self.assertNotError('later tell bar,baz more stuff')
self.assertRegexp('later notes', 'bar.*foo')
testPrefix = 'foo!bar@baz'
self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'something',
prefix=testPrefix))
m = self.getMsg(' ')
self.assertEqual(str(m).strip(),
'PRIVMSG #test :foo: Sent just now: <test> stuff')
def testHostmask(self):
self.assertNotError('later tell foo*!*@baz stuff')
self.assertNotError('later tell bar,baz more stuff')
self.assertRegexp('later notes', 'bar.*foo')
testPrefix = 'foo!bar@baz2'
self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'something',
prefix=testPrefix))
m = self.getMsg(' ')
self.assertEqual(m, None)
testPrefix = 'foo!bar@baz'
self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'something',
prefix=testPrefix))
m = self.getMsg(' ')
self.assertEqual(str(m).strip(),
'PRIVMSG #test :foo: Sent just now: <test> stuff')
def testNoteExpiry(self):
cb = self.irc.getCallback('Later')
# add a note 40 days in the past