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()
prompt = "Please enter a nickname: " myNick = sleepPrompt(prompt) msgLog.append(prompt + myNick) else: returnString = "Welcome back, " + myNick printMsg(returnString) msgLog.append(returnString) # Make sure nickname is long enough if len(myNick) < 3: errorMsg = "Nickname must be longer than 2 characters. Defaulting to IP." printMsg(errorMsg) msgLog.append(errorMsg) myNick = LOCAL_IP # Store nickname if myNick != dbNick: database.setNick(myNick) peers[LOCAL_IP] = myNick # Start listening to peers and managing heartbeats start_new_thread(processMessage, ()) start_new_thread(manageHeartbeat, ()) start_new_thread(handleUser, ()) # Ask for active peers sendStatus(traffic.GREET, ips=database.getGlobalList()) # must be in main thread (according to testing, not theory) opsys.runPopup() #handle popup notifications