AdvancedTagScript 3.2.4__tar.gz → 3.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/AdvancedTagScript.egg-info/PKG-INFO +3 -4
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/AdvancedTagScript.egg-info/SOURCES.txt +4 -6
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/PKG-INFO +3 -4
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/README.md +1 -1
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/__init__.py +12 -1
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/adapter/redbotadapters.py +1 -1
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/block/__init__.py +26 -12
- advancedtagscript-3.3.0/TagScriptEngine/block/assign.py +217 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/block/case.py +5 -3
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/block/command.py +1 -1
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/block/cooldown.py +3 -0
- advancedtagscript-3.3.0/TagScriptEngine/block/count.py +78 -0
- advancedtagscript-3.3.0/TagScriptEngine/block/cycleblock.py +74 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/block/embedblock.py +58 -27
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/block/helpers.py +35 -56
- advancedtagscript-3.3.0/TagScriptEngine/block/joinblock.py +43 -0
- advancedtagscript-3.3.0/TagScriptEngine/block/listblock.py +66 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/block/mathblock.py +77 -12
- advancedtagscript-3.3.0/TagScriptEngine/block/ordblock.py +62 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/block/replaceblock.py +16 -9
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/block/stopblock.py +1 -1
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/block/strf.py +1 -1
- advancedtagscript-3.3.0/TagScriptEngine/block/substr.py +80 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/block/urlencodeblock.py +2 -2
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/interpreter.py +5 -5
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/setup.cfg +1 -2
- advancedtagscript-3.2.4/TagScriptEngine/block/assign.py +0 -43
- advancedtagscript-3.2.4/TagScriptEngine/block/comment.py +0 -29
- advancedtagscript-3.2.4/TagScriptEngine/block/count.py +0 -68
- advancedtagscript-3.2.4/TagScriptEngine/block/substr.py +0 -25
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/AdvancedTagScript.egg-info/dependency_links.txt +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/AdvancedTagScript.egg-info/requires.txt +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/AdvancedTagScript.egg-info/top_level.txt +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/LICENSE +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/MANIFEST.in +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/_warnings.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/adapter/__init__.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/adapter/discordadapters.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/adapter/functionadapter.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/adapter/intadapter.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/adapter/objectadapter.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/adapter/stringadapter.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/block/allowedmentions.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/block/breakblock.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/block/control.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/block/fiftyfifty.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/block/loosevariablegetter.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/block/randomblock.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/block/range.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/block/redirect.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/block/require_blacklist.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/block/shortcutredirect.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/block/strictvariablegetter.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/exceptions.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/interface/__init__.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/interface/adapter.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/interface/block.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/py.typed +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/utils.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/verb.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/pyproject.toml +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/setup.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/tests/test_adapters.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/tests/test_basic.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/tests/test_edgecase.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/tests/test_escapes.py +0 -0
- {advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/tests/test_verbs.py +0 -0
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: AdvancedTagScript
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.3.0
|
|
4
4
|
Summary: An easy drop in user-provided Templating system.
|
|
5
5
|
Home-page: https://github.com/cool-aid-man/TagScriptEngine
|
|
6
6
|
Author: cool-aid-man, inthedark.org, PhenoM4n4n
|
|
7
7
|
Author-email: coolaid@duskybot.xyz
|
|
8
|
-
License:
|
|
8
|
+
License: CC-BY-4.0
|
|
9
9
|
Keywords: tagscript,string-templating,discord.py
|
|
10
10
|
Classifier: Development Status :: 5 - Production/Stable
|
|
11
11
|
Classifier: Intended Audience :: Developers
|
|
12
|
-
Classifier: License :: Freely Distributable
|
|
13
12
|
Classifier: Natural Language :: English
|
|
14
13
|
Classifier: Operating System :: OS Independent
|
|
15
14
|
Classifier: Programming Language :: Python :: 3.8
|
|
@@ -41,7 +40,7 @@ Dynamic: license-file
|
|
|
41
40
|
<img src="https://img.shields.io/pypi/v/AdvancedTagScript" alt="PyPI - Version">
|
|
42
41
|
</a>
|
|
43
42
|
<a href="https://advancedtagscript.readthedocs.io/en/latest/?badge=latest">
|
|
44
|
-
<img src="https://readthedocs.org/projects/
|
|
43
|
+
<img src="https://readthedocs.org/projects/AdvancedTagScript/badge/?version=latest" alt="Documentation Status" />
|
|
45
44
|
</a>
|
|
46
45
|
<a href="https://pypi.python.org/pypi/AdvancedTagScript/">
|
|
47
46
|
<img src="https://img.shields.io/pypi/dm/AdvancedTagScript" alt="PyPI - Downloads" />
|
|
@@ -9,11 +9,6 @@ AdvancedTagScript.egg-info/SOURCES.txt
|
|
|
9
9
|
AdvancedTagScript.egg-info/dependency_links.txt
|
|
10
10
|
AdvancedTagScript.egg-info/requires.txt
|
|
11
11
|
AdvancedTagScript.egg-info/top_level.txt
|
|
12
|
-
AdvancedTagscript.egg-info/PKG-INFO
|
|
13
|
-
AdvancedTagscript.egg-info/SOURCES.txt
|
|
14
|
-
AdvancedTagscript.egg-info/dependency_links.txt
|
|
15
|
-
AdvancedTagscript.egg-info/requires.txt
|
|
16
|
-
AdvancedTagscript.egg-info/top_level.txt
|
|
17
12
|
TagScriptEngine/__init__.py
|
|
18
13
|
TagScriptEngine/_warnings.py
|
|
19
14
|
TagScriptEngine/exceptions.py
|
|
@@ -34,15 +29,18 @@ TagScriptEngine/block/assign.py
|
|
|
34
29
|
TagScriptEngine/block/breakblock.py
|
|
35
30
|
TagScriptEngine/block/case.py
|
|
36
31
|
TagScriptEngine/block/command.py
|
|
37
|
-
TagScriptEngine/block/comment.py
|
|
38
32
|
TagScriptEngine/block/control.py
|
|
39
33
|
TagScriptEngine/block/cooldown.py
|
|
40
34
|
TagScriptEngine/block/count.py
|
|
35
|
+
TagScriptEngine/block/cycleblock.py
|
|
41
36
|
TagScriptEngine/block/embedblock.py
|
|
42
37
|
TagScriptEngine/block/fiftyfifty.py
|
|
43
38
|
TagScriptEngine/block/helpers.py
|
|
39
|
+
TagScriptEngine/block/joinblock.py
|
|
40
|
+
TagScriptEngine/block/listblock.py
|
|
44
41
|
TagScriptEngine/block/loosevariablegetter.py
|
|
45
42
|
TagScriptEngine/block/mathblock.py
|
|
43
|
+
TagScriptEngine/block/ordblock.py
|
|
46
44
|
TagScriptEngine/block/randomblock.py
|
|
47
45
|
TagScriptEngine/block/range.py
|
|
48
46
|
TagScriptEngine/block/redirect.py
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: AdvancedTagScript
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.3.0
|
|
4
4
|
Summary: An easy drop in user-provided Templating system.
|
|
5
5
|
Home-page: https://github.com/cool-aid-man/TagScriptEngine
|
|
6
6
|
Author: cool-aid-man, inthedark.org, PhenoM4n4n
|
|
7
7
|
Author-email: coolaid@duskybot.xyz
|
|
8
|
-
License:
|
|
8
|
+
License: CC-BY-4.0
|
|
9
9
|
Keywords: tagscript,string-templating,discord.py
|
|
10
10
|
Classifier: Development Status :: 5 - Production/Stable
|
|
11
11
|
Classifier: Intended Audience :: Developers
|
|
12
|
-
Classifier: License :: Freely Distributable
|
|
13
12
|
Classifier: Natural Language :: English
|
|
14
13
|
Classifier: Operating System :: OS Independent
|
|
15
14
|
Classifier: Programming Language :: Python :: 3.8
|
|
@@ -41,7 +40,7 @@ Dynamic: license-file
|
|
|
41
40
|
<img src="https://img.shields.io/pypi/v/AdvancedTagScript" alt="PyPI - Version">
|
|
42
41
|
</a>
|
|
43
42
|
<a href="https://advancedtagscript.readthedocs.io/en/latest/?badge=latest">
|
|
44
|
-
<img src="https://readthedocs.org/projects/
|
|
43
|
+
<img src="https://readthedocs.org/projects/AdvancedTagScript/badge/?version=latest" alt="Documentation Status" />
|
|
45
44
|
</a>
|
|
46
45
|
<a href="https://pypi.python.org/pypi/AdvancedTagScript/">
|
|
47
46
|
<img src="https://img.shields.io/pypi/dm/AdvancedTagScript" alt="PyPI - Downloads" />
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<img src="https://img.shields.io/pypi/v/AdvancedTagScript" alt="PyPI - Version">
|
|
7
7
|
</a>
|
|
8
8
|
<a href="https://advancedtagscript.readthedocs.io/en/latest/?badge=latest">
|
|
9
|
-
<img src="https://readthedocs.org/projects/
|
|
9
|
+
<img src="https://readthedocs.org/projects/AdvancedTagScript/badge/?version=latest" alt="Documentation Status" />
|
|
10
10
|
</a>
|
|
11
11
|
<a href="https://pypi.python.org/pypi/AdvancedTagScript/">
|
|
12
12
|
<img src="https://img.shields.io/pypi/dm/AdvancedTagScript" alt="PyPI - Downloads" />
|
|
@@ -55,6 +55,11 @@ from .block import (
|
|
|
55
55
|
CountBlock as CountBlock,
|
|
56
56
|
LengthBlock as LengthBlock,
|
|
57
57
|
CooldownBlock as CooldownBlock,
|
|
58
|
+
JoinBlock as JoinBlock,
|
|
59
|
+
ListBlock as ListBlock,
|
|
60
|
+
CycleBlock as CycleBlock,
|
|
61
|
+
OrdinalBlock as OrdinalBlock,
|
|
62
|
+
|
|
58
63
|
)
|
|
59
64
|
from .interface import (
|
|
60
65
|
Adapter as Adapter,
|
|
@@ -97,6 +102,7 @@ __all__: Tuple[str, ...] = (
|
|
|
97
102
|
"helper_parse_if",
|
|
98
103
|
"helper_parse_list_if",
|
|
99
104
|
"helper_split",
|
|
105
|
+
"AllowedMentionsBlock",
|
|
100
106
|
"AllBlock",
|
|
101
107
|
"AnyBlock",
|
|
102
108
|
"AssignmentBlock",
|
|
@@ -127,6 +133,11 @@ __all__: Tuple[str, ...] = (
|
|
|
127
133
|
"LowerBlock",
|
|
128
134
|
"CountBlock",
|
|
129
135
|
"LengthBlock",
|
|
136
|
+
"JoinBlock",
|
|
137
|
+
"ListBlock",
|
|
138
|
+
"CycleBlock",
|
|
139
|
+
"OrdinalBlock",
|
|
140
|
+
|
|
130
141
|
"SafeObjectAdapter",
|
|
131
142
|
"StringAdapter",
|
|
132
143
|
"IntAdapter",
|
|
@@ -170,7 +181,7 @@ __all__: Tuple[str, ...] = (
|
|
|
170
181
|
)
|
|
171
182
|
|
|
172
183
|
|
|
173
|
-
__version__: Final[str] = "3.
|
|
184
|
+
__version__: Final[str] = "3.3.0"
|
|
174
185
|
|
|
175
186
|
|
|
176
187
|
class VersionNamedTuple(NamedTuple):
|
{advancedtagscript-3.2.4 → advancedtagscript-3.3.0}/TagScriptEngine/adapter/redbotadapters.py
RENAMED
|
@@ -103,7 +103,7 @@ class RedBotAdapter(SimpleAdapter["Red"]):
|
|
|
103
103
|
Percentage of chunked guilds the bot has.
|
|
104
104
|
|
|
105
105
|
.. warning::
|
|
106
|
-
Attributes denoting
|
|
106
|
+
Attributes denoting ``(*)`` can only be used by the bot owner.
|
|
107
107
|
"""
|
|
108
108
|
|
|
109
109
|
if not _has_redbot:
|
|
@@ -3,13 +3,12 @@ from __future__ import annotations
|
|
|
3
3
|
from typing import Tuple
|
|
4
4
|
|
|
5
5
|
# isort: off
|
|
6
|
-
from .helpers import (
|
|
7
|
-
implicit_bool as implicit_bool,
|
|
8
|
-
helper_parse_if as helper_parse_if,
|
|
9
|
-
helper_parse_list_if as helper_parse_list_if,
|
|
10
|
-
helper_split as helper_split,
|
|
11
|
-
|
|
12
|
-
)
|
|
6
|
+
from .helpers import (
|
|
7
|
+
implicit_bool as implicit_bool,
|
|
8
|
+
helper_parse_if as helper_parse_if,
|
|
9
|
+
helper_parse_list_if as helper_parse_list_if,
|
|
10
|
+
helper_split as helper_split,
|
|
11
|
+
)
|
|
13
12
|
|
|
14
13
|
# isort: on
|
|
15
14
|
from .allowedmentions import (
|
|
@@ -89,14 +88,25 @@ from .count import (
|
|
|
89
88
|
CountBlock as CountBlock,
|
|
90
89
|
LengthBlock as LengthBlock,
|
|
91
90
|
)
|
|
91
|
+
from .joinblock import (
|
|
92
|
+
JoinBlock as JoinBlock,
|
|
93
|
+
)
|
|
94
|
+
from .listblock import (
|
|
95
|
+
ListBlock as ListBlock,
|
|
96
|
+
)
|
|
97
|
+
from .cycleblock import (
|
|
98
|
+
CycleBlock as CycleBlock,
|
|
99
|
+
)
|
|
100
|
+
from .ordblock import (
|
|
101
|
+
OrdinalBlock as OrdinalBlock,
|
|
102
|
+
)
|
|
92
103
|
|
|
93
104
|
__all__: Tuple[str, ...] = (
|
|
94
105
|
"implicit_bool",
|
|
95
|
-
"helper_parse_if",
|
|
96
|
-
"helper_parse_list_if",
|
|
97
|
-
"helper_split",
|
|
98
|
-
"
|
|
99
|
-
"AllowedMentionsBlock",
|
|
106
|
+
"helper_parse_if",
|
|
107
|
+
"helper_parse_list_if",
|
|
108
|
+
"helper_split",
|
|
109
|
+
"AllowedMentionsBlock",
|
|
100
110
|
"AllBlock",
|
|
101
111
|
"AnyBlock",
|
|
102
112
|
"AssignmentBlock",
|
|
@@ -127,4 +137,8 @@ __all__: Tuple[str, ...] = (
|
|
|
127
137
|
"LowerBlock",
|
|
128
138
|
"CountBlock",
|
|
129
139
|
"LengthBlock",
|
|
140
|
+
"JoinBlock",
|
|
141
|
+
"ListBlock",
|
|
142
|
+
"CycleBlock",
|
|
143
|
+
"OrdinalBlock",
|
|
130
144
|
)
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Optional, Tuple
|
|
4
|
+
|
|
5
|
+
from ..adapter import StringAdapter
|
|
6
|
+
from ..interface import verb_required_block
|
|
7
|
+
from ..interpreter import Context
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
__all__: Tuple[str, ...] = ("AssignmentBlock",)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AssignmentBlock(verb_required_block(False, parameter=True)): # type: ignore
|
|
14
|
+
"""
|
|
15
|
+
Variables are useful for storing a value and referencing it later in a tag.
|
|
16
|
+
Variables can be referenced using brackets as any other block.
|
|
17
|
+
|
|
18
|
+
.. note::
|
|
19
|
+
- Variables are not parsed by default. You must use the ``parse`` method to parse a variable.
|
|
20
|
+
- They are one of the most versatile and powerful features of TagScript.
|
|
21
|
+
- By default, a tag cannot store data between invocations. This is where ``variables`` come in.
|
|
22
|
+
- They are the only way to **store** data. And later **retrieve** it within the same invocation.
|
|
23
|
+
|
|
24
|
+
**Usage:** ``{=(<name>):<value>}``
|
|
25
|
+
|
|
26
|
+
**Aliases:** ``assign, let, var``
|
|
27
|
+
|
|
28
|
+
**Payload:** value
|
|
29
|
+
|
|
30
|
+
**Parameter:** name
|
|
31
|
+
|
|
32
|
+
**Examples:**
|
|
33
|
+
|
|
34
|
+
.. code-block:: yaml
|
|
35
|
+
|
|
36
|
+
{=(message1):Hi there! How are you?}
|
|
37
|
+
{=(message2):It's a beautiful day today!}
|
|
38
|
+
{=(message3):Did you know that TagScript is a powerful tool?}
|
|
39
|
+
|
|
40
|
+
Now, call the variables by their names:
|
|
41
|
+
{message1} # Hi there! How are you?
|
|
42
|
+
{message2} # It's a beautiful day today!
|
|
43
|
+
{message3} # Did you know that TagScript is a powerful tool?
|
|
44
|
+
|
|
45
|
+
More example:
|
|
46
|
+
{=(prefix):!}
|
|
47
|
+
The prefix here is `{prefix}`.
|
|
48
|
+
# The prefix here is `!`.
|
|
49
|
+
|
|
50
|
+
{assign(day):Monday}
|
|
51
|
+
{if({day}==Wednesday):It's Wednesday my dudes!|The day is {day}.}
|
|
52
|
+
# The day is Monday.
|
|
53
|
+
|
|
54
|
+
.. caution::
|
|
55
|
+
- You can name variables with **anything** ``except`` existing block names or aliases.
|
|
56
|
+
- They will ``not`` reference the value in payload, if the name is same as an existing block name or alias.
|
|
57
|
+
|
|
58
|
+
----
|
|
59
|
+
|
|
60
|
+
.. important:: How Argument Parsing Works - In Detail
|
|
61
|
+
|
|
62
|
+
- A variable is essentially a string that can be treated as a sequence of elements (words, numbers, etc.) when accessed.
|
|
63
|
+
These **elements** are split using ``delimiters`` (spaces by default) and are indexed sequentially starting from ``1``.
|
|
64
|
+
- A delimiter is a sequence of one or more characters that are used to split a string into a sequence of elements.
|
|
65
|
+
- Once a variable is assigned, its value can be referenced and ``parsed`` (split and indexed)
|
|
66
|
+
to extract ``specific`` parts. Let's take a look at **how** it works.
|
|
67
|
+
- Parsing out of bounds index will return the whole string.
|
|
68
|
+
|
|
69
|
+
----
|
|
70
|
+
|
|
71
|
+
.. rubric:: **Basic Argument Parsing**
|
|
72
|
+
|
|
73
|
+
Example
|
|
74
|
+
- "Coolaid is setting up the table. So, he grabbed - a cordless drill, some screws, a spirit level, and a pair of work gloves"
|
|
75
|
+
|
|
76
|
+
- So, our ``argument`` or ``args`` in short, would be:
|
|
77
|
+
|
|
78
|
+
.. code-block:: yaml
|
|
79
|
+
|
|
80
|
+
{=(args):Coolaid is setting up the table. So, he grabbed - a cordless drill, some screws, a spirit level, and a pair of work gloves}
|
|
81
|
+
|
|
82
|
+
.. note:: ``args`` is just a variable name, perhaps the most common name, but you can name it anything.
|
|
83
|
+
|
|
84
|
+
- Since, the default delimiter is ``space``, so you can access the ``each element`` as follows:
|
|
85
|
+
|
|
86
|
+
.. code-block:: yaml
|
|
87
|
+
|
|
88
|
+
{args(1)} -> Coolaid
|
|
89
|
+
{args(2)} -> is
|
|
90
|
+
{args(3)} -> setting
|
|
91
|
+
{args(4)} -> up
|
|
92
|
+
{args(5)} -> the
|
|
93
|
+
{args(6)} -> table.
|
|
94
|
+
|
|
95
|
+
{args(31)} -> Would return the whole string since it doesn't exist (indexing 31st element is out of bounds).
|
|
96
|
+
|
|
97
|
+
- ``0`` is special and returns the ``last`` element:
|
|
98
|
+
|
|
99
|
+
.. code-block:: yaml
|
|
100
|
+
|
|
101
|
+
{args(0)} -> gloves
|
|
102
|
+
|
|
103
|
+
- Negative indices allow you to access elements from the end of the sequence:
|
|
104
|
+
|
|
105
|
+
.. code-block:: yaml
|
|
106
|
+
|
|
107
|
+
{args(-1)} -> work
|
|
108
|
+
{args(-2)} -> of
|
|
109
|
+
{args(-3)} -> pair
|
|
110
|
+
{args(-4)} -> a
|
|
111
|
+
{args(-5)} -> and
|
|
112
|
+
{args(-6)} -> level,
|
|
113
|
+
|
|
114
|
+
.. rubric:: Prefix Range Access (``+n``)
|
|
115
|
+
|
|
116
|
+
- Prefixing an index with ``+`` returns all elements from the start up to and including that position:
|
|
117
|
+
|
|
118
|
+
.. code-block:: yaml
|
|
119
|
+
|
|
120
|
+
{args(+3)} -> Coolaid is setting
|
|
121
|
+
{args(+7)} -> Coolaid is setting up the table. So,
|
|
122
|
+
{args(+13)} -> Coolaid is setting up the table. So, he grabbed - a cordless drill,
|
|
123
|
+
|
|
124
|
+
.. rubric:: Suffix Range Access (``n+``)
|
|
125
|
+
|
|
126
|
+
- Suffixing an index with ``+`` returns all elements from that position (counting from the start) to the end:
|
|
127
|
+
|
|
128
|
+
.. code-block:: yaml
|
|
129
|
+
|
|
130
|
+
{args(3+)} -> setting up the table. So, he grabbed - a cordless drill, some screws, a spirit level, and a pair of work gloves
|
|
131
|
+
{args(7+)} -> So, he grabbed - a cordless drill, some screws, a spirit level, and a pair of work gloves
|
|
132
|
+
{args(13+)} -> drill, some screws, a spirit level, and a pair of work gloves
|
|
133
|
+
|
|
134
|
+
.. rubric:: Negative Range Access (``-n+``)
|
|
135
|
+
|
|
136
|
+
- Appending ``+`` to an negative-index returns a range — all elements from that position to the end:
|
|
137
|
+
- Negative indices are **first** resolved from the end of the sequence,
|
|
138
|
+
then range access continues forward to the end.
|
|
139
|
+
|
|
140
|
+
.. code-block:: yaml
|
|
141
|
+
|
|
142
|
+
{args(-1+)} -> work gloves # Since {args(0)} == gloves
|
|
143
|
+
{args(-11+)} -> drill, some screws, a spirit level, and a pair of work gloves
|
|
144
|
+
|
|
145
|
+
.. tip::
|
|
146
|
+
- ``+n`` → from start → n
|
|
147
|
+
- ``n+`` → from n → end (index resolved first)
|
|
148
|
+
- ``-n`` → nth element from end
|
|
149
|
+
- ``-n+`` → nth element from end → then forward to end (index resolved first)
|
|
150
|
+
|
|
151
|
+
-----
|
|
152
|
+
|
|
153
|
+
.. rubric:: **Advanced Argument Parsing**
|
|
154
|
+
|
|
155
|
+
A **custom delimiter** can be passed as the payload to change how
|
|
156
|
+
the value is split. The syntax is ``{variable(index):delimiter}``:
|
|
157
|
+
|
|
158
|
+
.. code-block:: yaml
|
|
159
|
+
|
|
160
|
+
# Using the same argument as before.
|
|
161
|
+
{=(args):Coolaid is setting up the table. So, he grabbed - a cordless drill, some screws, a spirit level, and a pair of work gloves}
|
|
162
|
+
|
|
163
|
+
1st Example:
|
|
164
|
+
{args(1):.} -> Coolaid is setting up the table
|
|
165
|
+
{args(2):.} -> So, he grabbed - a cordless drill, some screws, a spirit level, and a pair of work gloves
|
|
166
|
+
{args(3):.} -> Would return the entire string since there is no 3rd element.
|
|
167
|
+
|
|
168
|
+
2nd Example:
|
|
169
|
+
{args(1):-} -> Coolaid is setting up the table. So, he grabbed
|
|
170
|
+
{args(2):-} -> a cordless drill, some screws, a spirit level, and a pair of work gloves
|
|
171
|
+
|
|
172
|
+
.. note::
|
|
173
|
+
- In the 1st example, the custom delimiter is ``.``, hence the string is split by ``.`` leaving 2 elements.
|
|
174
|
+
- In the 2nd example, the custom delimiter is ``-``, hence the string is split by ``-`` leaving 2 elements.
|
|
175
|
+
- Since in both the examples, there are ``2 elements``, so ``args(3)`` would return the entire string.
|
|
176
|
+
Because the index ``3rd`` element is out of bounds.
|
|
177
|
+
|
|
178
|
+
.. rubric:: **Nested Variables**
|
|
179
|
+
|
|
180
|
+
- Variables can be **nested** to perform multi-level parsing:
|
|
181
|
+
|
|
182
|
+
.. code-block:: yaml
|
|
183
|
+
|
|
184
|
+
{=(raw):A - B, C, D}
|
|
185
|
+
{=(part):{raw(2):-}}
|
|
186
|
+
|
|
187
|
+
# "{raw(2):-}" splits "raw" by "-" and returns the 2nd element -> "B, C, D" (1st element is "A")
|
|
188
|
+
# Therefore, "part" == "B, C, D"
|
|
189
|
+
|
|
190
|
+
{part(1):,} -> B
|
|
191
|
+
{part(2):,} -> C
|
|
192
|
+
|
|
193
|
+
Another Example:
|
|
194
|
+
# What if you want to parse through the things that Coolaid grabbed?
|
|
195
|
+
# If you look closely the "-" delimiter is placed conveniently to separate the items. So, we'll use it:
|
|
196
|
+
|
|
197
|
+
{=(args):Coolaid is setting up the table. So, he grabbed - a cordless drill, some screws, a spirit level, and a pair of work gloves}
|
|
198
|
+
{=(items):{args(2):-}}
|
|
199
|
+
|
|
200
|
+
# "{args(2):-}" splits "args" by "-" and returns the 2nd element -> "a cordless drill, ... and a pair of work gloves"
|
|
201
|
+
# Therefore, "items" == "a cordless drill, some screws, a spirit level, and a pair of work gloves"
|
|
202
|
+
|
|
203
|
+
Items:
|
|
204
|
+
{items(1):,} -> a cordless drill
|
|
205
|
+
{items(2):,} -> some screws
|
|
206
|
+
{items(3):,} -> a spirit level
|
|
207
|
+
{items(4):,} -> and a pair of work gloves
|
|
208
|
+
|
|
209
|
+
"""
|
|
210
|
+
|
|
211
|
+
ACCEPTED_NAMES: Tuple[str, ...] = ("=", "assign", "let", "var")
|
|
212
|
+
|
|
213
|
+
def process(self, ctx: Context) -> Optional[str]:
|
|
214
|
+
if ctx.verb.parameter is None:
|
|
215
|
+
return None
|
|
216
|
+
ctx.response.variables[ctx.verb.parameter] = StringAdapter(str(ctx.verb.payload))
|
|
217
|
+
return ""
|
|
@@ -12,7 +12,7 @@ __all__: Tuple[str, ...] = ("UpperBlock", "LowerBlock")
|
|
|
12
12
|
class UpperBlock(Block):
|
|
13
13
|
"""Converts the given text to uppercase.
|
|
14
14
|
|
|
15
|
-
**Usage:** ``{upper([text])
|
|
15
|
+
**Usage:** ``{upper([text])}``
|
|
16
16
|
|
|
17
17
|
**Aliases:** ``uppercase, upper``
|
|
18
18
|
|
|
@@ -22,10 +22,11 @@ class UpperBlock(Block):
|
|
|
22
22
|
|
|
23
23
|
**Examples:** ::
|
|
24
24
|
|
|
25
|
-
The text is {
|
|
25
|
+
The text is {upper(ThIs Is A TeXt)}!
|
|
26
26
|
# The text is THIS IS A TEXT!
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
{=(args):Hello World}
|
|
29
|
+
You have entered {upper({args})}!
|
|
29
30
|
# You have entered HELLO WORLD!
|
|
30
31
|
"""
|
|
31
32
|
|
|
@@ -52,6 +53,7 @@ class LowerBlock(Block):
|
|
|
52
53
|
The text is {lower(ThIs Is A TeXt)}!
|
|
53
54
|
# The text is this is a text!
|
|
54
55
|
|
|
56
|
+
{=(args):HELLO WORLD}
|
|
55
57
|
You have entered {lower({args})}!
|
|
56
58
|
# You have entered hello world!
|
|
57
59
|
"""
|
|
@@ -28,6 +28,9 @@ class CooldownBlock(verb_required_block(True, payload=True, parameter=True)): #
|
|
|
28
28
|
cooldown is exceeded. If no message is passed, the default message will be sent instead.
|
|
29
29
|
The cooldown message supports 2 blocks: ``key`` and ``retry_after``.
|
|
30
30
|
|
|
31
|
+
.. note::
|
|
32
|
+
- Delimiter for the parameter (``<rate>`` and ``<per>``): ``|`` or ``~``. Where ``|`` takes priority over ``~``.
|
|
33
|
+
|
|
31
34
|
**Usage:** ``{cooldown(<rate>|<per>):<key>|[message]}``
|
|
32
35
|
|
|
33
36
|
**Payload:** key, message
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Optional, Tuple, cast
|
|
4
|
+
|
|
5
|
+
from ..interface import verb_required_block
|
|
6
|
+
from ..interpreter import Context
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
__all__: Tuple[str, ...] = ("CountBlock", "LengthBlock")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class CountBlock(verb_required_block(True, payload=True)): # type: ignore
|
|
13
|
+
"""
|
|
14
|
+
The count block counts occurrences of a substring within a message.
|
|
15
|
+
The search is case sensitive and includes overlapping substrings.
|
|
16
|
+
|
|
17
|
+
A payload (the message to search in) is **required**. Optionally,
|
|
18
|
+
pass the text to search for as a parameter. If no parameter is
|
|
19
|
+
provided, the block counts the number of words in the message
|
|
20
|
+
(spaces + 1).
|
|
21
|
+
|
|
22
|
+
**Usage:** ``{count([text]):<message>}``
|
|
23
|
+
|
|
24
|
+
**Aliases:** ``None``
|
|
25
|
+
|
|
26
|
+
**Payload:** ``message`` (required)
|
|
27
|
+
|
|
28
|
+
**Parameter:** ``text`` (optional, the substring to count)
|
|
29
|
+
|
|
30
|
+
**Examples:** ::
|
|
31
|
+
|
|
32
|
+
{count(Tag):TagScriptEngine}
|
|
33
|
+
# 1
|
|
34
|
+
|
|
35
|
+
{count(Tag):Tag Script Engine TagScriptEngine}
|
|
36
|
+
# 2
|
|
37
|
+
|
|
38
|
+
{count:hello world}
|
|
39
|
+
# 2 (word count: 1 space + 1)
|
|
40
|
+
|
|
41
|
+
{count(123)}
|
|
42
|
+
# Returns {count(123)} — rejected because no payload was provided
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
ACCEPTED_NAMES: Tuple[str, ...] = ("count",)
|
|
46
|
+
|
|
47
|
+
def process(self, ctx: Context) -> Optional[str]:
|
|
48
|
+
if ctx.verb.parameter:
|
|
49
|
+
payload: str = cast(str, ctx.verb.payload)
|
|
50
|
+
return str(payload.count(ctx.verb.parameter))
|
|
51
|
+
return str(cast(str, ctx.verb.payload).count(" ") + 1)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class LengthBlock(verb_required_block(True, parameter=True)): # type: ignore
|
|
55
|
+
"""
|
|
56
|
+
The length block returns the character count of the given text.
|
|
57
|
+
|
|
58
|
+
**Usage:** ``{length(<text>)}``
|
|
59
|
+
|
|
60
|
+
**Aliases:** ``len``
|
|
61
|
+
|
|
62
|
+
**Payload:** ``None``
|
|
63
|
+
|
|
64
|
+
**Parameter:** ``text`` (required)
|
|
65
|
+
|
|
66
|
+
**Examples:** ::
|
|
67
|
+
|
|
68
|
+
{len(TagScriptEngine)}
|
|
69
|
+
# 15
|
|
70
|
+
|
|
71
|
+
{len(hello world)}
|
|
72
|
+
# 11
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
ACCEPTED_NAMES: Tuple[str, ...] = ("length", "len")
|
|
76
|
+
|
|
77
|
+
def process(self, ctx: Context) -> Optional[str]:
|
|
78
|
+
return str(len(ctx.verb.parameter)) if ctx.verb.parameter else "-1"
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Optional, Tuple, cast
|
|
4
|
+
|
|
5
|
+
from ..interface import verb_required_block
|
|
6
|
+
from ..interpreter import Context
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
__all__: Tuple[str, ...] = ("CycleBlock",)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class CycleBlock(verb_required_block(True, payload=True, parameter=True)): # type: ignore
|
|
13
|
+
"""
|
|
14
|
+
The cycle block returns the element in the payload that corresponds to the
|
|
15
|
+
index value in the parameter. If the index is out of bounds, it loops around
|
|
16
|
+
using modulo (``index % list_length``).
|
|
17
|
+
|
|
18
|
+
List and Cycle blocks are another way to parse through a list of values in
|
|
19
|
+
TagScript. They both strictly use either commas ``,`` or tildes ``~`` as the
|
|
20
|
+
delimiters for the list placed in the block's payload. Use tildes when elements
|
|
21
|
+
contain commas. These blocks only function in Tags.
|
|
22
|
+
|
|
23
|
+
Cycles use ``0`` as the index for the first element. Negative values allow
|
|
24
|
+
for backward parsing. The block will return an error message if the value in
|
|
25
|
+
the parameter is not a number.
|
|
26
|
+
|
|
27
|
+
**Usage:** ``{cycle(<index>):<elem>,<elem2>,...}``
|
|
28
|
+
|
|
29
|
+
**Aliases:** ``None``
|
|
30
|
+
|
|
31
|
+
**Payload:** list of elements (comma or tilde separated)
|
|
32
|
+
|
|
33
|
+
**Parameter:** index
|
|
34
|
+
|
|
35
|
+
**Examples:**
|
|
36
|
+
|
|
37
|
+
.. code-block:: yaml
|
|
38
|
+
|
|
39
|
+
{cycle(1):Cake,Candy,Chips,Cookies,Donut}
|
|
40
|
+
# Candy
|
|
41
|
+
|
|
42
|
+
{cycle(13):Cake,Candy,Chips,Cookies,Donut}
|
|
43
|
+
# Cookies
|
|
44
|
+
# (The list has 5 elements. 13 modulo 5 = 3. Index 3 is "Cookies".)
|
|
45
|
+
|
|
46
|
+
{cycle(3):0,1,2}
|
|
47
|
+
# 0
|
|
48
|
+
# (3 modulo 3 = 0. Index 0 is "0".)
|
|
49
|
+
|
|
50
|
+
Negative indices:
|
|
51
|
+
{cycle(-1):Apple,Banana,Cherry}
|
|
52
|
+
# Cherry
|
|
53
|
+
|
|
54
|
+
{cycle(-69):Charlie,Aid,Bob,Dave,Eve,Phen,Steve,Tom,Wendy,Xavier}
|
|
55
|
+
# Aid
|
|
56
|
+
# (-69 modulo 10 = 1. Index 1 is "Aid".)
|
|
57
|
+
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
ACCEPTED_NAMES: Tuple[str, ...] = ("cycle",)
|
|
61
|
+
|
|
62
|
+
def process(self, ctx: Context) -> Optional[str]:
|
|
63
|
+
try:
|
|
64
|
+
index = int(cast(str, ctx.verb.parameter))
|
|
65
|
+
except (ValueError, TypeError):
|
|
66
|
+
return "Invalid index: parameter must be a number."
|
|
67
|
+
|
|
68
|
+
payload = cast(str, ctx.verb.payload)
|
|
69
|
+
if "~" in payload:
|
|
70
|
+
items = payload.split("~")
|
|
71
|
+
else:
|
|
72
|
+
items = payload.split(",")
|
|
73
|
+
|
|
74
|
+
return items[index % len(items)]
|