-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
56 lines (48 loc) · 1.75 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
import colorama
import random
import json
import yaml
import time
import os
import re
def sendprompt():
print("")
command = input(f"{colorama.Fore.YELLOW}Command: {colorama.Fore.GREEN}/{colorama.Fore.WHITE}")
checkcmd(command)
def sendpromptfirst():
command = input(f"{colorama.Fore.YELLOW}Command: {colorama.Fore.GREEN}/{colorama.Fore.WHITE}")
checkcmd(command)
def checkcmd(command):
input_arr = command.split(" ")
filename = input_arr[0] + ".cmd"
setting_value = input_arr[1] if len(input_arr) > 1 else None
directory = "commands/"
sendpatern = r'send\("([^"]+)"\)'
waitpatern = r'wait\((.*?)\)'
matching_files = []
for file in os.listdir(directory):
if file.endswith(".cmd") and file == filename:
matching_files.append(os.path.join(directory, file))
if matching_files:
for file in matching_files:
with open(file, "r") as f:
file_contents = f.read()
if 'setting = {"text" : string}' in file_contents:
if setting_value:
file_contents = file_contents.replace('{setting.text}', str(setting_value))
else:
print(f"{colorama.Fore.RED}Usage: /{input_arr[0]} [text]")
sendprompt()
if 'then' in file_contents:
text = file_contents.split('then\n')[1].split('\n')[0]
match = re.search(sendpatern, file_contents)
match2 = re.search(waitpatern, file_contents)
matches = re.findall(sendpatern, file_contents)
if matches:
for match in matches:
print(match)
sendprompt()
else:
print(f"{colorama.Fore.RED}Unknown command!")
sendprompt()
sendpromptfirst()