Skip to content

Commit

Permalink
Terminal now handles KeyboardInterrupt and EOF from ctrl+c and ctrl+d
Browse files Browse the repository at this point in the history
to end chat bot sessions.

This also fixes an issue where chatbot would reply after the exit()
command was issued. In addition the exit() command has been marked
for deprication in favor of using KeyboardInterrupt and EOF commands.
  • Loading branch information
gunthercox committed Dec 26, 2014
1 parent a28ed13 commit 7235e2d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
31 changes: 20 additions & 11 deletions chatterbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,26 @@ def begin(self, user_input="Type something to begin..."):

print(user_input)

while "exit()" not in user_input:

# 'raw_input' is just 'input' in python3
if sys.version_info[0] < 3:
user_input = str(raw_input())
else:
user_input = input()

bot_input = self.get_response(user_input)
for line in bot_input:
print(line["name"], line["text"])
while True:
try:
# 'raw_input' is just 'input' in python3
if sys.version_info[0] < 3:
user_input = str(raw_input())
else:
user_input = input()

# End the session if the exit command is issued
if "exit()" == user_input:
import warnings
warnings.warn("'exit()' is deprecated. Use 'ctrl c' or 'ctrl d' to end a session.")
break

bot_input = self.get_response(user_input)
for line in bot_input:
print(line["name"], line["text"])

except (KeyboardInterrupt, EOFError, SystemExit):
break


class TalkWithCleverbot(object):
Expand Down
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ talk.begin()

## Notes

Sample conversations for training the chatbot can be downloaded
from https://gist.github.com/gunthercox/6bde8279615b9b638f71

This program is not designed to be an open source version of CleverBot.
Although this **Chat Bot** returns responces, the code here handels communication
much differently then [CleverBot](http://www.cleverbot.com) does.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

setup(
name="ChatterBot",
version="1.0.0",
version="0.0.3",
description="An open-source chat bot program written in Python.",
long_description=readme("readme.md") + "\n\n" + history,
author="Gunther Cox",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_engram.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_close_results(self):
self.assertEqual(len(output), 1)
self.assertEqual(output[0].text, expected)

def test_failing_results(self):
def test_empty_input(self):

output = engram("", self.chatbot.log_directory)

Expand Down

0 comments on commit 7235e2d

Please sign in to comment.