-
Notifications
You must be signed in to change notification settings - Fork 0
/
com.py
77 lines (62 loc) · 1.84 KB
/
com.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
65
66
67
68
69
70
71
72
73
74
75
76
77
import subprocess
class commands:
def __getitem__(self, item):
return item
# just run python code
def py(script, m, memory):
try:
exec(script[0])
return ""
except Exception as error:
return error
def bat(s, m, memory):
script = s[0]
# Add "@echo off" to hide commands if "-o" modifier is present
if "-o" in m:
script = "@echo off\n" + script
# Run the script
result = subprocess.run(script, shell=True, capture_output=True, text=True)
# Check the return code
return result.stdout
# literally just print()
def say(s, m, memory):
if s[0][0] == "%":
key = s[0][1:] # Remove the '%' prefix
if key in memory:
value = memory[key]
else:
value = f"Undefined variable: {key}"
else:
value = s[0]
if '-n' in m:
print(value, end=" ")
else:
print(value)
return ""
# declare variable
def var(s, m, mem):
# i keep forgetting this command's syntax damm it
# var {name}\{type}\{value}
memory = mem
name = s[0].lower()
value = s[2]
if value[0] == "#":
value = value.removeprefix("#")
value = eval(value)
try:
kind = s[1]
except IndexError as v:
return f"{v}"
if kind == "int":
try:
memory[name] = int(value)
except ValueError as v:
return f"not a number"
elif kind == "str":
memory[name] = value
elif kind == "bool":
try:
memory[name] = bool(int(value))
except ValueError:
memory[name] = bool(value)
return memory