示例#1
0
文件: agave.py 项目: Bronan/Agave
def emulateIDU():
	"""Emulate an IDU"""
	ui.clear()
	ui.setInIDU(True)
	ui.writeToConsole(etc.IDU_TEXT)
	opsys.setTitleText("COM5:38400baud - Tera Term VT")
	
	ui.getUserMsg("", sleepEn=False, pwd=True, log=False)
	getUser = True
	while getUser:
		username = ""
		while username == "":
			username = ui.getUserMsg("SDIDU login: "******"Password: "******"factory") or (username == "root")
		if user and ((password == "exit") or (password == "arct1c")):
			opsys.exit()
		elif user and (password == "resume"):
			getUser = False
		else:
			ui.writeToConsole("Login incorrect")
	
	opsys.setTitleText(TITLE)
	ui.clear()
	ui.setInIDU(False)
	ui.writeToConsole(msgLog)
示例#2
0
文件: agave.py 项目: Bronan/Agave
def processMessage():
	"""Parse incoming commands and print messages."""
	while True:
		msg, sendersIP = traffic.listenToSocket()
		
		# Update heartbeat
		heartbeats[sendersIP] = time.time()
		if not sendersIP in peers:
			peers[sendersIP] = sendersIP
			mode[sendersIP] = len(MODE_TEXT)-1
			sendStatus(traffic.GREET, ips=sendersIP)
			printMsg(peers[sendersIP] + " has joined the party.")
		
		# Parse or print message
		if msg.startswith(traffic.QUIT):
			delPeer(sendersIP)
		elif msg.startswith(traffic.HEARTBEAT):
			parseStatus(msg[len(traffic.HEARTBEAT):], sendersIP)
		elif msg.startswith(traffic.GREET):
			parseStatus(msg[len(traffic.GREET):], sendersIP)
			sendStatus()
		elif msg.startswith(traffic.KICK):
			traffic.sendText(traffic.QUIT, peers.keys())
			opsys.exit()
		else:
			if msg.startswith(traffic.AGAVEBOT):
				printMsg("Agavebot: " + msg[len(AGAVEBOT):])
			elif msg.startswith(traffic.COMMAND_CHAR + traffic.COMMAND_CHAR):
				printMsg(peers[sendersIP] + ": " + msg[len(traffic.COMMAND_CHAR):])
			else:
				printMsg(peers[sendersIP] + ": " + msg[:])
			if botPower:
				msg = botResponses[random.randint(0, len(botResponses)-1)]
				traffic.sendText(traffic.AGAVEBOT + msg, peers.keys())
				printMsg("Agavebot: " + msg)
示例#3
0
文件: agave.py 项目: Bronan/Agave
def handleUser():
	"""Get and parse user input."""
	global botPower
	hiberCounter = 0
	
	# Get and process user input
	while True:
		# Get user input
		prompt = peers[LOCAL_IP] + ": "
		inputString = sleepPrompt(prompt)
		msgLog.append(prompt + inputString)
		
		# Process user input
		if len(inputString) > 0:
			commandString = inputString.lower()
			hiberCounter = 0
			if commandString.startswith(etc.AGAVEBOT):
				botPower = not botPower
				if botPower:
					printMsg("Agavebot: Agavebot is now activated.")
				else:
					printMsg("Agavebot: Why do you hate agavebot?")
			elif commandString.startswith(etc.CLEAR):
				ui.clear()
			elif commandString.startswith(etc.KICK):
				traffic.sendText(traffic.KICK, inputString[len(etc.KICK):])
			elif commandString.startswith(etc.HELP):
				printMsg(etc.help(ui.getCols(), VERSION, HIBER_NUM))
			elif commandString.startswith(etc.NICK):
				if len(inputString[len(etc.NICK):]) > 2:
					database.setNick(inputString[len(etc.NICK):])
					peers[LOCAL_IP] = inputString[len(etc.NICK):]
					sendStatus()
				else:
					printMsg("Nicknames must be at least 3 characters long.")
			elif (commandString.startswith(etc.QUIT) or commandString.startswith(etc.EXIT)):
				traffic.sendText(traffic.QUIT, peers.keys())
				opsys.exit()
			elif commandString.startswith(etc.WHOS):
				whosString = "\nPeer IP addresses  | Mode       | Peer nicknames\n" + "".center(34,"-")
				for ip in peers:
					whosString += "\n"
					if ip == LOCAL_IP:
						whosString += "-->"
					else:
						whosString += "   "
					whosString += ip.ljust(18) + MODE_TEXT[mode[ip]].ljust(13) + peers[ip]
				printMsg(whosString)
			elif commandString.startswith(etc.AWAY):
				setMode(AWAY)
				emulateIDU()
				setMode(CHAT)
			elif commandString.startswith("$test".lower()):
				printMsg(msgLog, log=False)
			else:
				if commandString.startswith(traffic.COMMAND_CHAR):
					inputString = traffic.COMMAND_CHAR + inputString
				traffic.sendText(inputString, peers.keys())
		else:
			msgLog.pop()
			hiberCounter += 1
			if hiberCounter >= HIBER_NUM:
				setMode(HIBERNATE)
				opsys.closePopup()
				emulateIDU()
				setMode(CHAT)
				opsys.resumePopup()