class Processor(object): name = "Jarvis-Processor" desc = "Console to process voice commands" version = "0.3" def __init__(self): self.Jarvis = Jarvis() def help(self, version): print print color("[ Jarvis - Personal Assistence - v{} ]".format(version), "blue") print print print color("[*] exit |or| quit : Terminate the program.", "blue") print print print color( "[*] sleep |or| stop |or| wait: Sleep until you say 'Jarvis'.", "blue") print print print color( "[*] newspaper |or| news: Read the top trending news from reddit.", "blue") print print print color( "[*] say |or| speak [message]: Ask Jarvis to say something.", "blue") print print color(" examples(say):", "green") print print color(" say I like donuts", "green") print color(" speak my name is Jarvis", "green") print print print color( "[*] run [script]: Run .sh script that you place on the scripts folder with chmod +x", "blue") print print color(" example(say):", "green") print print color( " run firewall | Place a firewall.sh on the scripts folder and give execution privilege first.", "green") print print print color( "[*] browser: Ask Jarvis to start your default browser.", "blue") print print color(" example(say):", "green") print print color(" browser", "green") print print print color("[*] terminal: Ask Jarvis to open a gnome-terminal.", "blue") print print color(" example(say):", "green") print print color(" terminal", "green") print print print color( "[*] search [query] Ask Jarvis to search query via google.", "blue") print print color(" example(say):", "green") print print color(" search python programming.", "green") print print print color( "[*] input [keystroke]: Send a command to the Arduino Leonardo without entering editor mode.", "blue") print print color(" * ARDUINO LEONARDO REQUIRED *", "red") print print color("voice commands: (Same as EDITOR MODE )", "yellow") print print print color("[*] editor: Start the editor mode.", "blue") print print color(" * ARDUINO LEONARDO REQUIRED *", "red") print print color(" [EDITOR MODE]", "red") print print color("voice commands: (anything else will be typed)", "yellow") print print color(" forward = tab", "green") print color(" back = (shift+tab)", "green") print color(" up = up arrow", "green") print color(" down = down arrow", "green") print color(" right = right arrow", "green") print color(" left = left arrow", "green") print color(" super = super/windows", "green") print color(" slash = slash(/)", "green") print color(" backspace = backspace(erase character)", "green") print color(" erase = press backspace 10 times", "green") print color(" space = space(spacebar)", "green") print color(" enter = enter(return)", "green") print color(" close = close(alt+f4)", "green") print color(" escape = escape(esc)", "green") print color(" exit = leaves editor mode", "green") print def start(self): try: self.Jarvis.ser.open() except Exception as e: print "[!] Arduino Leonardo not found, features that use keyboard will not work." try: self.Jarvis.Say(self.Jarvis.random('greetings')) while 1: try: self.command = self.Jarvis.Listen() self.message = self.command.split() self.input_list = [str(a) for a in self.message] if self.input_list[0] == "exit" or self.input_list[ 0] == "quit": self.Jarvis.Say(self.Jarvis.random('salutes')) exit() elif self.input_list[0] == "sleep" or self.input_list[ 0] == "stop" or self.input_list[0] == "wait": self.Jarvis.Say("Call me if you need me sir.") while 1: self.wait = self.Jarvis.Listen() if self.wait == "Jarvis": self.Jarvis.Say( self.Jarvis.random('affirmative')) break elif self.input_list[0] == "newspaper" or self.input_list[ 0] == "news": self.Jarvis.Say("Here are the news sir.") self.titles = self.Jarvis.GetNews() self.Jarvis.SpeakNews(self.titles) elif self.input_list[0] == "browser": try: webbrowser.open("https://www.google.com") self.Jarvis.Say(self.Jarvis.random('affirmative')) except Exception as e: print "[!] Exception caught: {}".format(e) pass elif self.input_list[0] == "terminal": try: os.system("gnome-terminal") self.Jarvis.Say(self.Jarvis.random('affirmative')) except Exception as e: print "[!] Exception caught: {}".format(e) pass elif self.input_list[0] == "search": try: search = self.input_list[1:] real = "".join(search) url = "https://www.google.com/search?q={}".format( real) webbrowser.open(url) self.Jarvis.Say(self.Jarvis.random('affirmative')) except Exception as e: print "[!] Exception caught: {}".format(e) pass elif self.input_list[0] == "say" or self.input_list[ 0] == "speak": self.Jarvis.Say(self.input_list[1:]) elif self.input_list[0] == "run": self.Jarvis.Say(self.Jarvis.random('affirmative')) os.system("./scripts/{}.sh".format(self.input_list[1])) elif self.input_list[0] == "input": try: self.Jarvis.SerialWrite(self.input_list[1]) self.Jarvis.Say(self.Jarvis.random('affirmative')) except: self.Jarvis.Say( "Feature not working master, plug your Arduino Leonardo then restart the program." ) pass elif self.input_list[0] == "editor": self.Jarvis.Say("Starting edition mode sir.") while 1: self.editmode = self.Jarvis.Listen() self.mesg = self.editmode #self.msg = "".join(self.mesg) if self.mesg is not None: try: self.Jarvis.SerialWrite(self.mesg) self.Jarvis.Say( self.Jarvis.random('affirmative')) except: self.Jarvis.Say( "Feature not working, plug you Arduino Leonardo then restart the program." ) break else: pass if self.editmode == "exit": self.Jarvis.Say("Stoping edition mode sir.") break else: print '[!] Input a valid option, enter "help" to see valid commands.' self.Jarvis.Say("i heard, {}".format(self.command)) self.Jarvis.Say(self.Jarvis.random('dntunderstand')) except IndexError: pass except AttributeError: pass except KeyboardInterrupt: print "\n[*] User requested shutdown" self.Jarvis.Say(self.Jarvis.random('salutes')) exit() except Exception as e: print "[!] Exception caught: {}".format(e) def backgroundstart(self, path): try: with open("{}/log/jarvis.log".format(path), "a+") as stdout: self.p = subprocess.Popen( ["python {}/core/processor.py".format(path)], shell=True, stdout=stdout, stderr=stdout) return except Exception as e: print "[-] Problem starting Jarvis in background: {}".format(e)
class Processor(object): def __init__(self): self.random = Randomstorm() self.Jarvis = Jarvis() self.RedditNews = RedditNews() def start(self): try: self.Jarvis.ser.open() except Exception as e: print "[!] Arduino Leonardo not found, features that use keyboard will not work." try: self.Jarvis.Say(self.random.random('greetings')) while 1: try: self.command = self.Jarvis.Listen() self.message = self.command.split() self.input_list = [str(a) for a in self.message] self.Jarvis.Say("i heard, {}".format(self.command)) if self.input_list[0] == "exit": self.Jarvis.Say(self.random.random('salutes')) exit() elif self.input_list[0] == "sleep": while 1: self.wait = self.Jarvis.Listen() if self.wait == "Jarvis": self.Jarvis.Say( self.random.random('affirmative')) break elif self.input_list[0] == "newspaper": self.Jarvis.Say("Here are the news sir.") self.titles = self.RedditNews.get_headlines() self.RedditNews.speak_headlines(self.titles) elif self.input_list[0] == "start": self.Jarvis.SerialWrite(self.input_list[1]) self.Jarvis.Say(self.random.random('affirmative')) elif self.input_list[0] == "say": self.Jarvis.Say(self.input_list[1:]) elif self.input_list[0] == "run": self.Jarvis.Say(self.random.random('affirmative')) os.system("./scripts/{}.sh".format(self.input_list[1])) elif self.input_list[0] == "editor": self.Jarvis.Say("Starting edition mode sir.") while 1: self.editmode = self.Jarvis.Listen() self.mesg = self.editmode #self.msg = "".join(self.mesg) if self.mesg is not None: try: self.Jarvis.SerialWrite(self.mesg) self.Jarvis.Say( self.random.random('affirmative')) except: print "[!] Feature not working, plug you Arduino Leonardo then try again." break else: pass if self.editmode == "exit": self.Jarvis.Say("Stoping edition mode sir.") break else: print '[!] Input a valid option, enter "help" to see valid commands.' self.Jarvis.Say(self.random.random('dntunderstand')) except IndexError: pass except AttributeError: pass except KeyboardInterrupt: print "\n[*] User requested shutdown" self.Jarvis.Say(self.random.random('salutes')) exit() except Exception as e: print "[!] Exception caught: {}".format(e)