mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +01:00
Changed the name to URL.
This commit is contained in:
parent
d548447750
commit
a456c5ea57
@ -80,10 +80,9 @@ def configure(onStart, afterConnect, advanced):
|
|||||||
# like to be run when the bot is started; append to afterConnect the
|
# 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.
|
# commands you would like to be run when the bot has finished connecting.
|
||||||
from questions import expect, anything, something, yn
|
from questions import expect, anything, something, yn
|
||||||
onStart.append('load URLSnarfer')
|
onStart.append('load URL')
|
||||||
|
|
||||||
class URLSnarfer(plugins.ChannelDBHandler, callbacks.Privmsg,
|
class URL(callbacks.Privmsg, plugins.Toggleable, plugins.ChannelDBHandler):
|
||||||
plugins.Toggleable):
|
|
||||||
toggles = plugins.ToggleDictionary({'tinysnarf':True,
|
toggles = plugins.ToggleDictionary({'tinysnarf':True,
|
||||||
'tinyreply':True})
|
'tinyreply':True})
|
||||||
_maxUrlLen = 46
|
_maxUrlLen = 46
|
||||||
@ -164,8 +163,7 @@ class URLSnarfer(plugins.ChannelDBHandler, callbacks.Privmsg,
|
|||||||
self.nextMsgs.setdefault(key, []).append((url, added))
|
self.nextMsgs.setdefault(key, []).append((url, added))
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
_tinyRe = re.compile(r'23 characters:\n<blockquote>(http://tinyurl.com/\w{4})'\
|
_tinyRe = re.compile(r'(http://tinyurl.com/\w{4})</blockquote>')
|
||||||
'</blockquote>')
|
|
||||||
def _getTinyUrl(self, url, cmd=False):
|
def _getTinyUrl(self, url, cmd=False):
|
||||||
try:
|
try:
|
||||||
fd = urllib2.urlopen('http://tinyurl.com/create.php?url=%s' % url)
|
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))
|
#debug.printf((id, url, added, addedBy))
|
||||||
return '#%s: %s' % (id, self._formatUrl(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>]
|
"""[<channel>]
|
||||||
|
|
||||||
Returns a random URL from the URL database. <channel> is only required
|
Returns a random URL from the URL database. <channel> is only required
|
||||||
@ -209,7 +207,7 @@ class URLSnarfer(plugins.ChannelDBHandler, callbacks.Privmsg,
|
|||||||
else:
|
else:
|
||||||
irc.reply(msg, self._formatUrlWithId(*cursor.fetchone()))
|
irc.reply(msg, self._formatUrlWithId(*cursor.fetchone()))
|
||||||
|
|
||||||
def tinyurl(self, irc, msg, args):
|
def tiny(self, irc, msg, args):
|
||||||
"""<url>
|
"""<url>
|
||||||
|
|
||||||
Returns a TinyURL.com version of <url>
|
Returns a TinyURL.com version of <url>
|
||||||
@ -225,7 +223,7 @@ class URLSnarfer(plugins.ChannelDBHandler, callbacks.Privmsg,
|
|||||||
else:
|
else:
|
||||||
irc.reply(msg, url)
|
irc.reply(msg, url)
|
||||||
|
|
||||||
def geturl(self, irc, msg, args):
|
def get(self, irc, msg, args):
|
||||||
"""[<channel>] <id>
|
"""[<channel>] <id>
|
||||||
|
|
||||||
Gets the URL with id <id> from the URL database for <channel>.
|
Gets the URL with id <id> from the URL database for <channel>.
|
||||||
@ -243,7 +241,7 @@ class URLSnarfer(plugins.ChannelDBHandler, callbacks.Privmsg,
|
|||||||
else:
|
else:
|
||||||
irc.reply(msg, self._formatUrl(*cursor.fetchone()))
|
irc.reply(msg, self._formatUrl(*cursor.fetchone()))
|
||||||
|
|
||||||
def numurls(self, irc, msg, args):
|
def num(self, irc, msg, args):
|
||||||
"""[<channel>]
|
"""[<channel>]
|
||||||
|
|
||||||
Returns the number of URLs in the URL database. <channel> is only
|
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.' % \
|
irc.reply(msg, 'I have %s %s in my database.' % \
|
||||||
(count, int(count) == 1 and 'URL' or 'URLs'))
|
(count, int(count) == 1 and 'URL' or 'URLs'))
|
||||||
|
|
||||||
def lasturls(self, irc, msg, args):
|
def last(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):
|
|
||||||
"""[<channel>] [--{from,with,at,proto,near}=<value>] --{nolimit,fancy}
|
"""[<channel>] [--{from,with,at,proto,near}=<value>] --{nolimit,fancy}
|
||||||
|
|
||||||
Gives the last URL matching the given criteria. --from is from whom
|
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)
|
irc.reply(msg, s)
|
||||||
|
|
||||||
|
|
||||||
Class = URLSnarfer
|
Class = URL
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
@ -72,60 +72,60 @@ except ImportError:
|
|||||||
sqlite = None
|
sqlite = None
|
||||||
|
|
||||||
if sqlite is not None:
|
if sqlite is not None:
|
||||||
class URLSnarferTestCase(ChannelPluginTestCase, PluginDocumentation):
|
class URLTestCase(ChannelPluginTestCase, PluginDocumentation):
|
||||||
plugins = ('URLSnarfer',)
|
plugins = ('URL',)
|
||||||
def test(self):
|
def test(self):
|
||||||
self.assertNotError('toggle tinyreply off')
|
self.assertNotError('toggle tinyreply off')
|
||||||
self.assertNotError('toggle tinysnarf off')
|
self.assertNotError('toggle tinysnarf off')
|
||||||
counter = 0
|
counter = 0
|
||||||
self.assertNotError('randomurl')
|
self.assertNotError('url random')
|
||||||
for url in urls:
|
for url in urls:
|
||||||
self.assertRegexp('numurls', str(counter))
|
self.assertRegexp('url num', str(counter))
|
||||||
self.feedMsg(url)
|
self.feedMsg(url)
|
||||||
counter += 1
|
counter += 1
|
||||||
self.assertNotError('geturl %s' % counter)
|
self.assertNotError('url get %s' % counter)
|
||||||
|
|
||||||
self.assertRegexp('numurls', str(counter))
|
self.assertRegexp('url num', str(counter))
|
||||||
self.assertRegexp('lasturl', re.escape(urls[-1]))
|
self.assertRegexp('url last', re.escape(urls[-1]))
|
||||||
self.assertRegexp('lasturl --proto https', re.escape(urls[-3]))
|
self.assertRegexp('url last --proto https', re.escape(urls[-3]))
|
||||||
self.assertRegexp('lasturl --at gameknot.com', re.escape(urls[-2]))
|
self.assertRegexp('url last --at gameknot.com', re.escape(urls[-2]))
|
||||||
self.assertRegexp('lasturl --with dhcp', re.escape(urls[-4]))
|
self.assertRegexp('url last --with dhcp', re.escape(urls[-4]))
|
||||||
self.assertRegexp('lasturl --from alsdkjf', '^No')
|
self.assertRegexp('url last --from alsdkjf', '^No')
|
||||||
self.assertNotError('randomurl')
|
self.assertNotError('url random')
|
||||||
|
|
||||||
def testDefaultNotFancy(self):
|
def testDefaultNotFancy(self):
|
||||||
self.assertNotError('toggle tinyreply off')
|
self.assertNotError('url toggle tinyreply off')
|
||||||
self.assertNotError('toggle tinysnarf off')
|
self.assertNotError('url toggle tinysnarf off')
|
||||||
self.feedMsg(urls[0])
|
self.feedMsg(urls[0])
|
||||||
self.assertResponse('lasturl', urls[0])
|
self.assertResponse('url last', urls[0])
|
||||||
|
|
||||||
def testAction(self):
|
def testAction(self):
|
||||||
self.assertNotError('toggle tinyreply off')
|
self.assertNotError('url toggle tinyreply off')
|
||||||
self.assertNotError('toggle tinysnarf off')
|
self.assertNotError('url toggle tinysnarf off')
|
||||||
self.irc.feedMsg(ircmsgs.action(self.channel, urls[1]))
|
self.irc.feedMsg(ircmsgs.action(self.channel, urls[1]))
|
||||||
self.assertNotRegexp('lasturl', '\\x01')
|
self.assertNotRegexp('url last', '\\x01')
|
||||||
|
|
||||||
def testTinyurl(self):
|
def testTinyurl(self):
|
||||||
self.assertNotError('toggle tinyreply on')
|
self.assertNotError('url toggle tinyreply on')
|
||||||
self.assertNotError('toggle tinysnarf off')
|
self.assertNotError('url toggle tinysnarf off')
|
||||||
self.assertRegexp('tinyurl http://sourceforge.net/tracker/?'\
|
self.assertRegexp('url tiny http://sourceforge.net/tracker/?'\
|
||||||
'func=add&group_id=58965&atid=489447',
|
'func=add&group_id=58965&atid=489447',
|
||||||
r'http://tinyurl.com/\w{4}')
|
r'http://tinyurl.com/\w{4}')
|
||||||
self.assertNotError('toggle tinysnarf on')
|
self.assertNotError('url toggle tinysnarf on')
|
||||||
self.assertRegexp('tinyurl http://sourceforge.net/tracker/?'\
|
self.assertRegexp('url tiny http://sourceforge.net/tracker/?'\
|
||||||
'func=add&group_id=58965&atid=489447',
|
'func=add&group_id=58965&atid=489447',
|
||||||
r'http://tinyurl.com/\w{4}')
|
r'http://tinyurl.com/\w{4}')
|
||||||
self.assertNotError('toggle tinyreply off')
|
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',
|
'func=add&group_id=58965&atid=489447',
|
||||||
r'http://tinyurl.com/\w{4}')
|
r'http://tinyurl.com/\w{4}')
|
||||||
|
|
||||||
def testTinysnarf(self):
|
def testTinysnarf(self):
|
||||||
self.assertNotError('toggle tinyreply off')
|
self.assertNotError('url toggle tinyreply off')
|
||||||
self.assertNotError('toggle tinysnarf on')
|
self.assertNotError('url toggle tinysnarf on')
|
||||||
self.assertNoResponse('http://sourceforge.net/tracker/?'\
|
self.assertNoResponse('http://sourceforge.net/tracker/?'\
|
||||||
'func=add&group_id=58965&atid=489447')
|
'func=add&group_id=58965&atid=489447')
|
||||||
self.assertNotError('toggle tinyreply on')
|
self.assertNotError('url toggle tinyreply on')
|
||||||
self.assertRegexp('http://sourceforge.net/tracker/?'\
|
self.assertRegexp('http://sourceforge.net/tracker/?'\
|
||||||
'func=add&group_id=58965&atid=489447',
|
'func=add&group_id=58965&atid=489447',
|
||||||
r'TinyURL: http://tinyurl.com/\w{4}')
|
r'TinyURL: http://tinyurl.com/\w{4}')
|
Loading…
Reference in New Issue
Block a user