+# encoding: utf8
###
# Copyright (c) 2010, Alex Munroe
# All rights reserved.
###
"""
-Add a description of the plugin (to be presented to the user inside the wizard)
-here. This should describe *what* the plugin does.
+Provides a Pokédex lookup interface.
"""
import supybot
# Use this for the version of this plugin. You may wish to put a CVS keyword
# in here if you're keeping the plugin in CVS or some similar system.
-__version__ = ""
+__version__ = "0.1"
# XXX Replace this with an appropriate author or supybot.Author instance.
-__author__ = supybot.authors.unknown
+__author__ = supybot.Author('Alex Munroe', 'Eevee', 'git@veekun.com')
# This is a dictionary mapping supybot.Author instances to lists of
# contributions.
__contributors__ = {}
# This is a url where the most recent plugin package can be downloaded.
-__url__ = '' # 'http://supybot.com/Members/yourname/Pokedex/download'
+__url__ = 'http://git.veekun.com/?p=dywypi.git;a=summary'
import config
import plugin
+# encoding: utf8
###
# Copyright (c) 2010, Alex Munroe
# All rights reserved.
import supybot.ircutils as ircutils
import supybot.callbacks as callbacks
+import pokedex.db
+import pokedex.db.tables as tables
+import pokedex.lookup
class Pokedex(callbacks.Plugin):
"""Add the help for "@plugin help Pokedex" here
This should describe *how* to use this plugin."""
- pass
+ def __init__(self, irc):
+ self.__parent = super(Pokedex, self)
+ self.__parent.__init__(irc)
+ self.db = pokedex.db.connect(self.registryValue('databaseURL'))
+
+ def pokedex(self, irc, msg, args, thing):
+ """<thing...>
+
+ Looks up <thing> in the veekun Pokédex."""
+
+ # Similar logic to the site, here.
+ results = pokedex.lookup.lookup(thing, session=self.db)
+
+ # Nothing found
+ if len(results) == 0:
+ irc.reply("I don't know what that is.")
+ return
+
+ # Multiple matches; propose them all
+ if len(results) > 1:
+ if results[0].exact:
+ reply = "Are you looking for"
+ else:
+ reply = "Did you mean"
+
+ # For exact name matches with multiple results, use type prefixes
+ # (item:Metronome). For anything else, omit them
+ use_prefixes = (results[0].exact
+ and '*' not in thing
+ and '?' not in thing)
+
+ result_strings = []
+ for result in results:
+ result_string = result.name
+ if use_prefixes:
+ # Table classes know their singular names
+ prefix = result.object.__singlename__
+ result_string = prefix + ':' + result_string
+ result_strings.append(result_string)
+
+ irc.reply("{0}: {1}?".format(reply, '; '.join(result_strings)))
+ return
+
+ # If we got here, there's an exact match; hurrah!
+ result = results[0]
+ if isinstance(result.object, tables.Pokemon):
+ irc.reply("""{name}, {type}-type Pokémon.""".format(
+ name=result.object.name,
+ type='/'.join(_.name for _ in result.object.types),
+ )
+ )
+
+ elif isinstance(result.object, tables.Move):
+ irc.reply("""{name}, {type}-type move.""".format(
+ name=result.object.name,
+ type=result.object.type.name,
+ )
+ )
+
+ elif isinstance(result.object, tables.Type):
+ irc.reply("""{name}, a type.""".format(
+ name=result.object.name,
+ )
+ )
+
+ elif isinstance(result.object, tables.Item):
+ irc.reply("""{name}, an item.""".format(
+ name=result.object.name,
+ )
+ )
+
+ elif isinstance(result.object, tables.Ability):
+ irc.reply("""{name}, an ability.""".format(
+ name=result.object.name,
+ )
+ )
+
+ else:
+ # This can only happen if lookup.py is upgraded and we are not
+ irc.reply("Uhh.. I found that, but I don't know what it is. :(")
+
+ pokedex = wrap(pokedex, [rest('something')])
Class = Pokedex