mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-18 14:40:51 +01:00
Later: Add support for hostmasks.
This commit is contained in:
parent
50c41f5862
commit
00b8b6b51e
@ -102,29 +102,11 @@ class Later(callbacks.Plugin):
|
|||||||
notes.append((at, whence, text))
|
notes.append((at, whence, text))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self._notes[nick] = [(at, whence, text)]
|
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.wildcards.append(nick)
|
||||||
self._flushNotes()
|
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):
|
def _deleteExpired(self):
|
||||||
expiry = self.registryValue('messageExpiry')
|
expiry = self.registryValue('messageExpiry')
|
||||||
curtime = time.time()
|
curtime = time.time()
|
||||||
@ -164,12 +146,7 @@ class Later(callbacks.Plugin):
|
|||||||
if ircutils.strEqual(nick, irc.nick):
|
if ircutils.strEqual(nick, irc.nick):
|
||||||
irc.error(_('I can\'t send notes to myself.'))
|
irc.error(_('I can\'t send notes to myself.'))
|
||||||
return
|
return
|
||||||
validnick = self._validateNick(irc, nick)
|
validnicks.append(nick)
|
||||||
if validnick is False:
|
|
||||||
irc.error(_('%s is an invalid IRC nick. Please check your '
|
|
||||||
'input.' % nick))
|
|
||||||
return
|
|
||||||
validnicks.append(validnick)
|
|
||||||
full_queues = []
|
full_queues = []
|
||||||
for validnick in validnicks:
|
for validnick in validnicks:
|
||||||
try:
|
try:
|
||||||
@ -182,7 +159,7 @@ class Later(callbacks.Plugin):
|
|||||||
full_queues))
|
full_queues))
|
||||||
else:
|
else:
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
tell = wrap(tell, [commalist('somethingWithoutSpaces'), 'text'])
|
tell = wrap(tell, [commalist(first('nick', 'hostmask')), 'text'])
|
||||||
|
|
||||||
@internationalizeDocstring
|
@internationalizeDocstring
|
||||||
def notes(self, irc, msg, args, nick):
|
def notes(self, irc, msg, args, nick):
|
||||||
@ -250,7 +227,7 @@ class Later(callbacks.Plugin):
|
|||||||
# Let's try wildcards.
|
# Let's try wildcards.
|
||||||
removals = []
|
removals = []
|
||||||
for wildcard in self.wildcards:
|
for wildcard in self.wildcards:
|
||||||
if ircutils.hostmaskPatternEqual(wildcard, msg.nick):
|
if ircutils.hostmaskPatternEqual(wildcard, msg.prefix):
|
||||||
removals.append(wildcard)
|
removals.append(wildcard)
|
||||||
notes.extend(self._notes.pop(wildcard))
|
notes.extend(self._notes.pop(wildcard))
|
||||||
for removal in removals:
|
for removal in removals:
|
||||||
|
@ -57,10 +57,37 @@ class LaterTestCase(ChannelPluginTestCase):
|
|||||||
conf.supybot.protocols.irc.strictRfc.setValue('True')
|
conf.supybot.protocols.irc.strictRfc.setValue('True')
|
||||||
self.assertError('later tell 1foo bar')
|
self.assertError('later tell 1foo bar')
|
||||||
self.assertError('later tell foo$moo zoob')
|
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)
|
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):
|
def testNoteExpiry(self):
|
||||||
cb = self.irc.getCallback('Later')
|
cb = self.irc.getCallback('Later')
|
||||||
# add a note 40 days in the past
|
# add a note 40 days in the past
|
||||||
|
Loading…
x
Reference in New Issue
Block a user