AdvancedTagScript 3.2.5__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.5 → advancedtagscript-3.3.0}/AdvancedTagScript.egg-info/PKG-INFO +1 -1
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/AdvancedTagScript.egg-info/SOURCES.txt +3 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/PKG-INFO +1 -1
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/__init__.py +7 -3
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/adapter/redbotadapters.py +1 -1
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/block/__init__.py +22 -12
- advancedtagscript-3.3.0/TagScriptEngine/block/assign.py +217 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/block/case.py +2 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/block/command.py +1 -1
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/block/cooldown.py +3 -0
- advancedtagscript-3.3.0/TagScriptEngine/block/cycleblock.py +74 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/block/embedblock.py +58 -27
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/block/helpers.py +35 -56
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/block/joinblock.py +2 -2
- advancedtagscript-3.3.0/TagScriptEngine/block/listblock.py +66 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/block/mathblock.py +77 -12
- advancedtagscript-3.3.0/TagScriptEngine/block/ordblock.py +62 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/block/strf.py +1 -1
- advancedtagscript-3.3.0/TagScriptEngine/block/substr.py +80 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/interpreter.py +5 -5
- advancedtagscript-3.2.5/TagScriptEngine/block/assign.py +0 -43
- advancedtagscript-3.2.5/TagScriptEngine/block/substr.py +0 -25
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/AdvancedTagScript.egg-info/dependency_links.txt +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/AdvancedTagScript.egg-info/requires.txt +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/AdvancedTagScript.egg-info/top_level.txt +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/LICENSE +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/MANIFEST.in +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/README.md +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/_warnings.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/adapter/__init__.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/adapter/discordadapters.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/adapter/functionadapter.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/adapter/intadapter.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/adapter/objectadapter.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/adapter/stringadapter.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/block/allowedmentions.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/block/breakblock.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/block/control.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/block/count.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/block/fiftyfifty.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/block/loosevariablegetter.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/block/randomblock.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/block/range.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/block/redirect.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/block/replaceblock.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/block/require_blacklist.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/block/shortcutredirect.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/block/stopblock.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/block/strictvariablegetter.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/block/urlencodeblock.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/exceptions.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/interface/__init__.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/interface/adapter.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/interface/block.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/py.typed +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/utils.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/TagScriptEngine/verb.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/pyproject.toml +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/setup.cfg +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/setup.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/tests/test_adapters.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/tests/test_basic.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/tests/test_edgecase.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/tests/test_escapes.py +0 -0
- {advancedtagscript-3.2.5 → advancedtagscript-3.3.0}/tests/test_verbs.py +0 -0
|
@@ -32,12 +32,15 @@ TagScriptEngine/block/command.py
|
|
|
32
32
|
TagScriptEngine/block/control.py
|
|
33
33
|
TagScriptEngine/block/cooldown.py
|
|
34
34
|
TagScriptEngine/block/count.py
|
|
35
|
+
TagScriptEngine/block/cycleblock.py
|
|
35
36
|
TagScriptEngine/block/embedblock.py
|
|
36
37
|
TagScriptEngine/block/fiftyfifty.py
|
|
37
38
|
TagScriptEngine/block/helpers.py
|
|
38
39
|
TagScriptEngine/block/joinblock.py
|
|
40
|
+
TagScriptEngine/block/listblock.py
|
|
39
41
|
TagScriptEngine/block/loosevariablegetter.py
|
|
40
42
|
TagScriptEngine/block/mathblock.py
|
|
43
|
+
TagScriptEngine/block/ordblock.py
|
|
41
44
|
TagScriptEngine/block/randomblock.py
|
|
42
45
|
TagScriptEngine/block/range.py
|
|
43
46
|
TagScriptEngine/block/redirect.py
|
|
@@ -24,7 +24,6 @@ from .block import (
|
|
|
24
24
|
helper_parse_if as helper_parse_if,
|
|
25
25
|
helper_parse_list_if as helper_parse_list_if,
|
|
26
26
|
helper_split as helper_split,
|
|
27
|
-
easier_helper_split as easier_helper_split,
|
|
28
27
|
AllowedMentionsBlock as AllowedMentionsBlock,
|
|
29
28
|
AllBlock as AllBlock,
|
|
30
29
|
AnyBlock as AnyBlock,
|
|
@@ -57,6 +56,9 @@ from .block import (
|
|
|
57
56
|
LengthBlock as LengthBlock,
|
|
58
57
|
CooldownBlock as CooldownBlock,
|
|
59
58
|
JoinBlock as JoinBlock,
|
|
59
|
+
ListBlock as ListBlock,
|
|
60
|
+
CycleBlock as CycleBlock,
|
|
61
|
+
OrdinalBlock as OrdinalBlock,
|
|
60
62
|
|
|
61
63
|
)
|
|
62
64
|
from .interface import (
|
|
@@ -100,7 +102,6 @@ __all__: Tuple[str, ...] = (
|
|
|
100
102
|
"helper_parse_if",
|
|
101
103
|
"helper_parse_list_if",
|
|
102
104
|
"helper_split",
|
|
103
|
-
"easier_helper_split",
|
|
104
105
|
"AllowedMentionsBlock",
|
|
105
106
|
"AllBlock",
|
|
106
107
|
"AnyBlock",
|
|
@@ -133,6 +134,9 @@ __all__: Tuple[str, ...] = (
|
|
|
133
134
|
"CountBlock",
|
|
134
135
|
"LengthBlock",
|
|
135
136
|
"JoinBlock",
|
|
137
|
+
"ListBlock",
|
|
138
|
+
"CycleBlock",
|
|
139
|
+
"OrdinalBlock",
|
|
136
140
|
|
|
137
141
|
"SafeObjectAdapter",
|
|
138
142
|
"StringAdapter",
|
|
@@ -177,7 +181,7 @@ __all__: Tuple[str, ...] = (
|
|
|
177
181
|
)
|
|
178
182
|
|
|
179
183
|
|
|
180
|
-
__version__: Final[str] = "3.
|
|
184
|
+
__version__: Final[str] = "3.3.0"
|
|
181
185
|
|
|
182
186
|
|
|
183
187
|
class VersionNamedTuple(NamedTuple):
|
{advancedtagscript-3.2.5 → 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 (
|
|
@@ -92,14 +91,22 @@ from .count import (
|
|
|
92
91
|
from .joinblock import (
|
|
93
92
|
JoinBlock as JoinBlock,
|
|
94
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
|
+
)
|
|
95
103
|
|
|
96
104
|
__all__: Tuple[str, ...] = (
|
|
97
105
|
"implicit_bool",
|
|
98
|
-
"helper_parse_if",
|
|
99
|
-
"helper_parse_list_if",
|
|
100
|
-
"helper_split",
|
|
101
|
-
"
|
|
102
|
-
"AllowedMentionsBlock",
|
|
106
|
+
"helper_parse_if",
|
|
107
|
+
"helper_parse_list_if",
|
|
108
|
+
"helper_split",
|
|
109
|
+
"AllowedMentionsBlock",
|
|
103
110
|
"AllBlock",
|
|
104
111
|
"AnyBlock",
|
|
105
112
|
"AssignmentBlock",
|
|
@@ -131,4 +138,7 @@ __all__: Tuple[str, ...] = (
|
|
|
131
138
|
"CountBlock",
|
|
132
139
|
"LengthBlock",
|
|
133
140
|
"JoinBlock",
|
|
141
|
+
"ListBlock",
|
|
142
|
+
"CycleBlock",
|
|
143
|
+
"OrdinalBlock",
|
|
134
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 ""
|
|
@@ -25,6 +25,7 @@ class UpperBlock(Block):
|
|
|
25
25
|
The text is {upper(ThIs Is A TeXt)}!
|
|
26
26
|
# The text is THIS IS A TEXT!
|
|
27
27
|
|
|
28
|
+
{=(args):Hello World}
|
|
28
29
|
You have entered {upper({args})}!
|
|
29
30
|
# You have entered HELLO WORLD!
|
|
30
31
|
"""
|
|
@@ -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,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)]
|
|
@@ -8,10 +8,9 @@ from discord import Colour, Embed
|
|
|
8
8
|
|
|
9
9
|
from ..interface import Block
|
|
10
10
|
from ..interpreter import Context
|
|
11
|
-
from .helpers import helper_split,
|
|
11
|
+
from .helpers import helper_split, implicit_bool
|
|
12
12
|
from ..utils import truncate
|
|
13
13
|
from ..exceptions import BadColourArgument, EmbedParseError
|
|
14
|
-
from .._warnings import removal
|
|
15
14
|
|
|
16
15
|
try:
|
|
17
16
|
import orjson # noqa: F401
|
|
@@ -59,8 +58,10 @@ def set_dynamic_url(embed: Embed, attribute: str, value: str) -> None:
|
|
|
59
58
|
|
|
60
59
|
|
|
61
60
|
def add_field(embed: Embed, _: str, payload: str) -> None:
|
|
62
|
-
if (data :=
|
|
63
|
-
raise EmbedParseError(
|
|
61
|
+
if (data := helper_split(payload, maxsplit=2, double_semicolon=True)) is None: # type: ignore
|
|
62
|
+
raise EmbedParseError(
|
|
63
|
+
"`add_field` payload was not split by `;;` (double semicolon), `|` (pipe), or `~` (tilde)"
|
|
64
|
+
)
|
|
64
65
|
try:
|
|
65
66
|
name, value, _inline = data
|
|
66
67
|
inline = implicit_bool(_inline)
|
|
@@ -69,7 +70,10 @@ def add_field(embed: Embed, _: str, payload: str) -> None:
|
|
|
69
70
|
"`inline` argument for `add_field` is not a boolean value (_inline)"
|
|
70
71
|
)
|
|
71
72
|
except ValueError:
|
|
72
|
-
name, value = cast(
|
|
73
|
+
name, value = cast(
|
|
74
|
+
List[str],
|
|
75
|
+
helper_split(payload, maxsplit=1, double_semicolon=True),
|
|
76
|
+
)
|
|
73
77
|
inline = False
|
|
74
78
|
name = truncate(name, max=FIELD_LIMITS["field.name"])
|
|
75
79
|
value = truncate(value, max=FIELD_LIMITS["field.value"])
|
|
@@ -77,7 +81,7 @@ def add_field(embed: Embed, _: str, payload: str) -> None:
|
|
|
77
81
|
|
|
78
82
|
|
|
79
83
|
def set_footer(embed: Embed, _: str, payload: str) -> None:
|
|
80
|
-
data =
|
|
84
|
+
data = helper_split(payload, maxsplit=1, double_semicolon=True) # type: ignore
|
|
81
85
|
if data is None:
|
|
82
86
|
embed.set_footer(text=truncate(payload, max=FIELD_LIMITS["footer.text"]))
|
|
83
87
|
else:
|
|
@@ -85,6 +89,15 @@ def set_footer(embed: Embed, _: str, payload: str) -> None:
|
|
|
85
89
|
embed.set_footer(text=truncate(text, max=FIELD_LIMITS["footer.text"]), icon_url=icon_url)
|
|
86
90
|
|
|
87
91
|
|
|
92
|
+
def set_author(embed: Embed, _: str, payload: str) -> None:
|
|
93
|
+
data = helper_split(payload, maxsplit=1, double_semicolon=True) # type: ignore
|
|
94
|
+
if data is None:
|
|
95
|
+
embed.set_author(name=truncate(payload, max=FIELD_LIMITS["author.name"]))
|
|
96
|
+
else:
|
|
97
|
+
name, icon_url = data
|
|
98
|
+
embed.set_author(name=truncate(name, max=FIELD_LIMITS["author.name"]), icon_url=icon_url)
|
|
99
|
+
|
|
100
|
+
|
|
88
101
|
# Discord embed field character limits
|
|
89
102
|
# https://docs.discord.com/developers/resources/message#embed-object-embed-limits
|
|
90
103
|
FIELD_LIMITS: Dict[str, int] = {
|
|
@@ -110,19 +123,41 @@ class EmbedBlock(Block):
|
|
|
110
123
|
Multiple embed generators are available online to visualize and generate
|
|
111
124
|
embed JSON.
|
|
112
125
|
|
|
126
|
+
.. important::
|
|
127
|
+
- `Embed Limits are: <https://docs.discord.com/developers/resources/message#embed-object-embed-limits>`_
|
|
128
|
+
- Title: 256 characters
|
|
129
|
+
- Description: 4096 characters
|
|
130
|
+
- Footer: 2048 characters
|
|
131
|
+
- Author: 256 characters
|
|
132
|
+
- Field name: 256 characters
|
|
133
|
+
- Field value: 1024 characters
|
|
134
|
+
- The total length of the embed must not exceed 6000 characters.
|
|
135
|
+
|
|
113
136
|
**Usage:** ``{embed(<json>)}``
|
|
114
137
|
|
|
115
138
|
**Payload:** None
|
|
116
139
|
|
|
117
140
|
**Parameter:** json
|
|
118
141
|
|
|
119
|
-
**Examples:**
|
|
142
|
+
**Examples:**
|
|
143
|
+
|
|
144
|
+
.. code-block:: yaml
|
|
120
145
|
|
|
146
|
+
Example 1:
|
|
121
147
|
{embed({"title":"Hello!", "description":"This is a test embed."})}
|
|
148
|
+
|
|
149
|
+
Example 2:
|
|
122
150
|
{embed({
|
|
123
151
|
"title":"Here's a random duck!",
|
|
124
152
|
"image":{"url":"https://random-d.uk/api/randomimg"},
|
|
125
|
-
"color":15194415
|
|
153
|
+
"color":15194415,
|
|
154
|
+
"fields": [
|
|
155
|
+
{
|
|
156
|
+
"name": "Fun Fact",
|
|
157
|
+
"value": "Ducks are birds that are well-adapted to life in and around water.",
|
|
158
|
+
"inline": false
|
|
159
|
+
}
|
|
160
|
+
]
|
|
126
161
|
})}
|
|
127
162
|
|
|
128
163
|
**Manual**
|
|
@@ -135,11 +170,12 @@ class EmbedBlock(Block):
|
|
|
135
170
|
* ``url``
|
|
136
171
|
* ``thumbnail``
|
|
137
172
|
* ``image``
|
|
173
|
+
* ``author``
|
|
138
174
|
* ``footer``
|
|
139
175
|
* ``field`` - (See below)
|
|
140
176
|
|
|
141
|
-
Adding a field to an embed requires the payload to be split by
|
|
142
|
-
|
|
177
|
+
Adding a field to an embed requires the payload to be split by ``;;``,
|
|
178
|
+
``|`` or ``~`` into either 2 or 3 parts. The first part is the name
|
|
143
179
|
of the field, the second is the text of the field, and the third
|
|
144
180
|
optionally specifies whether the field should be inline.
|
|
145
181
|
|
|
@@ -155,16 +191,22 @@ class EmbedBlock(Block):
|
|
|
155
191
|
{embed(title):Rules}
|
|
156
192
|
{embed(description):Follow these rules to ensure a good experience in our server!}
|
|
157
193
|
{embed(field):Rule 1|Respect everyone you speak to.|false}
|
|
194
|
+
{embed(author):Mod Team|{author(avatar)}}
|
|
158
195
|
{embed(footer):Thanks for reading!|{guild(icon)}}
|
|
159
196
|
|
|
160
197
|
Both methods can be combined to create an embed in a tag.
|
|
161
198
|
The following tagscript uses JSON to create an embed with fields and later
|
|
162
199
|
set the embed title.
|
|
163
200
|
|
|
164
|
-
::
|
|
201
|
+
.. caution::
|
|
202
|
+
- The ``JSON`` block acts as a base for the embed.
|
|
203
|
+
- Since blocks are processed in **order**, the ``JSON`` block **must** come **before** any manual attribute blocks.
|
|
204
|
+
- The manual attributes are used to ``modify`` or ``add`` to the embed created by the ``JSON`` block.
|
|
165
205
|
|
|
166
|
-
|
|
167
|
-
|
|
206
|
+
.. code-block:: yaml
|
|
207
|
+
|
|
208
|
+
{embed({
|
|
209
|
+
"description": "This is a test description.",
|
|
168
210
|
"fields": [
|
|
169
211
|
{
|
|
170
212
|
"name": "Field 1",
|
|
@@ -173,6 +215,8 @@ class EmbedBlock(Block):
|
|
|
173
215
|
}
|
|
174
216
|
]
|
|
175
217
|
})}
|
|
218
|
+
{embed(title):My embed title}
|
|
219
|
+
|
|
176
220
|
"""
|
|
177
221
|
|
|
178
222
|
ACCEPTED_NAMES: Tuple[str, ...] = ("embed",)
|
|
@@ -186,23 +230,10 @@ class EmbedBlock(Block):
|
|
|
186
230
|
"thumbnail": set_dynamic_url,
|
|
187
231
|
"image": set_dynamic_url,
|
|
188
232
|
"field": add_field,
|
|
233
|
+
"author": set_author,
|
|
189
234
|
"footer": set_footer,
|
|
190
235
|
}
|
|
191
236
|
|
|
192
|
-
@removal(
|
|
193
|
-
name="EmbedBlock",
|
|
194
|
-
reason=(
|
|
195
|
-
"One of EmbedBlock's trait is scheduled to be removed in the next minor release, "
|
|
196
|
-
"A minor exception handling which would restrict the embed from getting sent and "
|
|
197
|
-
"would raise TagScriptEngine.exceptions.EmbedParseError incase it had more than "
|
|
198
|
-
"6000 characters, to know more about the limitations of discord embeds refer to the "
|
|
199
|
-
"[Official Discord API Docs](https://discord.com/developers/docs/resources/channel#embed-object-embed-limits)."
|
|
200
|
-
),
|
|
201
|
-
version="3.2.0",
|
|
202
|
-
)
|
|
203
|
-
def __init__(self) -> None:
|
|
204
|
-
super().__init__()
|
|
205
|
-
|
|
206
237
|
@staticmethod
|
|
207
238
|
def get_embed(ctx: Context) -> Embed:
|
|
208
239
|
return ctx.response.actions.get("embed", Embed())
|