84e9cf9673afee76dd7e0d965d98a30cd5b16c1c
3 # Copyright (c) 2010, Alex Munroe
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
9 # * Redistributions of source code must retain the above copyright notice,
10 # this list of conditions, and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above copyright notice,
12 # this list of conditions, and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # * Neither the name of the author of this software nor the name of
15 # contributors to this software may be used to endorse or promote products
16 # derived from this software without specific prior written consent.
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 # POSSIBILITY OF SUCH DAMAGE.
32 import supybot
.conf
as conf
33 import supybot
.utils
as utils
34 from supybot
.commands
import *
35 import supybot
.plugins
as plugins
36 import supybot
.ircutils
as ircutils
37 import supybot
.callbacks
as callbacks
40 import pokedex
.db
.tables
as tables
43 class Pokedex(callbacks
.Plugin
):
44 """Add the help for "@plugin help Pokedex" here
45 This should describe *how* to use this plugin."""
46 def __init__(self
, irc
):
47 self
.__parent
= super(Pokedex
, self
)
48 self
.__parent
.__init__(irc
)
49 self
.db
= pokedex
.db
.connect(self
.registryValue('databaseURL'))
50 self
.indices
= pokedex
.lookup
.open_index(
51 directory
=conf
.supybot
.directories
.data
.dirize('pokedex-index'),
55 def pokedex(self
, irc
, msg
, args
, thing
):
58 Looks up <thing> in the veekun Pokédex."""
60 # Similar logic to the site, here.
61 results
= pokedex
.lookup
.lookup(thing
, session
=self
.db
,
66 irc
.reply("I don't know what that is.")
69 # Multiple matches; propose them all
72 reply
= "Are you looking for"
74 reply
= "Did you mean"
76 # For exact name matches with multiple results, use type prefixes
77 # (item:Metronome). For anything else, omit them
78 use_prefixes
= (results
[0].exact
83 for result
in results
:
84 result_string
= result
.name
86 # Table classes know their singular names
87 prefix
= result
.object.__singlename__
88 result_string
= prefix
+ ':' + result_string
89 result_strings
.append(result_string
)
91 irc
.reply("{0}: {1}?".format(reply
, '; '.join(result_strings
)))
94 # If we got here, there's an exact match; hurrah!
96 if isinstance(result
.object, tables
.Pokemon
):
97 irc
.reply("""{name}, {type}-type Pokémon.""".format(
98 name
=result
.object.name
,
99 type='/'.join(_
.name
for _
in result
.object.types
),
103 elif isinstance(result
.object, tables
.Move
):
104 irc
.reply("""{name}, {type}-type move.""".format(
105 name
=result
.object.name
,
106 type=result
.object.type.name
,
110 elif isinstance(result
.object, tables
.Type
):
111 irc
.reply("""{name}, a type.""".format(
112 name
=result
.object.name
,
116 elif isinstance(result
.object, tables
.Item
):
117 irc
.reply("""{name}, an item.""".format(
118 name
=result
.object.name
,
122 elif isinstance(result
.object, tables
.Ability
):
123 irc
.reply("""{name}, an ability.""".format(
124 name
=result
.object.name
,
129 # This can only happen if lookup.py is upgraded and we are not
130 irc
.reply("Uhh.. I found that, but I don't know what it is. :(")
132 pokedex
= wrap(pokedex
, [rest('something')])
138 # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: