Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Python-Chatbot/chat2.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
99 lines (97 sloc)
4.36 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from MyDictionary import * | |
def social(chat): | |
import random | |
try: | |
user=input("Can you share your life with me? ") | |
except: | |
print("Invalid input!") | |
else: | |
for i in user.split(): | |
if i.lower() in MyDictionary["REFUSE"] or i.lower() in MyDictionary["Emotion_negative"]: | |
try: | |
user=input("I'm so sorry affecting your bad mood. So do you want to leave, or stay with my other services?(leave/service) ") | |
except: | |
print("Invalid input!") | |
else: | |
for j in user.split(): | |
if (str(j.lower())).strip() in ["leave"]: | |
exit() | |
elif (str(j.lower())).strip() in ["service"]: | |
from main2 import main2 | |
main2() | |
else: | |
print("I don't know what the hell are yo saying dude!!!") | |
try: | |
chat=input("Say again please: ") | |
except: | |
print("Invalid input!") | |
else: | |
social(chat) | |
else: | |
for j in user.split(): | |
if str(j.lower()) in Emotion_positive: | |
em=True | |
break | |
else: | |
em=False | |
continue | |
print(em) | |
res="I'm quite " | |
from parrot import find_longest_word | |
if em==True: | |
print(res,"glad to hear that you are",find_longest_word(user.split()),".") | |
else: | |
try: | |
user=input("Sorry what do you mean by ",find_longest_word(user.split()),"?") | |
except: | |
print("Invalid input!") | |
finally: | |
print(res,"disappointed to hear that you said",find_longest_word(user.split()),".") | |
'''Greet each other''' | |
def greet(): | |
import random | |
while True: | |
res="" | |
found=False | |
try: | |
user=input("Hello, what's up bro? ") | |
for i in user.split(): | |
if i.lower() in GREETING_KEYWORDS: | |
print(GREETING_RESPONSES[random.randint(1,len(GREETING_RESPONSES))-1] ) # random generate a response based on user input | |
found=True | |
else: | |
if i.index(user.split())<len(user.split())-1: | |
continue | |
else: | |
found=False # return error | |
while found==False: | |
for j in user.split(): | |
if j.lower() in (GREETING_KEYWORDS.lower()).strip(): # check if greeting words are in the user input | |
res=GREETING_RESPONSES[random.randint(0,len(GREETING_RESPONSES-1))] # returns a greeting statement if yes | |
found==True | |
else: | |
from Checkings import isRepeat,CountRepeat | |
if isRepeat(user)==True: | |
for k in range(0,len(CountRepeat(user))): | |
print("Word '",CountRepeat(user)[k][0],"' has been repeated:",CountRepeat(user)[k][1]," times.") | |
print("Response '",str(i),"' in '",str(user),"' not found sorry!") | |
else: | |
print("",end="") | |
if found==True: | |
break | |
else: | |
print("Error not found for: "+str(user)) | |
user=input("Hello, what's up bro? ") | |
except: # error exception | |
print("Invalid input!") | |
else: | |
user=input("Are you feeling great with me today? ") # prompt to ask if user wants to start chatting | |
status=True | |
for i in user.split(): | |
if i.lower() in REFUSE: # return to main menu | |
from main2 import main2 | |
main2() | |
else: # start chatting | |
print("Great! \n") | |
social(user) | |
'''Greeting part ends''' |