Example #1
0
def parse_cmd(sender, destination, message):
	global switch, closing, channel_options
	if destination.replace(' ', '') == config_options['irc_nickname']:
		destination = sender
	try:
		if simplify(message)[:4] == 'echo':
			arg = message.replace("\r\n", "")
			if len(arg) == 4:
				chat(destination, 'Echo..echo...echo... ^^')
			else:
				msg = arg[4:]
				if msg[0] == ' ':
					msg = msg[1:]
				chat(destination, msg + "\r\n")
		elif simplify(message)[:4] == 'call':
			msg = message.replace('\r', '').replace('\n', '').replace('call ', 'call')[4:]
			if len(simplify(msg)) == 0:
				msg = 'No Message'
			string = '%s - PING from %s: %s' % (hextime(), sender.replace(' ', ''), msg)
			cmd = '/bin/bash /root/sendtxt.sh "%s"' % urllib2.quote(string)
			print cmd
			os.system(cmd)
			chat(sender, 'Echo35 has been notified. However, I cannot guarantee they are available at the moment.')
		elif simplify(message)[:4] == 'time':
			chat(destination, hextime())
		elif simplify(message)[:2] == 'lt':
			chat(destination, get_last_tweet().text)
		elif simplify(message)[:3] == 'plt':
			chat(destination, parse_tweet(get_last_tweet()))
		elif message.lower()[:4] == 'cmd ':
			chat(destination, isla_cypher.parse(message[4:]))
		elif simplify(message)[:7] == 'channel':
			if sender != 'echo35':
				chat(sender, 'You don\'t have permission to set my channel.')
				return
			channel = message.replace('\r\n', '').lower()[8:]
			if channel[0] != '#':
					channel = '#' + channel
			if message.replace('\r\n', '').lower()[:13] == 'channel join ':
				if channel in channel_options:
					chat(sender, 'I am already in ' + channel + ".")
					return
				channel = message.replace('\r\n', '').lower()[13:]
				if channel[0] != '#':
					channel = '#' + channel
				irc.send('JOIN ' + channel + '\r\n')
				chat(sender, 'Joined channel ' + channel + '\r\n')
				channel_options[channel] = copy.deepcopy(channel_defaults)
			elif message.replace('\r\n', '').lower()[:13] == 'channel part ':
				channel = message.replace('\r\n', '').lower()[13:]
				del channel_options[channel]
				irc.send('PART ' + channel + '\r\n')
				chat(sender, 'Left channel ' + channel + '\r\n')
				return
			config_options['irc_channel'] = channel
			chat(sender, 'Now focusing on channel ' + config_options['irc_channel'])
		elif simplify(message).lower()[:3] == 'say':
			msg = message[3:]
			if sender != 'echo35':
				chat(sender, 'You don\'t have permission to use my elegant voice!')
			elif len(msg) > 0:
				if msg[0] == ' ':
					msg = msg[1:]
				chat(config_options['irc_channel'], msg + "\r\n")
		elif simplify(message)[:3] == 'def' or message[:1] == '?':
			# print 'defining ' + message.replace('?', 'def')[3:]
			# print 'got ' + get_definition(message.replace('?', 'def')[3:])
			chat(destination, get_definition(simplify(message.replace('\n', '').replace('?', 'def')[3:])))
		elif message.replace('\r\n', '').lower() == 'poweroff':
			if sender.replace('@', '') == 'echo35':
				broadcast('An operator has powered me down. Goodbye!')
				irc.send('QUIT\r\n')
				closing = True
				exit()
			else:
				chat(sender, 'You don\'t have permission to power me down.')
		else:
			return

	except:
		print 'Failed to interpret command.'
		chat(sender, 'You broke me! Something glitched, your last message has been saved and will be analyzed to find out what went wrong.')
		file = open('acronymous.log', 'a')
		file.write('[%s %s]: Error parsing command \'%s\'\n' % (ircbot_lib.current_date(config_options['date_format']), ircbot_lib.current_time(config_options['time_format']), message.replace("\r\n", '')))
		file.close()
Example #2
0
def parse_tweet(tweet):
	return isla_cypher.parse(tweet.text)