Exemple #1
0
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()
Exemple #2
0
		else:
			ui.writeToConsole("Login incorrect")
	
	opsys.setTitleText(TITLE)
	ui.clear()
	ui.setInIDU(False)
	ui.writeToConsole(msgLog)

if __name__ == "__main__":
	"""Initialize and run threads."""
	# Set current mode
	mode[LOCAL_IP] = CHAT
	
	# Clear screen and welcome user
	ui.clear()
	printMsg(etc.welcome(ui.getCols(), VERSION))
	opsys.setTitleText(TITLE)
	
	# Initialize the database module
	dbNick, botResponses = database.initialize(LOCAL_IP)
	
	myNick = dbNick
	
	# Get nickname
	if myNick == None:
		prompt = "Please enter a nickname: "
		myNick = sleepPrompt(prompt)
		msgLog.append(prompt + myNick)
	else:
		returnString = "Welcome back, " + myNick
		printMsg(returnString)