def setupClarissa(install_path): useWebServices() os.remove(dir_path + "/settings.rif") if (os.path.isfile(dir_path + "/settings.rif")): out = open('settings.rif', 'a') del_settings = input( "This will delete your current settings. Do you wish to continue? (Y/N)" ) if "y" in del_settings.lower(): os.remove("rm -R Settings") os.mkdir("Settings") else: exit() else: if not os.path.exists(install_path + "/Settings"): os.mkdir(install_path + "/Settings") out = open('settings.rif', 'w') print("Setting up Clarissa. This should not take long.") setup = open(os.path.expanduser("~") + "/._clarissa.py", 'w') setup.write("import os\n") setup.write("os.environ['CLARISSA_PATH']=r\"" + install_path + "\"") setup.flush() setup.close() os.environ['CLARISSA_PATH'] = install_path w.setClarissaSettingWithPath(dir_path + "/settings.rif", "main", "install", install_path) w.setClarissaSettingWithPath(dir_path + "/settings.rif", "main", "cbot_dir", os.path.dirname(os.path.realpath(__file__))) w.setClarissaSetting("main", "auto_update", "false") w.setClarissaSetting("speech", "hey_clarissa_enabled", "false") w.setClarissaSetting("speech", "speak_out", "false") w.setClarissaSetting("main", "user.name", input("Your username: "******"clarissa", "name", "Clarissa") if (os.path.exists(dir_path + "/corpus") is False): os.mkdir("corpus") download( "https://softy.000webhostapp.com/apps/sites/clarissa/corpus/chameleons.pdf", "Chameleons", dir_path + "/corpus/chameleons.pdf") download( "https://softy.000webhostapp.com/apps/sites/clarissa/corpus/movie_characters_metadata.txt", "Movie Characters Meta Data", dir_path + "/corpus/movie_characters_metadata.txt") download( "https://softy.000webhostapp.com/apps/sites/clarissa/corpus/movie_conversations.txt", "Movie Conversations", dir_path + "/corpus/movie_conversations.txt") download( "https://softy.000webhostapp.com/apps/sites/clarissa/corpus/movie_lines.txt", "Movie Lines", dir_path + "/corpus/movie_lines.txt") download( "https://softy.000webhostapp.com/apps/sites/clarissa/corpus/movie_titles_metadata.txt", "Movie Titles", dir_path + "/corpus/movie_titles_metadata.txt") download( "https://softy.000webhostapp.com/apps/sites/clarissa/corpus/raw_script_urls.txt", "Raw Script", dir_path + "/corpus/raw_script_urls.txt") download( "https://softy.000webhostapp.com/apps/sites/clarissa/corpus/README.txt", "README", dir_path + "/corpus/README.txt")
def setupOfflineClarissa(install_path): w.setClarissaSettingWithPath(dir_path + "/user.rif", "user", "user", "Offline") w.setClarissaSettingWithPath(dir_path + "/user.rif", "pass", "pass", "Offline") if (os.path.isfile(dir_path + "/settings.rif")): out = open('settings.rif', 'a') del_settings = input( "This will delete your current settings. Do you wish to continue? (Y/N)" ) if "y" in del_settings.lower(): shutil.rmtree("Settings") os.mkdir("Settings") else: exit() else: if not os.path.exists(install_path + "/Settings"): os.mkdir(install_path + "/Settings") out = open('settings.rif', 'w') print("Setting up Clarissa. This should not take long.") setup = open(os.path.expanduser("~") + "/._clarissa.py", 'w') setup.write("import os\n") setup.write("os.environ['CLARISSA_PATH']=r\"" + install_path + "\"") setup.flush() setup.close() os.environ['CLARISSA_PATH'] = install_path w.setClarissaSettingWithPath(dir_path + "/settings.rif", "main", "install", install_path) w.setClarissaSetting("main", "auto_update", "false") w.setClarissaSetting("speech", "hey_clarissa_enabled", "false") w.setClarissaSetting("speech", "speak_out", "false") w.setClarissaSetting("main", "user.name", input("Your username: "******"Setup successful. When you are back online, re-run this setup.")
def getSpeech(): #Initialize speech recognizer as reader reader = speech_recognizer.Recognizer() #Open speech recognizer with speech_recognizer.Microphone() as mic: #Listen for those sweet, sweet vocals audio = reader.listen(mic) try: #Remind them they are awesome print( r.getClarissaSetting("main", "user.name") + ": " + reader.recognize_google(audio)) return reader.recognize_google(audio) except speech_recognizer.UnknownValueError: #F**k, we f****d up if (r.getClarissaSetting("speech", "speak_out") == "true"): tts.init("I'm sorry. I could not understand that.", 'en-US', False) print("Clarissa: I'm sorry. I could not understand that") except speech_recognizer.RequestError as error: #F*****g f**k cant keep f*****g up shit f**k! if ("recognition connection failed" in "{0}".format(error)): if (r.getClarissaSetting("speech", "speak_out") == "true"): tts.init( "I need an internet connection for speech recognition. I will disable speech recognition. You can later re-enable it by running python bot.py --enable-speech-recognition", 'en-US', False) print( "Clarissa: I need an internet connection for speech recognition. I will disable speech recognition. You can later re-enable it by running python bot.py --enable-speech-recognition" ) w.setClarissaSetting("speech", "hey_clarissa_enabled", "false") toBot(messageToBot=input( r.getClarissaSetting("main", "user.name") + ": ")) print("Clarissa: Could not process: {0}".format(error)) if (r.getClarissaSetting("speech", "speak_out") == "true"): tts.init("Could not process {0}".format(error), 'en-US', False) except (KeyboardInterrupt, SystemExit): #shutil.rmtree("Audio/", True) bot.getResponse("kill-bot")
return convs try: open(dir_path + "/settings.rif", "w") if (sys.argv[1] == "--reset"): os.remove("commands.list") exit() if (internet_on() is False): setupOfflineClarissa(dir_path) exit() setupClarissa(dir_path) if (sys.argv[1] == "--set-bot-name"): w.setClarissaSetting("clarissa", "name", sys.argv[2]) else: w.setClarissaSetting("clarissa", "name", "Clarissa") except IndexError: print("Run python setup.py") print("Or run python setup.py --reset to reset Clarissa to default") print("Or run python setup.py --rebuild-chat to rebuild the chat database") print( "Or run python setup.py --set-bot-name [BOT_NAME] to change Clarissa's name" ) if (internet_on() is False): setupOfflineClarissa(dir_path) exit() setupClarissa(dir_path) except requests.exceptions.ConnectionError: print("Offline setup!")
def __init__(self, path): #Set the update path w.setClarissaSetting("update", "update_dir", path) self.path = r.setClarissaSetting("update", "update_dir")
def set_name(bot_name): writer.setClarissaSetting("clarissa", "name", bot_name) #import bot as bot os.system("py -3 " + str("bot.py"))
def toBot(messageToBot): try: #Reload the bot and learner modules reload(bot) reload(learner) #If the message is none, go to getSpeech(), as that is #When we are needed if (messageToBot == None): messageToBot = getSpeech() #Not relevant. Ignore, otherwise whole application combusts #Into an eternal pit of fire if (os.path.isfile(".bot_engage")): print("You can only run one instance of Clarissa.") else: #Not relevant, yet still works swearNum = 1 #Remind the computer where CLARISSA_PATH is os.environ['CLARISSA_PATH'] = r.getClarissaSettingWithPath( dir_path + "/settings.rif", "main", "install") #Just for shits and giggles, remind the computer who the user name is! os.environ['USER_NAME'] = r.getClarissaSetting("main", "user.name") if (messageToBot == "--add-command"): #Write command to server writeCommand(command=input("Command: "), response=input("Responses: ")) reload(bot) elif (messageToBot == "kill-bot"): #Die, die, die! w.setClarissaSetting("clarissa", "name", "Clarissa") exit() elif (messageToBot == "--clear-commands"): #Leave for multi-user computers. Clears the command list that is written. os.remove("chat.log") print("Cleared commands") exit() elif (messageToBot == "learn"): #Ancient code, but will be used sometime soon. learner.learn(db_support=False) elif (messageToBot == "--get-commands"): #Print out commands commandsList = open("commands.list", "r") print(commandsList.read()) elif (messageToBot == "--get-logs"): #Print out what has been said logs = open('chat.log', 'r') print(logs.read()) elif ("Call me " in messageToBot): w.setClarissaSetting("main", "user.name", messageToBot.replace("Call me ", "")) elif ("call me " in messageToBot): w.setClarissaSetting("main", "user.name", messageToBot.replace("call me ", "")) elif ("Run " in messageToBot): #Runs an installed application #Thank the lord I placed the code in another module apps = Apps() if (apps.does_app_exist(messageToBot.replace("Run ", "")) == True): apps.run(messageToBot.replace("Run ", "")) return None else: print(messageToBot.replace("Run ", "") + " was not found") if (clarissa_voice_recognition_enabled == True): toBot(messageToBot=getSpeech()) else: toBot(messageToBot=input( r.getClarissaSetting("main", "user.name") + ": ")) elif ("run " in messageToBot): #Same deal, but lower case apps = Apps() if (apps.does_app_exist(messageToBot.replace("run ", "")) == True): apps.run(messageToBot.replace("run ", "")) return None else: print(messageToBot.replace("run ", "") + " was not found") if (clarissa_voice_recognition_enabled == True): toBot(messageToBot=getSpeech()) else: toBot(messageToBot=input( r.getClarissaSetting("main", "user.name") + ": ")) elif ("Make app" in messageToBot): #Create an app apps = Apps() apps.make_app(input("App name:")) elif ("make app" in messageToBot): #Same deal but in lower case apps = Apps() apps.make_app(input("App name:")) #Log what was said for later review by user log.log("chat.log", messageToBot) #Initialize cpu hopper cpu_def = CPU() #Will only work on Windows, temporarily cpu_def.run_code(code=bot.getResponse(messageToBot)) #Check if speech recognition is enabled #If it is, messageToBot is None if (clarissa_voice_recognition_enabled == True): toBot(messageToBot=getSpeech()) else: toBot(messageToBot=input( r.getClarissaSetting("main", "user.name") + ": ")) except TypeError: #If there is an error, check if speech recognition is enabled if (clarissa_voice_recognition_enabled is True): #Use voice toBot(getSpeech()) else: #Use normal toBot(messageToBot=input( r.getClarissaSetting("main", "user.name") + ": ")) except (KeyboardInterrupt, SystemExit): #End on exit, 100% will fail first 5 seconds. Not my problem, user. bot.getResponse("kill-bot")
#os.remove("commands.bot") #os.remove("responses.bot") os.remove("bot_response.py") writeCommand("Hello", "Hi") reload(bot) print("Cleared commands") elif ("learn" in sys.argv): learner.learn(db_support=False) elif ("--get-commands" in sys.argv): commandsList = open("commands.list", "r") print(commandsList.read()) elif ("--get-logs" in sys.argv): logs = open('chat.log', 'r') print(logs.read()) elif (sys.argv[1] == "set.name"): w.setClarissaSetting("main", "user.name", sys.argv[2]) elif (sys.argv[1] == "--get-setting"): print(getClarissaSetting("main", sys.argv[2])) elif ("--enable-auto-update" in sys.argv): w.setClarissaSettingWithPath(dir_path + "settings.rif", "update", "Clarissa.AUTO_UPDATE", "true") elif ("--update-bot" in sys.argv): updateSystem() elif (sys.argv[1] == "--set-setting"): w.setClarissaSetting(sys.argv[2], sys.argv[3], sys.argv[4]) elif ("--enable-speech-recognition" in sys.argv): w.setClarissaSetting("speech", "hey_clarissa_enabled", "true") elif ("--disable-speech-recognition" in sys.argv): w.setClarissaSetting("speech", "hey_clarissa_enabled", "false") elif ("--speak-out" in sys.argv): w.setClarissaSetting("speech", "speak_out", "true")