mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-30 14:14:37 +01:00
Made it not depend on Alias anymore.
This commit is contained in:
parent
c6b232b588
commit
246afc30e1
@ -27,6 +27,9 @@
|
|||||||
* Added Karma.most for determining various "mosts" in the Karma
|
* Added Karma.most for determining various "mosts" in the Karma
|
||||||
database.
|
database.
|
||||||
|
|
||||||
|
* Changed RSS so RSS feed commands may be added while the bot is
|
||||||
|
running, and so added RSS feed commands are in the RSS plugin.
|
||||||
|
|
||||||
* Changed Lookup so added lookups are added in the Lookup plugin
|
* Changed Lookup so added lookups are added in the Lookup plugin
|
||||||
itself so there's no dependency on Alias, and so loaded lookups
|
itself so there's no dependency on Alias, and so loaded lookups
|
||||||
can be seen via 'list Lookup'.
|
can be seen via 'list Lookup'.
|
||||||
|
@ -38,11 +38,14 @@ __revision__ = "$Id$"
|
|||||||
|
|
||||||
import plugins
|
import plugins
|
||||||
|
|
||||||
|
import sets
|
||||||
import time
|
import time
|
||||||
|
import types
|
||||||
from itertools import imap
|
from itertools import imap
|
||||||
|
|
||||||
import rssparser
|
import rssparser
|
||||||
|
|
||||||
|
import conf
|
||||||
import utils
|
import utils
|
||||||
import privmsgs
|
import privmsgs
|
||||||
import callbacks
|
import callbacks
|
||||||
@ -50,30 +53,60 @@ import callbacks
|
|||||||
def configure(onStart, afterConnect, advanced):
|
def configure(onStart, afterConnect, advanced):
|
||||||
from questions import expect, anything, something, yn
|
from questions import expect, anything, something, yn
|
||||||
onStart.append('load RSS')
|
onStart.append('load RSS')
|
||||||
if 'load Alias' not in onStart:
|
|
||||||
print 'The RSS configure questions need the Alias plugin, but it is '
|
|
||||||
print 'not loaded.'
|
|
||||||
if yn('Do you want to load that plugin now?') == 'y':
|
|
||||||
onStart.append('load Alias')
|
|
||||||
else:
|
|
||||||
print 'You can still use the RSS plugin, but you won\'t be asked'
|
|
||||||
print 'any further questions.'
|
|
||||||
return
|
|
||||||
prompt = 'Would you like to add an RSS feed?'
|
prompt = 'Would you like to add an RSS feed?'
|
||||||
while yn(prompt) == 'y':
|
while yn(prompt) == 'y':
|
||||||
prompt = 'Would you like to add another RSS feed?'
|
prompt = 'Would you like to add another RSS feed?'
|
||||||
name = something('What\'s the name of the website?')
|
name = something('What\'s the name of the website?')
|
||||||
url = something('What\'s the URL of the RSS feed?')
|
url = something('What\'s the URL of the RSS feed?')
|
||||||
onStart.append('alias add %s "rss %s"' % (name, url))
|
onStart.append('rss add %s %s' % (name, url))
|
||||||
onStart.append('alias lock %s' % name)
|
#onStart.append('alias lock %s' % name)
|
||||||
|
|
||||||
class RSS(callbacks.Privmsg):
|
class RSS(callbacks.Privmsg):
|
||||||
threaded = True
|
threaded = True
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
callbacks.Privmsg.__init__(self)
|
callbacks.Privmsg.__init__(self)
|
||||||
|
self.feedNames = sets.Set()
|
||||||
self.lastRequest = {}
|
self.lastRequest = {}
|
||||||
self.cachedFeeds = {}
|
self.cachedFeeds = {}
|
||||||
|
|
||||||
|
def add(self, irc, msg, args):
|
||||||
|
"""<name> <url>
|
||||||
|
|
||||||
|
Adds a command to this plugin that will look up the RSS feed at the
|
||||||
|
given URL.
|
||||||
|
"""
|
||||||
|
(name, url) = privmsgs.getArgs(args, required=2)
|
||||||
|
docstring = """takes no arguments
|
||||||
|
|
||||||
|
Reports the titles for %s at the RSS feed <%s>. RSS feeds are only
|
||||||
|
looked up every half hour at the most (since that's how most
|
||||||
|
websites prefer it).
|
||||||
|
""" % (name, url)
|
||||||
|
name = callbacks.canonicalName(name)
|
||||||
|
def f(self, irc, msg, args):
|
||||||
|
args.insert(0, url)
|
||||||
|
self.rss(irc, msg, args)
|
||||||
|
f = types.FunctionType(f.func_code, f.func_globals,
|
||||||
|
f.func_name, closure=f.func_closure)
|
||||||
|
f.__doc__ = docstring
|
||||||
|
self.feedNames.add(name)
|
||||||
|
setattr(self.__class__, name, f)
|
||||||
|
irc.reply(msg, conf.replySuccess)
|
||||||
|
|
||||||
|
def remove(self, irc, msg, args):
|
||||||
|
"""<name>
|
||||||
|
|
||||||
|
Removes the command for looking up RSS feeds at <name> from
|
||||||
|
this plugin.
|
||||||
|
"""
|
||||||
|
name = privmsgs.getArgs(args)
|
||||||
|
name = callbacks.canonicalName(name)
|
||||||
|
if name not in self.feedNames:
|
||||||
|
irc.error(msg, 'That\'s not a valid RSS feed command name.')
|
||||||
|
return
|
||||||
|
delattr(self.__class__, name)
|
||||||
|
irc.reply(msg, conf.replySuccess)
|
||||||
|
|
||||||
def rss(self, irc, msg, args):
|
def rss(self, irc, msg, args):
|
||||||
"""<url>
|
"""<url>
|
||||||
|
|
||||||
|
@ -38,9 +38,18 @@ class RSSTestCase(PluginTestCase, PluginDocumentation):
|
|||||||
self.assertNotRegexp('rss info http://slashdot.org/slashdot.rss',
|
self.assertNotRegexp('rss info http://slashdot.org/slashdot.rss',
|
||||||
'-1 years')
|
'-1 years')
|
||||||
|
|
||||||
def testRsstitles(self):
|
def testRss(self):
|
||||||
self.assertNotError('rss http://slashdot.org/slashdot.rss')
|
self.assertNotError('rss http://slashdot.org/slashdot.rss')
|
||||||
|
|
||||||
|
def testRssAdd(self):
|
||||||
|
self.assertNotError('rss add slashdot '
|
||||||
|
'http://slashdot.org/slashdot.rss')
|
||||||
|
self.assertNotError('slashdot')
|
||||||
|
self.assertNotError('rss slashdot')
|
||||||
|
self.assertNotError('rss remove slashdot')
|
||||||
|
self.assertError('slashdot')
|
||||||
|
self.assertError('rss slashdot')
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user