diff options
Diffstat (limited to 'modules/quotes.py')
-rw-r--r-- | modules/quotes.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/modules/quotes.py b/modules/quotes.py new file mode 100644 index 0000000..b8eb988 --- /dev/null +++ b/modules/quotes.py @@ -0,0 +1,33 @@ +info = { + 'author': 'Jon Bergli Heier', + 'title': 'IRC Quotes', + 'description': 'Allows users to access a quote database.', +} + +import sys +sys.path.insert(0, '/home/snakebite/py') +from quotelib import IRCHandler as Quote_IRCHandler +quote_handler = Quote_IRCHandler('/home/snakebite/quotes.db') + +class Module: + def __init__(self, bot): + self.irc = bot + + def __call__(self, nick, channel, msg): + if not msg.startswith('!quote'): + return + 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:] + + if cmd.isdigit() or (cmd[0] == '#' and cmd[1:].isdigit()): + cmd, args = 'get', [cmd] + + quote_handler.nick = nick.split('!')[0] + if hasattr(quote_handler, cmd) and callable(getattr(quote_handler, cmd)): + for line in getattr(quote_handler, cmd)(*args): + self.irc.msg(channel if not channel == self.irc.nickname else nick.split('!')[0], line) + else: + self.irc.msg(channel if not channel == self.irc.nickname else nick.split('!')[0], '%s, invalid command "%s"' % (nick.split('!')[0], cmd)) |