def handle_command(command, channel): """ Executes bot command if the command is known """ # Default response is help text for the user default_response = "Not sure what you mean. Try *{}*.".format( EXAMPLE_COMMAND) # Finds and executes the given command, filling in response response = None # This is where you start to implement more commands! if command.startswith(EXAMPLE_COMMAND): response = "Sure...write some more code then I can do that!" if 'weather' in command: response = weather.current_weather() #print(response) if 'joke' in command: response = jokes.get_joke() if 'quote' in command or 'motivation' in command: response = quotes.get_quote() #print(response) # Sends the response back to the channel slack_client.api_call("chat.postMessage", channel=channel, text=response or default_response)
def display_routine(self): routine = "" config = self.config['ticker'] try: routine = "Price" for crypto in config['crypto']: coin = self.crypto.get_coin(crypto) self.viewer.display_message(str.upper(coin["name"]), MessageType.FALLING, coin['logo']) for j in range(0, 3): message = self.crypto.get_details(crypto, config['vs_currency']) self.viewer.display_message(message, MessageType.BOUNCING, coin['logo'], delay=30) if (config['tell_jokes']): routine = "Joke" message = get_joke() self.viewer.display_message("JOKE TIME", MessageType.FALLING, delay=25) self.viewer.display_message(message, MessageType.SCROLLING) except ConnectionError: self.viewer.display_message(f'Error connecting to {routine} API', MessageType.SCROLLING) except Exception as e: print(e) self.viewer.display_message("Encountered an Unknown Error", MessageType.SCROLLING)
def test_get_single_joke(self): responses.add(responses.GET, build_url(), json=mock_json('single'), status=200) self.assertEqual(get_joke(), 'IMMA JOKE')
def main_chat(user_input): greetings = ("hello", "hi", "what's up", "good morning", "good evening", "good afternoon", "how are you") answer = user_input.split() for word in answer: if word in greetings: return greet_user(word) elif word == "joke": return get_joke() else: return get_weather(user_input)
if float(mood["happiness"]) > 0.3: emotions.append("happy") else: emotions.append("not happy") print(emotions[-10:-1]) if "happy" not in emotions[-4:-1]: ## TELL A JOKE print("Looks like you need a joke. Here's one:") #content = requests.get("https://icanhazdadjoke.com/", headers={"Accept": "application/json"}) #parsed = json.loads(content.text) #joke = parsed["joke"] joke = jokes.get_joke() print(joke) text_to_speech.speak( "You look unhappy, here's a joke for you. " + joke, 8000) ## CROP PICTURE TO YOUR FACE ONLY height = frame.shape[0] print(height) width = frame.shape[1] print(width) x1 = json_response[0]["faceRectangle"]["left"] - 70 x2 = x1 + 70 + json_response[0]["faceRectangle"]["width"] + 70 y1 = json_response[0]["faceRectangle"]["top"] - 150 y2 = y1 + 150 + json_response[0]["faceRectangle"]["height"] + 70 x1 = x1 if x1 > 0 else 0
just_told_a_joke = False # if you've been sad for the past 4 time stamps: if "happy" not in emotions[-4:-1]: #print(method_to_make_you_happier_count) if method_to_make_you_happier_count == 0: ## TELL A JOKE #print("Looks like you need a joke. Here's one:") #content = requests.get("https://icanhazdadjoke.com/", headers={"Accept": "application/json"}) #parsed = json.loads(content.text) #joke = parsed["joke"] joke, joke_number = jokes.get_joke() latest_joke_number = joke_number #print(joke, joke_number) #print(joke) text_to_speech.speak( "You look unhappy, here's a joke for you. " + joke, 8000) print("We have told you a joke!") last_method_to_increase_happiness = "joke" just_told_a_joke = True if method_to_make_you_happier_count == 1: ## CROP PICTURE TO YOUR FACE ONLY AND TWEET IT
def joke(bot, update): bot.send_message(chat_id=update.message.chat_id, text=get_joke())
def send_message_insert(self, message): user_input = self.entry_field.get() pr1 = "You : " + user_input + "\n" self.text_box.configure(state=NORMAL) self.text_box.insert(END, pr1) self.text_box.configure(state=DISABLED) self.text_box.see(END) #t1 = threading.Thread(target=self.playResponce, args=(user_input,)) #t1.start() #time.sleep(1) if 'voice mode' in user_input or 'voice command' in user_input: main() elif 'wikipedia' in user_input: if checknet() == True: speak("Searching...") query = user_input.replace('wikipedia', '') result = wikipedia.summary(query, sentences=3) speak('According to Wikipedia') pr = "Buddy : " + result + "\n" self.text_box.configure(state=NORMAL) self.text_box.insert(END, pr) self.text_box.configure(state=DISABLED) self.text_box.see(END) self.last_sent_label( str( time.strftime("Last message sent: " + '%B %d, %Y' + ' at ' + '%I:%M %p'))) self.entry_field.delete(0, END) time.sleep(0) t2 = threading.Thread(target=self.playResponce, args=(result, )) t2.start() else: result = "You are offline please connect internet connection" pr = "Buddy : " + result + "\n" self.text_box.configure(state=NORMAL) self.text_box.insert(END, pr) self.text_box.configure(state=DISABLED) self.text_box.see(END) self.last_sent_label( str( time.strftime("Last message sent: " + '%B %d, %Y' + ' at ' + '%I:%M %p'))) self.entry_field.delete(0, END) time.sleep(0) t2 = threading.Thread(target=self.playResponce, args=(result, )) t2.start() time.sleep(0) elif 'cpu' in user_input: usage = str(psutil.cpu_percent()) battery = psutil.sensors_battery() battery = str(battery.percent) pr = "Buddy : CPU usage is at " + usage + " and Battery is " + battery + "%\n" self.text_box.configure(state=NORMAL) self.text_box.insert(END, pr) self.text_box.configure(state=DISABLED) self.text_box.see(END) self.last_sent_label( str( time.strftime("Last message sent: " + '%B %d, %Y' + ' at ' + '%I:%M %p'))) self.entry_field.delete(0, END) result = "CPU usage is at " + usage + "and Battery is " + battery + " %" t2 = threading.Thread(target=self.playResponce, args=(result, )) t2.start() elif 'joke' in user_input: result = jokes.get_joke() pr = "Buddy : " + result + "\n" self.text_box.configure(state=NORMAL) self.text_box.insert(END, pr) self.text_box.configure(state=DISABLED) self.text_box.see(END) self.last_sent_label( str( time.strftime("Last message sent: " + '%B %d, %Y' + ' at ' + '%I:%M %p'))) self.entry_field.delete(0, END) time.sleep(0) t2 = threading.Thread(target=self.playResponce, args=(result, )) t2.start() time.sleep(0) elif 'time' in user_input: result = datetime.datetime.now().strftime("%I:%M:%S") speak("The current time is") pr = "Buddy : " + result + "\n" self.text_box.configure(state=NORMAL) self.text_box.insert(END, pr) self.text_box.configure(state=DISABLED) self.text_box.see(END) self.last_sent_label( str( time.strftime("Last message sent: " + '%B %d, %Y' + ' at ' + '%I:%M %p'))) self.entry_field.delete(0, END) time.sleep(0) t2 = threading.Thread(target=self.playResponce, args=(result, )) t2.start() elif 'make a note' in user_input or 'write a note' in user_input: try: speak("What should i write?") checknet() if checknet() == False: speak( "You are Offline, Please Connect Internet Connection For Voice Inraction..." ) else: mixer.init() mixer.music.load( "C:\\Users\\Rajan Kumar Sah\\Desktop\\Project_File\\music\\tone.mp3" ) mixer.music.play() r = sr.Recognizer() with sr.Microphone() as source: r.pause_threshold = 1 audio = r.listen(source) print("Recognizing...") query = r.recognize_google(audio, language="en-in") file = open('notes.txt', 'w') strTime = datetime.datetime.now().strftime("%H:%M:%S") file.write(strTime) file.write(":- ") file.write(query) file.write("\n") speak("Succesfully Done..") pr = "Buddy : Note = " + query + "\n" self.text_box.configure(state=NORMAL) self.text_box.insert(END, pr) self.text_box.configure(state=DISABLED) self.text_box.see(END) self.last_sent_label( str( time.strftime("Last message sent: " + '%B %d, %Y' + ' at ' + '%I:%M %p'))) except Exception as e: speak("Something went wrong, Please Try Again...") elif 'show notes' in user_input or 'show note' in user_input: speak("Showing Notes...") file = open('notes.txt', 'r') self.text_box.configure(state=NORMAL) self.text_box.insert(END, "Notes\n-------------------------\n") self.text_box.insert(END, file.read()) self.text_box.configure(state=DISABLED) self.text_box.see(END) self.last_sent_label( str( time.strftime("Last message sent: " + '%B %d, %Y' + ' at ' + '%I:%M %p'))) elif 'email messages' in user_input: if True: result = "How many messages do you want to see ?" pr = "Buddy : " + result + "\n" self.text_box.configure(state=NORMAL) self.text_box.insert(END, pr) self.text_box.configure(state=DISABLED) self.text_box.see(END) self.last_sent_label( str( time.strftime("Last message sent: " + '%B %d, %Y' + ' at ' + '%I:%M %p'))) self.entry_field.delete(0, END) time.sleep(0) t2 = threading.Thread(target=self.playResponce, args=(result, )) t2.start() time.sleep(0) #view_message() pass elif 'send email' in user_input: pass elif 'on youtube' in user_input: user_input = user_input.replace('on youtube', '') if 'search' in user_input: user_input = user_input.replace('search', '') speak("Searching...") wb.open('https://www.youtube.com/results?search_query=' + user_input) if True: result = "Search completed" pr = "Buddy : " + result + "\n" self.text_box.configure(state=NORMAL) self.text_box.insert(END, pr) self.text_box.configure(state=DISABLED) self.text_box.see(END) self.last_sent_label( str( time.strftime("Last message sent: " + '%B %d, %Y' + ' at ' + '%I:%M %p'))) self.entry_field.delete(0, END) time.sleep(1) t2 = threading.Thread(target=self.playResponce, args=(result, )) t2.start() time.sleep(3) elif 'search' in user_input: user_input = user_input.replace('search', '') speak("Searching...") wb.open('https://www.google.com/search?q=' + user_input) if True: result = "Search Completed" pr = "Buddy : " + result + "\n" self.text_box.configure(state=NORMAL) self.text_box.insert(END, pr) self.text_box.configure(state=DISABLED) self.text_box.see(END) self.last_sent_label( str( time.strftime("Last message sent: " + '%B %d, %Y' + ' at ' + '%I:%M %p'))) self.entry_field.delete(0, END) t2 = threading.Thread(target=self.playResponce, args=(result, )) t2.start() time.sleep(3) elif 'notepad' in user_input: speak("Opening Notepad...") notepad = 'C:\\Windows\\System32\\notepad.exe' os.startfile(notepad) elif 'vlc' in user_input: speak("Opening VLC Player...") vlc = 'C:\\Program Files\\VideoLAN\\VLC\\vlc.exe' os.startfile(vlc) elif 'media player' in user_input: speak("Opening Media Player...") wm = 'C:\\Program Files\\Windows Media Player\\wmplayer.exe' os.startfile(wm) elif 'sublime' in user_input: speak("Opening Sublime Editor...") sublime = 'C:\\Program Files\\Sublime Text 3\\subl.exe' os.startfile(sublime) elif 'mozila' in user_input: speak("Opening Mozila Firefox") mozila = 'C:\\Program Files\\Mozilla Firefox\\firefox.exe' os.startfile(mozila) elif 'explorer' in user_input: speak("Opening Internet Explorer") explorer = 'C:\\Program Files\\Internet Explorer\\iexplore.exe' os.startfile(explorer) elif 'adobe reader' in user_input: speak("Opening Adobe Reader") adobe = 'C:\\Program Files (x86)\\Adobe\\Acrobat Reader DC\\Reader\\AcroRd32.exe' os.startfile(adobe) elif 'code block' in user_input: speak("Opening Code Block Editor") codeblock = 'C:\\Program Files (x86)\\CodeBlocks\\codeblocks.exe' os.startfile(codeblock) elif 'edit plus' in user_input: speak("Opening Edit Plus Editor") editplus = 'C:\\Program Files (x86)\\EditPlus\\editplus.exe' os.startfile(editplus) elif 'chrome' in user_input: speak("Opening Chrome Browser") chrome = 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe' os.startfile(chrome) elif 'browser' in user_input: speak("Opening Chrome Browser") chrome = 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe' os.startfile(chrome) elif 'typing' in user_input: speak("Opening Typing Master") typing = 'C:\\Program Files (x86)\\TypingMaster\\TypingMaster.exe' os.startfile(typing) elif 'word' in user_input: speak("Opening MS Word") word = 'C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\WINWORD.EXE' os.startfile(word) elif 'excel' in user_input: speak("Opening MS Excel") excel = 'C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\EXCEL.EXE' os.startfile(excel) elif 'power point' in user_input: speak("Opening MS Power Point") Powerpoint = 'C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\POWERPNT.EXE' os.startfile(Powerpoint) elif 'team viewer' in user_input: speak("Opening Team Viewer") teamviewer = 'C:\\Program Files (x86)\\TeamViewer\\TeamViewer.EXE' os.startfile(teamviewer) elif 'edge' in user_input: speak("Opening Edge Browser") edge = 'C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe' os.startfile(edge) elif 'bye' in user_input: result = "Bye Bye" pr = "Buddy : " + result + "\n" if 'bye' in user_input: self.text_box.configure(state=NORMAL) self.text_box.insert(END, pr) self.text_box.configure(state=DISABLED) self.text_box.see(END) self.last_sent_label( str( time.strftime("Last message sent: " + '%B %d, %Y' + ' at ' + '%I:%M %p'))) self.entry_field.delete(0, END) time.sleep(0) t2 = threading.Thread(target=self.playResponce, args=(result, )) t2.start() time.sleep(3) exit() else: ob = chat(user_input) pr = "Buddy : " + ob + "\n" self.text_box.configure(state=NORMAL) self.text_box.insert(END, pr) self.text_box.configure(state=DISABLED) self.text_box.see(END) self.last_sent_label( str( time.strftime("Last message sent: " + '%B %d, %Y' + ' at ' + '%I:%M %p'))) self.entry_field.delete(0, END) time.sleep(0) t2 = threading.Thread(target=self.playResponce, args=(ob, )) t2.start()
def test_get_twopart_joke(self): responses.add(responses.GET, build_url(), json=mock_json('twopart'), status=200) self.assertEqual(get_joke(), 'IMMA JOKE.....IMMA DELIVERY')
def main(): os.system('cls') f = open("C:\\Users\\Rajan Kumar Sah\\Desktop\\Project_File\\intro\\voice_intro.txt","r") ascii = "".join(f.readlines()) print(colorText(ascii)) speak("Voice Mode Activated...") checknet() while True: query = takecommand().lower() if 'wikipedia' in query: try: speak("Searching...") query=query.replace('wikipedia','') result=wikipedia.summary(query,sentences=3) speak('According to Wikipedia') pr="Buddy : " + result + "\n" speak(result) except: speak("Not Found Correct Result..") elif 'time' in query: result = datetime.datetime.now().strftime("%I:%M:%S") speak("The current time is") pr="Buddy : " + result + "\n" speak(result) elif 'email messages' in query: #view_message() pass elif 'send email' in query: pass elif 'on youtube' in query: query =query.replace('on youtube','') if 'search' in query: query = query.replace('search','') speak("Searching...") wb.open('https://www.youtube.com/results?search_query='+query) speak("Search completed") elif 'search' in query: query = query.replace('search','') speak("Searching...") wb.open('https://www.google.com/search?q='+query) speak("Search completed") elif 'cpu' in query: usage = str(psutil.cpu_percent()) battery = psutil.sensors_battery() battery = str(battery.percent) result = "CPU usage is at " + usage + "and Battery is "+ battery +" %" speak(result) elif 'joke' in query: result = jokes.get_joke() speak(result) elif 'write a note' in query or 'make a note' in query: try: speak("What should i write?") checknet() if checknet()== False: speak("You are Offline, Please Connect Internet Connection For Voice Inraction...") else: mixer.init() mixer.music.load('tone.mp3') mixer.music.play() r=sr.Recognizer() with sr.Microphone() as source: r.pause_threshold = 1 audio = r.listen(source) print("Recognizing...") query1 = r.recognize_google(audio,language="en-in") file = open('notes.txt','a') strTime = datetime.datetime.now().strftime("%H:%M:%S") file.write(strTime) file.write(":- ") file.write(query1) file.write("\n") speak("Succesfully Done..") except Exception as e: speak("Something went wrong, Please Try Again...") elif 'show notes' in query or 'show note' in query: speak("Showing Notes...") file = open('notes.txt','r') speak(file.read()) elif 'notepad' in query: speak("Opening Notepad...") notepad = 'C:\\Windows\\System32\\notepad.exe' os.startfile(notepad) elif 'vlc' in query: speak("Opening VLC Player...") vlc = 'C:\\Program Files\\VideoLAN\\VLC\\vlc.exe' os.startfile(vlc) elif 'media player' in query: speak("Opening Media Player...") wm = 'C:\\Program Files\\Windows Media Player\\wmplayer.exe' os.startfile(wm) elif 'sublime' in query: speak("Opening Sublime Editor...") sublime = 'C:\\Program Files\\Sublime Text 3\\subl.exe' os.startfile(sublime) elif 'mozila' in query: speak("Opening Mozila Firefox") mozila = 'C:\\Program Files\\Mozilla Firefox\\firefox.exe' os.startfile(mozila) elif 'explorer' in query: speak("Opening Internet Explorer") explorer = 'C:\\Program Files\\Internet Explorer\\iexplore.exe' os.startfile(explorer) elif 'adobe reader' in query: speak("Opening Adobe Reader") adobe = 'C:\\Program Files (x86)\\Adobe\\Acrobat Reader DC\\Reader\\AcroRd32.exe' os.startfile(adobe) elif 'code block' in query: speak("Opening Code Block Editor") codeblock = 'C:\\Program Files (x86)\\CodeBlocks\\codeblocks.exe' os.startfile(codeblock) elif 'edit plus' in query: speak("Opening Edit Plus Editor") editplus = 'C:\\Program Files (x86)\\EditPlus\\editplus.exe' os.startfile(editplus) elif 'chrome' in query: speak("Opening Chrome Browser") chrome = 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe' os.startfile(chrome) elif 'browser' in query: speak("Opening Chrome Browser") chrome = 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe' os.startfile(chrome) elif 'typing' in query: speak("Opening Typing Master") typing = 'C:\\Program Files (x86)\\TypingMaster\\TypingMaster.exe' os.startfile(typing) elif 'word' in query: speak("Opening MS Word") word = 'C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\WINWORD.EXE' os.startfile(word) elif 'excel' in query: speak("Opening MS Excel") excel = 'C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\EXCEL.EXE' os.startfile(excel) elif 'power point' in query: speak("Opening MS Power Point") Powerpoint = 'C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\POWERPNT.EXE' os.startfile(Powerpoint) elif 'team viewer' in query: speak("Opening Team Viewer") teamviewer = 'C:\\Program Files (x86)\\TeamViewer\\TeamViewer.EXE' os.startfile(teamviewer) elif 'edge' in query: speak("Opening Edge Browser") edge = 'C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe' os.startfile(edge) elif 'bye' in query: result = "Bye Bye" speak(result) exit() elif "stop" in query or "exit form voice" in query or "deactivate" in query: speak("Voice Mode deactivated..") break else: ob=chat(query) pr="Buddy : " + ob + "\n" speak(ob)