From 52be3b3b2bd6a9d83570de43b6c5c4ee859bd974 Mon Sep 17 00:00:00 2001 From: Eevee Date: Mon, 1 Feb 2010 20:05:04 -0800 Subject: [PATCH] =?utf8?q?Stubbed=20out=20Pok=C3=A9dex=20plugin.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- plugins/Pokedex/__init__.py | 10 +++--- plugins/Pokedex/config.py | 7 ++-- plugins/Pokedex/plugin.py | 87 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 95 insertions(+), 9 deletions(-) diff --git a/plugins/Pokedex/__init__.py b/plugins/Pokedex/__init__.py index d25615c..d1482f5 100644 --- a/plugins/Pokedex/__init__.py +++ b/plugins/Pokedex/__init__.py @@ -1,3 +1,4 @@ +# encoding: utf8 ### # Copyright (c) 2010, Alex Munroe # All rights reserved. @@ -29,8 +30,7 @@ ### """ -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 @@ -38,17 +38,17 @@ import supybot.world as world # 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 diff --git a/plugins/Pokedex/config.py b/plugins/Pokedex/config.py index 8a4b079..9e538ea 100644 --- a/plugins/Pokedex/config.py +++ b/plugins/Pokedex/config.py @@ -1,3 +1,4 @@ +# encoding: utf8 ### # Copyright (c) 2010, Alex Munroe # All rights reserved. @@ -41,9 +42,9 @@ def configure(advanced): Pokedex = conf.registerPlugin('Pokedex') -# This is where your configuration variables (if any) should go. For example: -# conf.registerGlobalValue(Pokedex, 'someConfigVariableName', -# registry.Boolean(False, """Help for someConfigVariableName.""")) +conf.registerGlobalValue(Pokedex, 'databaseURL', + registry.String('', """SQLAlchemy-compatible URL to the pokedex + database.""")) # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: diff --git a/plugins/Pokedex/plugin.py b/plugins/Pokedex/plugin.py index b81ced2..77de7d9 100644 --- a/plugins/Pokedex/plugin.py +++ b/plugins/Pokedex/plugin.py @@ -1,3 +1,4 @@ +# encoding: utf8 ### # Copyright (c) 2010, Alex Munroe # All rights reserved. @@ -34,11 +35,95 @@ import supybot.plugins as plugins 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): + """ + + Looks up 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 -- 2.7.4