-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·64 lines (52 loc) · 2.25 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import json
import os
import config
import process
def get_input():
# Get the size of the terminal
rows, columns = os.popen('stty size', 'r').read().split()
columns = int(columns)
# Calculate the padding for the config.current_path
left_padding = (columns - len(config.current_path)) // 2
right_padding = columns - len(config.current_path) - left_padding
# Create the = line with the config.current_path in the middle
equal_line = "=" * left_padding + config.current_path + "=" * right_padding
return input(
"\n{}\n{}: ".format(equal_line, config.USER.capitalize()))
def main():
print("\n" + "=" * 80)
print("\nWelcome to Angel chat bot!")
print("Voice is disabled by default (change config.py to enable it).")
print("You can start chatting by typing your messages.")
print("Type 'forget' to forget the conversation.")
while True:
try:
if len(config.dialogue_history) > config.dialogue_limit:
config.dialogue_history = config.dialogue_history[-config.dialogue_limit:]
# Write dialogue_history to dialogue_history.log as JSON
with open(config.dialogue_history_path, "w") as f:
json.dump(config.dialogue_history, f, indent=4)
# refresh the json values
config.set_json_values()
config.set_file_system()
config.set_current_path()
user_input = get_input()
# Check if the user wants to forget the conversation history
if user_input.lower() == 'forget':
config.dialogue_history = []
process.process_input(
"Forget about what we talked about before")
with open(config.dialogue_history_path, "w") as f:
json.dump([], f)
config.set_json_values()
# Check if the user wants to have normal conversation
else:
process.process_input(user_input)
except Exception as e:
print("An error occurred while processing the input.", e)
with open(config.PATH+'current_path.txt', 'w') as f:
f.write(config.current_path)
break
# main()
if __name__ == "__main__":
main()