Exemplo n.º 1
0
	def log_event(self, event):
		target = ''
		args = ''

		# don't log my own events, those should already be IRCActions!
		if event.source == self.nickname:
			return

		# chat messages are not events.
		if event.command == "PRIVMSG":
			return

		# determine command
		if event.command == "MODE":
			full = "MODE " + event.params[0]
			try:
				cmd = IRCCommand.objects.get(command=full)
				target = event.params[1]
			except IRCCommand.DoesNotExist:
				return
		else:
			try:
				cmd = IRCCommand.objects.get(command=event.command)
				target = event.params[0]
			except IRCCommand.DoesNotExist:
				return

		comment = "issued via command"
	
		# find user
		#TODO: handle unknown user
		try:
			user = IRCHost.objects.get(hostname=event.host).user
		except IRCHost.DoesNotExist:
			comment += ": " + str(event.source) + "@" + str(event.host)
			user = User.objects.get(username="******")

		new_action = IRCAction()
		new_action.user = user
		new_action.command = cmd
		new_action.target = target
		new_action.args = args
		new_action.comment = comment
		new_action.performed = True
		new_action.save()
Exemplo n.º 2
0
	def process_chat_command(self, event):
		# does an authorized user even exist?
		try:
			user = IRCHost.objects.get(hostname=event.host).user
		except IRCHost.DoesNotExist:
			return

		# were we issued a valid command?
		msg = event.params[0]
		if msg[0] == "!":
			tokens = msg.split()
			chat_command = tokens[0]

			try:
				cmd = IRCCommand.objects.get(chat_command=chat_command)
			except IRCCommand.DoesNotExist:
				return

			# who is the target?
			if len(tokens) == 1:
				target = event.source
			else:
				target = tokens[1]

			# is the user allowed to issue this command?
			#TODO: actually handle some exceptions here.
			try:
				if user.userprofile.level >= cmd.level:
					new_action = IRCAction()
					new_action.command = cmd
					new_action.user = user
					new_action.target = target
					new_action.args = ''
					new_action.comment = "issued via msg: " + str(event.params[0])
					new_action.performed = False
					new_action.save()
					self.process_queue(event)
				else:
					self.send_notice(event.source, "permission denied")
			except:
				pass