|
12 | 12 |
|
13 | 13 | print("Formatting and sorting QAs...") |
14 | 14 |
|
| 15 | +# commands array |
| 16 | +cmds = [ |
| 17 | + ["help", "helpcmd"], |
| 18 | + ["services", connect.list_processes], |
| 19 | + ["time", "timecmd"], |
| 20 | + ["math", "mathcmd"], |
| 21 | + ["exit", exit], |
| 22 | + ["quit", exit] |
| 23 | +] |
| 24 | + |
15 | 25 | # Removes the annoying \n in all the lines |
16 | 26 | for file_line in file_lines: |
17 | 27 | file_place = file_lines.index(file_line) |
|
25 | 35 | answers.append(split_answer) |
26 | 36 |
|
27 | 37 | print("\nWelcome to Lenny! Version 0.3:30.10.20") |
28 | | -print("To get started, type in any question! Type \"help\" to get more detailed instructions.\n") |
| 38 | +print("To get started, type in any question! Type \"/help\" to get more detailed instructions.\n") |
29 | 39 |
|
30 | 40 | while True: |
31 | 41 | user_input = input("[~] ") |
|
34 | 44 | # Built in functions (priority) so that user can't overwrite them |
35 | 45 | if user_input == "exit" or user_input == "quit": |
36 | 46 | exit() |
37 | | - |
38 | | - if user_input == "help": |
39 | | - connect.run_process("helpcmd") |
40 | | - continue |
41 | 47 |
|
42 | | - math_symbols_replaced = user_input.replace("-", "+").replace("/", "+").replace("*", "+") |
43 | | - math_symbol_split = math_symbols_replaced.split("+") |
44 | | - |
45 | | - if len(math_symbol_split) > 1: |
46 | | - left_input_length = len(math_symbol_split[0]) |
47 | | - input_operator = user_input[left_input_length] |
48 | | - |
49 | | - connect.run_process("mathcmd", input_operator, math_symbol_split[0], math_symbol_split[1]) |
50 | | - continue |
51 | | - |
52 | | - if user_input == "services": |
53 | | - connect.list_processes() |
54 | | - continue |
55 | | - |
56 | | - if user_input == "whats the time" or user_input == "what is the time" or user_input == "time": |
57 | | - connect.run_process("timecmd") |
58 | | - continue |
| 48 | + # Command handling |
| 49 | + if user_input[0] == "/": |
| 50 | + foundResult = False |
| 51 | + |
| 52 | + for cmd in cmds: |
| 53 | + if user_input[1:] == cmd[0]: |
| 54 | + if isinstance(cmd[1], str): |
| 55 | + connect.run_process(cmd[1]) |
| 56 | + else: |
| 57 | + cmd[1]() |
| 58 | + |
| 59 | + foundResult = True |
| 60 | + break |
| 61 | + |
| 62 | + if foundResult == True: |
| 63 | + continue |
| 64 | + else: |
| 65 | + print("I don't think I have any commands that go by that name. Maybe try removing spaces or punctuation!") |
| 66 | + continue |
59 | 67 |
|
60 | 68 | # User-generated question/answer handling |
61 | 69 | if user_input in questions: |
|
0 commit comments