Changed the name to URL.

This commit is contained in:
Jeremy Fincher 2003-11-04 08:48:05 +00:00
parent d548447750
commit a456c5ea57
2 changed files with 36 additions and 48 deletions

View File

@ -80,10 +80,9 @@ def configure(onStart, afterConnect, advanced):
# like to be run when the bot is started; append to afterConnect the
# commands you would like to be run when the bot has finished connecting.
from questions import expect, anything, something, yn
onStart.append('load URLSnarfer')
onStart.append('load URL')
class URLSnarfer(plugins.ChannelDBHandler, callbacks.Privmsg,
plugins.Toggleable):
class URL(callbacks.Privmsg, plugins.Toggleable, plugins.ChannelDBHandler):
toggles = plugins.ToggleDictionary({'tinysnarf':True,
'tinyreply':True})
_maxUrlLen = 46
@ -164,8 +163,7 @@ class URLSnarfer(plugins.ChannelDBHandler, callbacks.Privmsg,
self.nextMsgs.setdefault(key, []).append((url, added))
db.commit()
_tinyRe = re.compile(r'23 characters:\n<blockquote>(http://tinyurl.com/\w{4})'\
'</blockquote>')
_tinyRe = re.compile(r'(http://tinyurl.com/\w{4})</blockquote>')
def _getTinyUrl(self, url, cmd=False):
try:
fd = urllib2.urlopen('http://tinyurl.com/create.php?url=%s' % url)
@ -191,7 +189,7 @@ class URLSnarfer(plugins.ChannelDBHandler, callbacks.Privmsg,
#debug.printf((id, url, added, addedBy))
return '#%s: %s' % (id, self._formatUrl(url, added, addedBy))
def randomurl(self, irc, msg, args):
def random(self, irc, msg, args):
"""[<channel>]
Returns a random URL from the URL database. <channel> is only required
@ -209,7 +207,7 @@ class URLSnarfer(plugins.ChannelDBHandler, callbacks.Privmsg,
else:
irc.reply(msg, self._formatUrlWithId(*cursor.fetchone()))
def tinyurl(self, irc, msg, args):
def tiny(self, irc, msg, args):
"""<url>
Returns a TinyURL.com version of <url>
@ -225,7 +223,7 @@ class URLSnarfer(plugins.ChannelDBHandler, callbacks.Privmsg,
else:
irc.reply(msg, url)
def geturl(self, irc, msg, args):
def get(self, irc, msg, args):
"""[<channel>] <id>
Gets the URL with id <id> from the URL database for <channel>.
@ -243,7 +241,7 @@ class URLSnarfer(plugins.ChannelDBHandler, callbacks.Privmsg,
else:
irc.reply(msg, self._formatUrl(*cursor.fetchone()))
def numurls(self, irc, msg, args):
def num(self, irc, msg, args):
"""[<channel>]
Returns the number of URLs in the URL database. <channel> is only
@ -257,17 +255,7 @@ class URLSnarfer(plugins.ChannelDBHandler, callbacks.Privmsg,
irc.reply(msg, 'I have %s %s in my database.' % \
(count, int(count) == 1 and 'URL' or 'URLs'))
def lasturls(self, irc, msg, args):
"""[<channel>] [--{from,with,at,proto,near}=<value>]
Uses arguments in the same way as lasturl; acts as if lasturl was given
the --nolimit option.
"""
if '--nolimit' not in args:
args.append('--nolimit')
self.lasturl(irc, msg, args)
def lasturl(self, irc, msg, args):
def last(self, irc, msg, args):
"""[<channel>] [--{from,with,at,proto,near}=<value>] --{nolimit,fancy}
Gives the last URL matching the given criteria. --from is from whom
@ -342,6 +330,6 @@ class URLSnarfer(plugins.ChannelDBHandler, callbacks.Privmsg,
irc.reply(msg, s)
Class = URLSnarfer
Class = URL
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:

View File

@ -72,60 +72,60 @@ except ImportError:
sqlite = None
if sqlite is not None:
class URLSnarferTestCase(ChannelPluginTestCase, PluginDocumentation):
plugins = ('URLSnarfer',)
class URLTestCase(ChannelPluginTestCase, PluginDocumentation):
plugins = ('URL',)
def test(self):
self.assertNotError('toggle tinyreply off')
self.assertNotError('toggle tinysnarf off')
counter = 0
self.assertNotError('randomurl')
self.assertNotError('url random')
for url in urls:
self.assertRegexp('numurls', str(counter))
self.assertRegexp('url num', str(counter))
self.feedMsg(url)
counter += 1
self.assertNotError('geturl %s' % counter)
self.assertNotError('url get %s' % counter)
self.assertRegexp('numurls', str(counter))
self.assertRegexp('lasturl', re.escape(urls[-1]))
self.assertRegexp('lasturl --proto https', re.escape(urls[-3]))
self.assertRegexp('lasturl --at gameknot.com', re.escape(urls[-2]))
self.assertRegexp('lasturl --with dhcp', re.escape(urls[-4]))
self.assertRegexp('lasturl --from alsdkjf', '^No')
self.assertNotError('randomurl')
self.assertRegexp('url num', str(counter))
self.assertRegexp('url last', re.escape(urls[-1]))
self.assertRegexp('url last --proto https', re.escape(urls[-3]))
self.assertRegexp('url last --at gameknot.com', re.escape(urls[-2]))
self.assertRegexp('url last --with dhcp', re.escape(urls[-4]))
self.assertRegexp('url last --from alsdkjf', '^No')
self.assertNotError('url random')
def testDefaultNotFancy(self):
self.assertNotError('toggle tinyreply off')
self.assertNotError('toggle tinysnarf off')
self.assertNotError('url toggle tinyreply off')
self.assertNotError('url toggle tinysnarf off')
self.feedMsg(urls[0])
self.assertResponse('lasturl', urls[0])
self.assertResponse('url last', urls[0])
def testAction(self):
self.assertNotError('toggle tinyreply off')
self.assertNotError('toggle tinysnarf off')
self.assertNotError('url toggle tinyreply off')
self.assertNotError('url toggle tinysnarf off')
self.irc.feedMsg(ircmsgs.action(self.channel, urls[1]))
self.assertNotRegexp('lasturl', '\\x01')
self.assertNotRegexp('url last', '\\x01')
def testTinyurl(self):
self.assertNotError('toggle tinyreply on')
self.assertNotError('toggle tinysnarf off')
self.assertRegexp('tinyurl http://sourceforge.net/tracker/?'\
self.assertNotError('url toggle tinyreply on')
self.assertNotError('url toggle tinysnarf off')
self.assertRegexp('url tiny http://sourceforge.net/tracker/?'\
'func=add&group_id=58965&atid=489447',
r'http://tinyurl.com/\w{4}')
self.assertNotError('toggle tinysnarf on')
self.assertRegexp('tinyurl http://sourceforge.net/tracker/?'\
self.assertNotError('url toggle tinysnarf on')
self.assertRegexp('url tiny http://sourceforge.net/tracker/?'\
'func=add&group_id=58965&atid=489447',
r'http://tinyurl.com/\w{4}')
self.assertNotError('toggle tinyreply off')
self.assertRegexp('tinyurl http://sourceforge.net/tracker/?'\
self.assertRegexp('url tiny http://sourceforge.net/tracker/?'\
'func=add&group_id=58965&atid=489447',
r'http://tinyurl.com/\w{4}')
def testTinysnarf(self):
self.assertNotError('toggle tinyreply off')
self.assertNotError('toggle tinysnarf on')
self.assertNotError('url toggle tinyreply off')
self.assertNotError('url toggle tinysnarf on')
self.assertNoResponse('http://sourceforge.net/tracker/?'\
'func=add&group_id=58965&atid=489447')
self.assertNotError('toggle tinyreply on')
self.assertNotError('url toggle tinyreply on')
self.assertRegexp('http://sourceforge.net/tracker/?'\
'func=add&group_id=58965&atid=489447',
r'TinyURL: http://tinyurl.com/\w{4}')