Skip to content

Commit 61b8808

Browse files
authored
Merge v0.3.3 pull request to main
The v0.3.3 update mainly cleans up the code and makes some things more efficient.
2 parents 97836ae + 899bfe8 commit 61b8808

8 files changed

Lines changed: 174 additions & 170 deletions

File tree

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ Lenny is a self-learning AI that can remember the answers to any question the us
44

55
So far Lenny is kind of useless because you need to know the answer to your question for Lenny to learn.
66

7-
### 0.3.2 updates:
8-
- New square root command
9-
- Auto formatting removes punctuation
7+
### 0.3.3 updates:
8+
- Cleaned up some code and made things more efficient
9+
- `help` and `services` inputs now have the same formatting as the main input
10+
- Moved all command functions into one file to save space
11+
- Fixed a so far unknown bug regarding service toggling
1012

1113
### Using Lenny
1214
1. Clone this repository

cmds.py

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
import math
2+
import datetime
3+
import formatting
4+
5+
def kSquareRoot(tested_num, repetitions): # KasCode's Square Root finder algorithm!
6+
current_min = 0
7+
current_max = tested_num
8+
percent_done = 0
9+
10+
for loop_place in range(repetitions):
11+
middle = current_min + ( current_max - current_min ) / 2
12+
#print("min: "+str(current_min)+", max: "+str(current_max)+", middle: "+str(middle))
13+
14+
tenth_percent = math.floor(loop_place/repetitions*10)
15+
if tenth_percent > percent_done:
16+
percent_done = tenth_percent
17+
print(str(tenth_percent*10)+"%")
18+
19+
if middle * middle == tested_num:
20+
print("Exact result found after "+str(loop_place)+" repetitions!")
21+
break
22+
23+
if middle * middle > tested_num:
24+
current_max = middle
25+
else:
26+
current_min = middle
27+
28+
return current_min + ( current_max - current_min ) / 2
29+
30+
def sqrtcmd():
31+
tested_num = 0
32+
reps = 0
33+
34+
while True:
35+
try:
36+
tninput = input("Enter the number you want to find the square root of: ")
37+
tninput = int(tninput)
38+
except ValueError:
39+
print("Make sure you're typing in a number!")
40+
continue
41+
else:
42+
tested_num = tninput
43+
break
44+
45+
while True:
46+
try:
47+
tninput = input("Now enter the number of algorithm repetitions. Type \"help\" for more: ")
48+
if tninput == "help":
49+
print("This number is how many times this algorithm will repeat. The higher the number, the more accurate my result will be! I recommend around 5000-50000000 (A lot)")
50+
continue
51+
else:
52+
tninput = int(tninput)
53+
except ValueError:
54+
print("Make sure you're typing in a number!")
55+
continue
56+
else:
57+
reps = tninput
58+
break
59+
60+
result = kSquareRoot(tested_num, reps)
61+
print("Result: "+str(result))
62+
63+
def timecmd():
64+
time = datetime.datetime.now()
65+
print("The time is " + time.strftime("%H") + ":" + time.strftime("%M"))
66+
print("Today is " + time.strftime("%A") + ", " + time.strftime("%d") + " " + time.strftime("%B"))
67+
68+
def helpcmd():
69+
print("\nI work by learning the answers to any question you have, then remembering them for later.\nFor more help, type in any of the subjects below for details.\nWhen you're done, type in \"exit\" to go back.")
70+
71+
print("\nformat\ncommands\ninput markers\n")
72+
73+
while True:
74+
user_input = input("[H] ")
75+
user_input = formatting.format_input(user_input)
76+
77+
if user_input == "exit":
78+
break
79+
80+
if user_input == "format":
81+
print("I recommend that you don't add any punctuations such as ! or ?. I also don't really care whether you capitalize your sentences or not!")
82+
continue
83+
84+
if user_input == "commands":
85+
print("I have some built in commands that you can use such as time and math!")
86+
print("You start all commands with a \"/\" and then the command. Below is a list of all my commands")
87+
print("/math - [ALPHA] This is still in development, but right now this is capable of doing basic math with only two numbers.")
88+
print("/help - This sends you to this page!")
89+
print("/services - Lists down all the services being used in this program, and gives you the option to disable/enable them")
90+
print("/time - Prints the time and date! Pretty nifty, huh?")
91+
print("/sqrt - Brings up the kSquareRoot function for finding the square root of the number you're looking for.")
92+
continue
93+
94+
if user_input == "input markers":
95+
print("You might have noticed that when you're typing something in, theres a little box on the left. Here is a list of what they mean:")
96+
print(" [~] - basic input where you write in a question")
97+
print(" [H] - help page input for detail on subjects")
98+
print(" [A] - answering input that will set whatever you write as the answer to your question")
99+
print(" [S] - service editing input")
100+
continue
101+
102+
def mathcmd():
103+
print("\nI work by learning the answers to any question you have, then remembering them for later.\nFor more help, type in any of the subjects below for details.\nWhen you're done, type in \"exit\" to go back.")
104+
105+
print("\nformat\ncommands\ninput markers\n")
106+
107+
while True:
108+
user_input = input("[H] ")
109+
110+
111+
if user_input == "exit":
112+
break
113+
114+
if user_input == "format":
115+
print("I recommend that you don't add any punctuations such as ! or ?. I also don't really care whether you capitalize your sentences or not!")
116+
continue
117+
118+
if user_input == "commands":
119+
print("I have some built in commands that you can use such as time and math!")
120+
print("You start all commands with a \"/\" and then the command. Below is a list of all my commands")
121+
print("/math - [ALPHA] This is still in development, but right now this is capable of doing basic math with only two numbers.")
122+
print("/help - This sends you to this page!")
123+
print("/services - Lists down all the services being used in this program, and gives you the option to disable/enable them")
124+
print("/time - Prints the time and date! Pretty nifty, huh?")
125+
print("/sqrt - Brings up the kSquareRoot function for finding the square root of the number you're looking for.")
126+
continue
127+
128+
if user_input == "input markers":
129+
print("You might have noticed that when you're typing something in, theres a little box on the left. Here is a list of what they mean:")
130+
print(" [~] - basic input where you write in a question")
131+
print(" [H] - help page input for detail on subjects")
132+
print(" [A] - answering input that will set whatever you write as the answer to your question")
133+
print(" [S] - service editing input")
134+
continue

