summaryrefslogtreecommitdiff
path: root/modules/anidb.py
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-05-26 18:33:03 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2010-05-26 18:33:03 +0200
commitc23d205928499b578e0742363dbfd8dc0116f394 (patch)
tree3b28becd52bd3cee3af26b6bcbd484df8bc4dd9f /modules/anidb.py
parentb4b59bf076d8d4ec22b489174707ecda72a1c06e (diff)
Replaced module's __call__ with a keyword mechanism.
Diffstat (limited to 'modules/anidb.py')
-rw-r--r--modules/anidb.py26
1 files changed, 14 insertions, 12 deletions
diff --git a/modules/anidb.py b/modules/anidb.py
index 7a5a761..3c8302e 100644
--- a/modules/anidb.py
+++ b/modules/anidb.py
@@ -20,7 +20,8 @@ for option in ('username', 'password'):
class Module:
def __init__(self, bot):
self.irc = bot
- self.db = PgSQL.connect(database = 'fot')
+ self.db = PgSQL.connect(database = 'fot', host = 'komachi.')
+ self.irc.register_keyword('!anidb', self)
def get_aid(self, msg, short = False):
if msg.isdigit():
@@ -85,9 +86,11 @@ class Module:
aid)
def get_anime(self, msg):
- short = msg.startswith('-s ')
+ short = msg.startswith('-s')
if short:
msg = ' '.join(msg.split()[1:])
+ if not len(msg):
+ return 'Usage: !anidb [-s] search|aid'
aid = self.get_aid(msg, short)
if len(aid) == 1:
return self.get_info(aid[0][0])
@@ -97,16 +100,15 @@ class Module:
else:
return 'anidb: %s%s' % ('%d/%d results: ' % (5, len(aid)) if len(aid) > 5 else '', ', '.join(['%s (%d)' % (x[1], x[0]) for x in aid[:5]]))
- def __call__(self, nick, channel, msg):
- if msg.startswith('!anidb'):
- target = channel if not channel == self.irc.nickname else nick.split('!')[0]
- args = msg.split()
- if len(args) == 1:
- self.irc.msg(target, 'Usage: !anidb [-s] search|aid')
- return
- info = self.get_anime(' '.join(args[1:]))
- if info:
- self.irc.msg(target, info)
+ def keyword(self, nick, channel, kw, msg):
+ target = channel if not channel == self.irc.nickname else nick.split('!')[0]
+ args = msg.split()
+ if len(args) == 0:
+ self.irc.msg(target, 'Usage: !anidb [-s] search|aid')
+ return
+ info = self.get_anime(' '.join(args))
+ if info:
+ self.irc.msg(target, info)
if __name__ == '__main__':
import sys