Added an email converter.

This commit is contained in:
Jeremy Fincher 2005-02-01 07:08:13 +00:00
parent 307f50137b
commit 978cf65453
2 changed files with 14 additions and 0 deletions

View File

@ -475,6 +475,12 @@ def getUrl(irc, msg, args, state):
else: else:
irc.errorInvalid('url', args[0]) irc.errorInvalid('url', args[0])
def getEmail(irc, msg, args, state):
if utils.net.emailRe.match(args[0]):
state.args.append(args.pop(0))
else:
irc.errorInvalid('email', args[0])
def getHttpUrl(irc, msg, args, state): def getHttpUrl(irc, msg, args, state):
if utils.web.httpUrlRe.match(args[0]): if utils.web.httpUrlRe.match(args[0]):
state.args.append(args.pop(0)) state.args.append(args.pop(0))
@ -557,6 +563,7 @@ wrappers = ircutils.IrcDict({
'color': getIrcColor, 'color': getIrcColor,
'now': getNow, 'now': getNow,
'url': getUrl, 'url': getUrl,
'email': getEmail,
'httpUrl': getHttpUrl, 'httpUrl': getHttpUrl,
'long': getLong, 'long': getLong,
'float': getFloat, 'float': getFloat,

View File

@ -142,5 +142,12 @@ class ConverterTestCase(CommandsTestCase):
self.assertState(['url'], [url], [url]) self.assertState(['url'], [url], [url])
self.assertState(['httpUrl'], [url], [url]) self.assertState(['httpUrl'], [url], [url])
def testEmail(self):
email = 'jemfinch@supybot.com'
self.assertState(['email'], [email], [email])
self.assertError(['email'], ['foo'])
self.assertError(['email'], ['foo@'])
self.assertError(['email'], ['@foo'])
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: