diff options
Diffstat (limited to 'modules/anidb.py')
-rw-r--r-- | modules/anidb.py | 26 |
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 |