forked from JonSnowbd/TagScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol.py
More file actions
50 lines (43 loc) · 1.81 KB
/
Copy pathcontrol.py
File metadata and controls
50 lines (43 loc) · 1.81 KB
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
from .. import Interpreter, adapter
from ..interface import Block
from . import helper_parse_list_if, helper_parse_if, helper_split
from typing import Optional
import random
def parse_into_output(payload, result):
if result is None:
return None
try:
output = helper_split(payload, False)
if output != None and len(output) == 2:
return output[0] if result else output[1]
else:
return payload if result else ""
except:
return None
class AnyBlock(Block):
def will_accept(self, ctx : Interpreter.Context) -> bool:
dec = ctx.verb.declaration.lower()
return any([dec=="any",dec=="or"])
def process(self, ctx : Interpreter.Context) -> Optional[str]:
if ctx.verb.payload is None or ctx.verb.parameter is None:
return None
result = any(helper_parse_list_if(ctx.verb.parameter) or [])
return parse_into_output(ctx.verb.payload, result)
class AllBlock(Block):
def will_accept(self, ctx : Interpreter.Context) -> bool:
dec = ctx.verb.declaration.lower()
return any([dec=="all",dec=="and"])
def process(self, ctx : Interpreter.Context) -> Optional[str]:
if ctx.verb.payload is None or ctx.verb.parameter is None:
return None
result = all(helper_parse_list_if(ctx.verb.parameter) or [])
return parse_into_output(ctx.verb.payload, result)
class IfBlock(Block):
def will_accept(self, ctx : Interpreter.Context) -> bool:
dec = ctx.verb.declaration.lower()
return dec == "if"
def process(self, ctx : Interpreter.Context) -> Optional[str]:
if ctx.verb.payload is None or ctx.verb.parameter is None:
return None
result = helper_parse_if(ctx.verb.parameter)
return parse_into_output(ctx.verb.payload, result)