cmds/helpcmd.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

cmds/mathcmd.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

cmds/sqrtcmd.py

Lines changed: 0 additions & 60 deletions
This file was deleted.

cmds/timecmd.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

connect.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
# Main module in the code that will be used to filter which other modules will be used
22

3-
import cmds.helpcmd
4-
import cmds.mathcmd
5-
import cmds.timecmd
6-
import cmds.sqrtcmd
3+
import cmds
4+
import formatting
75

8-
service_list_file = open("service-list", "r")
9-
services = service_list_file.readlines()
10-
service_list_file.close()
6+
with open("service-list", "r") as service_list_file:
7+
services = service_list_file.readlines()
118

129
service_enabled = []
1310
service_names = []
@@ -16,15 +13,13 @@
1613
service_names.append(split_service[0])
1714
service_enabled.append(split_service[1].rstrip()) # Get rid of that annoying \n
1815

19-
modules_list = dir(cmds)
20-
2116
def run_process(name, *args):
22-
if name in modules_list:
17+
if name in service_names:
2318
if service_enabled[service_names.index(name)] == "enabled": # Checks if the service is enabled
2419
if len(args) > 0:
25-
getattr(cmds, name).func(*args)
20+
getattr(cmds, name)(*args)
2621
else:
27-
getattr(cmds, name).func()
22+
getattr(cmds, name)()
2823
else:
2924
print("This service is disabled. Type the command \"services\" to enable it.")
3025
else:
@@ -36,6 +31,7 @@ def list_processes(): # List and toggle services
3631
print(service + " - " + service_enabled[service_names.index(service)])
3732

3833
user_input = input("[S] ")
34+
user_input = formatting.format_input(user_input)
3935

4036
if user_input == "cancel":
4137
print("Cancelled\n")
@@ -48,10 +44,9 @@ def list_processes(): # List and toggle services
4844
else:
4945
service_e = "enabled"
5046

51-
services[service_names.index(user_input)] = user_input+"-"+service_e # Overwrite file with new preferences
52-
service_file_w = open("service-list", "w")
53-
service_file_w.writelines(services)
54-
service_file_w.close()
47+
services[service_names.index(user_input)] = user_input+"-"+service_e+"\n" # Overwrite file with new preferences
48+
with open("service-list", "w") as service_file_w:
49+
service_file_w.writelines(services)
5550

5651
service_enabled[service_names.index(user_input)] = service_e # Sets local variable to disabled so that user doesn't have to reset for effect to kick in
5752
print(user_input + " " + service_e+"\n")

0 commit comments

Comments
 (0)