mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Updated to use the registry.
This commit is contained in:
parent
6831dafee5
commit
0b11192acf
@ -40,12 +40,13 @@ import plugins
|
|||||||
|
|
||||||
import amazon
|
import amazon
|
||||||
|
|
||||||
|
import registry
|
||||||
|
|
||||||
import conf
|
import conf
|
||||||
import utils
|
import utils
|
||||||
import ircutils
|
import ircutils
|
||||||
import privmsgs
|
import privmsgs
|
||||||
import callbacks
|
import callbacks
|
||||||
import configurable
|
|
||||||
|
|
||||||
|
|
||||||
def configure(onStart, afterConnect, advanced):
|
def configure(onStart, afterConnect, advanced):
|
||||||
@ -59,21 +60,30 @@ def configure(onStart, afterConnect, advanced):
|
|||||||
key = anything('What is it?')
|
key = anything('What is it?')
|
||||||
|
|
||||||
onStart.append('load Amazon')
|
onStart.append('load Amazon')
|
||||||
onStart.append('amazon licensekey %s' % key)
|
conf.supybot.plugins.Amazon.licenseKey.set(key)
|
||||||
else:
|
else:
|
||||||
print 'You\'ll need to get a key before you can use this plugin.'
|
print 'You\'ll need to get a key before you can use this plugin.'
|
||||||
print 'You can apply for a key at http://www.amazon.com/webservices'
|
print 'You can apply for a key at http://www.amazon.com/webservices'
|
||||||
|
|
||||||
|
class LicenseKey(registry.String):
|
||||||
|
def set(self, s):
|
||||||
|
# In case we decide we need to recover
|
||||||
|
original = getattr(self, 'value', self.default)
|
||||||
|
registry.String.set(self, s)
|
||||||
|
if self.value:
|
||||||
|
amazon.setLicense(self.value)
|
||||||
|
|
||||||
class Amazon(callbacks.Privmsg,configurable.Mixin):
|
conf.registerPlugin('Amazon')
|
||||||
|
conf.registerChannelValue(conf.supybot.plugins.Amazon, 'bold',
|
||||||
|
registry.Boolean(True, """Determines whether the results are bolded."""))
|
||||||
|
conf.registerGlobalValue(conf.supybot.plugins.Amazon, 'licenseKey',
|
||||||
|
LicenseKey('', """Sets the license key for using Amazon Web Services.
|
||||||
|
Must be set before any other commands in the plugin are used."""))
|
||||||
|
|
||||||
|
class Amazon(callbacks.Privmsg):
|
||||||
threaded = True
|
threaded = True
|
||||||
configurables = configurable.Dictionary(
|
|
||||||
[('bold', configurable.BoolType, True,
|
|
||||||
"""Determines whether the results are bolded.""")]
|
|
||||||
)
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
configurable.Mixin.__init__(self)
|
|
||||||
callbacks.Privmsg.__init__(self)
|
callbacks.Privmsg.__init__(self)
|
||||||
|
|
||||||
def _genResults(self, reply, attribs, items, url, bold, bold_item):
|
def _genResults(self, reply, attribs, items, url, bold, bold_item):
|
||||||
@ -104,17 +114,6 @@ class Amazon(callbacks.Privmsg,configurable.Mixin):
|
|||||||
self.log.warning(str(e))
|
self.log.warning(str(e))
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def licensekey(self, irc, msg, args):
|
|
||||||
"""<key>
|
|
||||||
|
|
||||||
Sets the license key for using Amazon Web Services. Must be set before
|
|
||||||
any other commands in this module are used.
|
|
||||||
"""
|
|
||||||
key = privmsgs.getArgs(args)
|
|
||||||
amazon.setLicense(key)
|
|
||||||
irc.replySuccess()
|
|
||||||
licensekey = privmsgs.checkCapability(licensekey, 'admin')
|
|
||||||
|
|
||||||
def isbn(self, irc, msg, args):
|
def isbn(self, irc, msg, args):
|
||||||
"""[--url] <isbn>
|
"""[--url] <isbn>
|
||||||
|
|
||||||
@ -140,7 +139,7 @@ class Amazon(callbacks.Privmsg,configurable.Mixin):
|
|||||||
'%(publisher)s%(url)s'
|
'%(publisher)s%(url)s'
|
||||||
try:
|
try:
|
||||||
book = amazon.searchByKeyword(isbn)
|
book = amazon.searchByKeyword(isbn)
|
||||||
bold = self.configurables.get('bold', msg.args[0])
|
bold = conf.supybot.plugins.Amazon.bold()
|
||||||
res = self._genResults(s, attribs, book, url, bold, 'title')
|
res = self._genResults(s, attribs, book, url, bold, 'title')
|
||||||
if res:
|
if res:
|
||||||
irc.reply(utils.commaAndify(res))
|
irc.reply(utils.commaAndify(res))
|
||||||
@ -173,7 +172,7 @@ class Amazon(callbacks.Privmsg,configurable.Mixin):
|
|||||||
'%(publisher)s%(url)s'
|
'%(publisher)s%(url)s'
|
||||||
try:
|
try:
|
||||||
books = amazon.searchByKeyword(keyword)
|
books = amazon.searchByKeyword(keyword)
|
||||||
bold = self.configurables.get('bold', msg.args[0])
|
bold = conf.supybot.plugins.Amazon.bold()
|
||||||
res = self._genResults(s, attribs, books, url, bold, 'title')
|
res = self._genResults(s, attribs, books, url, bold, 'title')
|
||||||
if res:
|
if res:
|
||||||
irc.reply(utils.commaAndify(res))
|
irc.reply(utils.commaAndify(res))
|
||||||
@ -212,7 +211,7 @@ class Amazon(callbacks.Privmsg,configurable.Mixin):
|
|||||||
'%(date)s; published by %(publisher)s%(url)s'
|
'%(date)s; published by %(publisher)s%(url)s'
|
||||||
try:
|
try:
|
||||||
videos = amazon.searchByKeyword(keyword, product_line=product)
|
videos = amazon.searchByKeyword(keyword, product_line=product)
|
||||||
bold = self.configurables.get('bold', msg.args[0])
|
bold = conf.supybot.plugins.Amazon.bold()
|
||||||
res = self._genResults(s, attribs, videos, url, bold, 'title')
|
res = self._genResults(s, attribs, videos, url, bold, 'title')
|
||||||
if res:
|
if res:
|
||||||
irc.reply(utils.commaAndify(res))
|
irc.reply(utils.commaAndify(res))
|
||||||
@ -243,7 +242,7 @@ class Amazon(callbacks.Privmsg,configurable.Mixin):
|
|||||||
s = '"%(title)s"%(url)s'
|
s = '"%(title)s"%(url)s'
|
||||||
try:
|
try:
|
||||||
item = amazon.searchByASIN(asin)
|
item = amazon.searchByASIN(asin)
|
||||||
bold = self.configurables.get('bold', msg.args[0])
|
bold = conf.supybot.plugins.Amazon.bold()
|
||||||
res = self._genResults(s, attribs, item, url, bold, 'title')
|
res = self._genResults(s, attribs, item, url, bold, 'title')
|
||||||
if res:
|
if res:
|
||||||
irc.reply(utils.commaAndify(res))
|
irc.reply(utils.commaAndify(res))
|
||||||
@ -277,7 +276,7 @@ class Amazon(callbacks.Privmsg,configurable.Mixin):
|
|||||||
s = '"%(title)s" %(manufacturer)s%(url)s'
|
s = '"%(title)s" %(manufacturer)s%(url)s'
|
||||||
try:
|
try:
|
||||||
item = amazon.searchByUPC(upc)
|
item = amazon.searchByUPC(upc)
|
||||||
bold = self.configurables.get('bold', msg.args[0])
|
bold = conf.supybot.plugins.Amazon.bold()
|
||||||
res = self._genResults(s, attribs, item, url, bold, 'title')
|
res = self._genResults(s, attribs, item, url, bold, 'title')
|
||||||
if res:
|
if res:
|
||||||
irc.reply(utils.commaAndify(res))
|
irc.reply(utils.commaAndify(res))
|
||||||
@ -310,7 +309,7 @@ class Amazon(callbacks.Privmsg,configurable.Mixin):
|
|||||||
'%(publisher)s%(url)s'
|
'%(publisher)s%(url)s'
|
||||||
try:
|
try:
|
||||||
books = amazon.searchByAuthor(author)
|
books = amazon.searchByAuthor(author)
|
||||||
bold = self.configurables.get('bold', msg.args[0])
|
bold = conf.supybot.plugins.Amazon.bold()
|
||||||
res = self._genResults(s, attribs, books, url, bold, 'title')
|
res = self._genResults(s, attribs, books, url, bold, 'title')
|
||||||
if res:
|
if res:
|
||||||
irc.reply(utils.commaAndify(res))
|
irc.reply(utils.commaAndify(res))
|
||||||
@ -408,7 +407,7 @@ class Amazon(callbacks.Privmsg,configurable.Mixin):
|
|||||||
'%(publisher)s%(url)s'
|
'%(publisher)s%(url)s'
|
||||||
try:
|
try:
|
||||||
items = amazon.searchByArtist(artist, product_line=product)
|
items = amazon.searchByArtist(artist, product_line=product)
|
||||||
bold = self.configurables.get('bold', msg.args[0])
|
bold = conf.supybot.plugins.Amazon.bold()
|
||||||
res = self._genResults(s, attribs, items, url, bold, 'title')
|
res = self._genResults(s, attribs, items, url, bold, 'title')
|
||||||
if res:
|
if res:
|
||||||
irc.reply(utils.commaAndify(res))
|
irc.reply(utils.commaAndify(res))
|
||||||
@ -448,7 +447,7 @@ class Amazon(callbacks.Privmsg,configurable.Mixin):
|
|||||||
'%(date)s; published by %(publisher)s%(url)s'
|
'%(date)s; published by %(publisher)s%(url)s'
|
||||||
try:
|
try:
|
||||||
items = amazon.searchByActor(actor, product_line=product)
|
items = amazon.searchByActor(actor, product_line=product)
|
||||||
bold = self.configurables.get('bold', msg.args[0])
|
bold = conf.supybot.plugins.Amazon.bold()
|
||||||
res = self._genResults(s, attribs, items, url, bold, 'title')
|
res = self._genResults(s, attribs, items, url, bold, 'title')
|
||||||
if res:
|
if res:
|
||||||
irc.reply(utils.commaAndify(res))
|
irc.reply(utils.commaAndify(res))
|
||||||
@ -488,7 +487,7 @@ class Amazon(callbacks.Privmsg,configurable.Mixin):
|
|||||||
'%(date)s; published by %(publisher)s%(url)s'
|
'%(date)s; published by %(publisher)s%(url)s'
|
||||||
try:
|
try:
|
||||||
items = amazon.searchByDirector(director, product_line=product)
|
items = amazon.searchByDirector(director, product_line=product)
|
||||||
bold = self.configurables.get('bold', msg.args[0])
|
bold = conf.supybot.plugins.Amazon.bold()
|
||||||
res = self._genResults(s, attribs, items, url, bold, 'title')
|
res = self._genResults(s, attribs, items, url, bold, 'title')
|
||||||
if res:
|
if res:
|
||||||
irc.reply(utils.commaAndify(res))
|
irc.reply(utils.commaAndify(res))
|
||||||
@ -527,7 +526,7 @@ class Amazon(callbacks.Privmsg,configurable.Mixin):
|
|||||||
try:
|
try:
|
||||||
items = amazon.searchByManufacturer(manufacturer,
|
items = amazon.searchByManufacturer(manufacturer,
|
||||||
product_line=product)
|
product_line=product)
|
||||||
bold = self.configurables.get('bold', msg.args[0])
|
bold = conf.supybot.plugins.Amazon.bold()
|
||||||
res = self._genResults(s, attribs, items, url, bold, 'title')
|
res = self._genResults(s, attribs, items, url, bold, 'title')
|
||||||
if res:
|
if res:
|
||||||
irc.reply(utils.commaAndify(res))
|
irc.reply(utils.commaAndify(res))
|
||||||
|
@ -31,14 +31,14 @@
|
|||||||
|
|
||||||
from testsupport import *
|
from testsupport import *
|
||||||
|
|
||||||
LICENSE_KEY = 'INITIAL_NON_LICENSE_KEY'
|
LICENSE_KEY = 'AMAZONS_NOT_CHECKING_KEYS'
|
||||||
|
|
||||||
if LICENSE_KEY != 'INITIAL_NON_LICENSE_KEY' and network:
|
if LICENSE_KEY != 'INITIAL_NON_LICENSE_KEY' and network:
|
||||||
class AmazonTestCase(PluginTestCase, PluginDocumentation):
|
class AmazonTestCase(PluginTestCase, PluginDocumentation):
|
||||||
plugins = ('Amazon',)
|
plugins = ('Amazon',)
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
PluginTestCase.setUp(self)
|
PluginTestCase.setUp(self)
|
||||||
self.assertNotError('licensekey %s' % LICENSE_KEY)
|
conf.supybot.plugins.amazon.licensekey.set(LICENSE_KEY)
|
||||||
|
|
||||||
def testIsbn(self):
|
def testIsbn(self):
|
||||||
self.assertHelp('isbn')
|
self.assertHelp('isbn')
|
||||||
@ -62,7 +62,7 @@ if LICENSE_KEY != 'INITIAL_NON_LICENSE_KEY' and network:
|
|||||||
def testAuthor(self):
|
def testAuthor(self):
|
||||||
self.assertHelp('author')
|
self.assertHelp('author')
|
||||||
self.assertRegexp('author torvalds', r'Just for Fun')
|
self.assertRegexp('author torvalds', r'Just for Fun')
|
||||||
self.assertRegexp('author --url torvalds', r'Linus.*/exec/obidos')
|
self.assertRegexp('author --url torvalds', r'Reilly.*/exec/obidos')
|
||||||
|
|
||||||
def testArtist(self):
|
def testArtist(self):
|
||||||
self.assertHelp('artist')
|
self.assertHelp('artist')
|
||||||
|
Loading…
Reference in New Issue
Block a user