Esempio n. 1
0
def sendprint( packet ):
	try:
		if packet['command'] == "PONG":
			return # Ingore PONGs
		if __main__.database['globals']['debug']:
			__main__.senddebugprint( packet['raw'], packet['timestamp'] )
		else:
			toprint = ""
			# Don't overwrite a part of packet
			# TODO: Just replace newlines etc; spaces are valid at the ends!
			packetrest = packet['rest'].rstrip()
			user = __main__.database['api']['ircsettings']['nick']
			if packet['command'] == "PRIVMSG":
				locMessage = packetrest.partition( " :" )
				if locMessage[0] in __main__.database['api']['ircsettings']['channels']: #channel message
					if not locMessage[2].startswith( "\x01ACTION" ):
						toprint = "[" + locMessage[0] + "] " + user + ": " + locMessage[2]
					else:
						toprint = "[" + locMessage[0] + "] *" + user + locMessage[2][7:-1]
				else: #PM
					if locMessage[2][0] != "\x01":
						toprint = ">" + locMessage[0] + "<: " + locMessage[2]
					else: #CTCP or ME
						if locMessage[2].startswith( "\x01ACTION" ): #ME
							toprint = ">" + locMessage[0] + "< *" + user + locMessage[2][7:-1]
						else:
							pass #TODO
							#toprint = "Received a CTCP " + locMessage[2][1:-1] + " from " + user
			elif packet['command'] == "PART":
				locMessage = packetrest.partition( " :" )
				toprint = "[" + locMessage[0] + "] " + user + " has left (Part: " + locMessage[2] + ")"
			elif packet['command'] == "JOIN":
				if packetrest[0] != "#": # HACK: Some networks send an extra character here, and some don't...
					packetrest = packetrest[1:]
				toprint = "[" + packetrest + "] " + user + " has joined"
			elif packet['command'] == "QUIT":
				toprint = user + " has quit (Quit: " + packetrest[1:] + ")"
			elif packet['command'] == "NICK":
				toprint = user + " is now known as " + packetrest
			elif packet['command'] == "TOPIC":
				locTopic = packetrest.partition( " :" )
				toprint = "[" + locTopic[0] + "] " + user + " has changed the topic to: " + locTopic[2]
			elif packet['command'] == "INVITE":
				locMessage = packetrest.partition( " :" )
				toprint = user + " has invited " + locMessage[0] + " to " + locMessage[2]
			if toprint != "":
				__main__.sendregularprint( toprint, packet['timestamp'] )
	except Exception as err: # Really. REALLY.
		__main__.errorprint( "Exception in sendprint:" )
		__main__.warnprint( pybotutils.getExceptionTraceback( err ) )