diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/anidb.py | 24 | ||||
-rw-r--r-- | modules/google_search.py | 26 | ||||
-rw-r--r-- | modules/quotes.py | 7 | ||||
-rw-r--r-- | modules/tracking.py | 14 | ||||
-rw-r--r-- | modules/url_titles.py | 3 |
5 files changed, 36 insertions, 38 deletions
diff --git a/modules/anidb.py b/modules/anidb.py index 7a5a761..fbc9e11 100644 --- a/modules/anidb.py +++ b/modules/anidb.py @@ -21,6 +21,7 @@ class Module: def __init__(self, bot): self.irc = bot self.db = PgSQL.connect(database = 'fot') + 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 diff --git a/modules/google_search.py b/modules/google_search.py index 625cdf2..8af2c62 100644 --- a/modules/google_search.py +++ b/modules/google_search.py @@ -9,6 +9,7 @@ import urllib, urllib2, simplejson class Module: def __init__(self, bot): self.irc = bot + self.irc.register_keyword('!g', self) def search(self, s): try: @@ -24,19 +25,18 @@ class Module: return return (response['results'][0]['titleNoFormatting'], response['results'][0]['url']) - def __call__(self, nick, channel, msg): - if msg.startswith('!g'): - target = channel if not channel == self.irc.nickname else nick.split('!')[0] - args = msg.split() - if len(args) == 1: - self.irc.msg(target, 'Usage: !g search') - return - results = self.search(' '.join(args[1:])) - if results: - results = '\002%s\002 %s' % results - self.irc.msg(target, results.encode('utf-8')) - else: - self.irc.msg(target, 'No results.') + 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: !g search') + return + results = self.search(' '.join(args)) + if results: + results = '\002%s\002 %s' % results + self.irc.msg(target, results.encode('utf-8')) + else: + self.irc.msg(target, 'No results.') if __name__ == '__main__': import sys diff --git a/modules/quotes.py b/modules/quotes.py index a5060cd..772701c 100644 --- a/modules/quotes.py +++ b/modules/quotes.py @@ -201,13 +201,10 @@ quote_handler = IRCHandler() class Module: def __init__(self, bot): self.irc = bot + self.irc.register_keyword('!quote', self) - def __call__(self, nick, channel, msg): - if not msg.startswith('!quote'): - return + def keyword(self, nick, channel, kw, msg): args = msg.split(' ') - if msg.startswith('!quote'): - args = args[1:] cmd = args[0] if len(args) and len(args[0].strip()) else 'random' args = args[1:] diff --git a/modules/tracking.py b/modules/tracking.py index 94b8d86..aa33980 100644 --- a/modules/tracking.py +++ b/modules/tracking.py @@ -54,6 +54,7 @@ class Module: def __init__(self, bot): self.setup_db() self.irc = bot + self.irc.register_keyword('!track', self) self.tracking = [] self.lc = LoopingCall(self.lc_callback) if bot: @@ -200,21 +201,18 @@ class Module: session.close() return msg - def __call__(self, nick, channel, msg): - if not msg.startswith('!track'): - return - + def keyword(self, nick, channel, kw, msg): args = msg.split() - if len(args) < 2: + if len(args) < 1: self.irc.msg(channel if not channel == self.irc.nickname else nick.split('!')[0], 'Usage: !track (start|stop|status TRACKINGNO)|list') return - mode = args[1] + mode = args[0] if mode.lower() in ('start', 'stop', 'status'): - if len(args) != 3 and mode.lower() != 'status': + if len(args) != 2 and mode.lower() != 'status': self.irc.msg(channel if not channel == self.irc.nickname else nick.split('!')[0], 'Usage: !track (start|stop|status TRACKINGNO)|list') return - code = args[2] if len(args) == 3 else '' + code = args[1] if len(args) == 2 else '' msg = None if mode.lower() == 'start': diff --git a/modules/url_titles.py b/modules/url_titles.py index d5408ce..3172fac 100644 --- a/modules/url_titles.py +++ b/modules/url_titles.py @@ -15,6 +15,7 @@ class Module: def __init__(self, bot): self.irc = bot + self.irc.register_callback(self) def spotify(self, s): try: @@ -137,7 +138,7 @@ class Module: s += '\002[%d]\002 %s ' % (i+1, format_text(titles[i])) return s.strip() - def __call__(self, nick, channel, msg): + def privmsg(self, nick, channel, msg): titles = self.get_titles(msg) if titles: self.irc.msg(channel if not channel == self.irc.nickname else nick.split('!')[0], titles) |