summaryrefslogtreecommitdiff
path: root/modules/quotes.py
blob: 873f0f38c8aba3a1fd7795d02c813ffca90024a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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()

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))