# Chatbot-test.py # This short program tests out some of the Chatbot, making sure it won't crash. Needs Chatbot v0.2.0 or later. import Chatbot # PyCharm seems to think this is an error, but it seems fine. import random import os import sys __author__ = 'Peter Maar' __version__ = '1.0.0' Chatbot.debugTestMode = True humanSayList = ["Hello!", "How are you?", "What is your name?", "What time is it?", "How's the weather?", "DFTBA", "Good Morning!", "Bye!", "I gtg", "Just FYI idk who u are."] outstuff = '' for i in range(100): humanSays = humanSayList[random.randint(0, len(humanSayList)-1)] print("Human says:", humanSays) stuff = outstuff + "\n\n\n:::\n\n\n" + humanSays outstuff = Chatbot.processInput(stuff) print("Bot says:", outstuff) humanSayList.append(outstuff) print("\n\n\n\n\n\n\n\n\n\n") print(Chatbot.thingsToSayOld) print("\n\n\n\n\n") print(Chatbot.smartSayDict) os.remove(sys.path[0] + "/DEBUG-smartSayDict.pickle") os.remove(sys.path[0] + "/DEBUG-thingsToSayOld.pickle")
return (recievedMessage, addr[0]) try: srvrPort = int(input("Enter the port number to host the server on:\n")) except ValueError: print("Error. Bad port number. Invalid port number. Port number must be an integer.") exit() print("Your Local IP Address is:") ipSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) ipSock.connect(("8.8.8.8",80)) #TODO This is the only way to get the IP accurately regardless of network setups, is to connect to something, but this will fail if there is no internet. Maybe add a try except? print(ipSock.getsockname()[0]) ipSock.close() print("Starting server...") Chatbot.processInput('') # Chatbot knows not to store blank strings (safeToStore stops them), and this will prompt to create the pickle files if needed num = random.randint(0, 1000000) print("Server started. Waiting for connections. Press Ctrl + C to exit.") while True: r = receive(srvrPort) msg = r[0] ip = r[1] if msg[msg.find("\n\n\n:::\n\n\n")+9:] == "server: print code": # If the user says 'server: print code' print(num) # Print the number on the server screen send(ip, srvrPort, "Code is now on server console.") elif msg[msg.find("\n\n\n:::\n\n\n")+9:] == "server: exit " + str(num): # If the user says 'server: exit' and the correct code, exit send(ip, srvrPort, "Correct code. Server exiting.") exit()