AdvancedTagScript 3.2.5__tar.gz → 3.3.1__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.
Files changed (65) hide show
  1. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/AdvancedTagScript.egg-info/PKG-INFO +1 -1
  2. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/AdvancedTagScript.egg-info/SOURCES.txt +3 -0
  3. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/PKG-INFO +1 -1
  4. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/__init__.py +7 -3
  5. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/adapter/redbotadapters.py +11 -9
  6. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/block/__init__.py +22 -12
  7. advancedtagscript-3.3.1/TagScriptEngine/block/assign.py +217 -0
  8. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/block/case.py +2 -0
  9. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/block/command.py +1 -1
  10. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/block/cooldown.py +3 -0
  11. advancedtagscript-3.3.1/TagScriptEngine/block/cycleblock.py +74 -0
  12. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/block/embedblock.py +58 -27
  13. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/block/helpers.py +35 -56
  14. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/block/joinblock.py +2 -2
  15. advancedtagscript-3.3.1/TagScriptEngine/block/listblock.py +66 -0
  16. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/block/mathblock.py +77 -12
  17. advancedtagscript-3.3.1/TagScriptEngine/block/ordblock.py +62 -0
  18. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/block/strf.py +1 -1
  19. advancedtagscript-3.3.1/TagScriptEngine/block/substr.py +80 -0
  20. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/interpreter.py +5 -5
  21. advancedtagscript-3.2.5/TagScriptEngine/block/assign.py +0 -43
  22. advancedtagscript-3.2.5/TagScriptEngine/block/substr.py +0 -25
  23. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/AdvancedTagScript.egg-info/dependency_links.txt +0 -0
  24. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/AdvancedTagScript.egg-info/requires.txt +0 -0
  25. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/AdvancedTagScript.egg-info/top_level.txt +0 -0
  26. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/LICENSE +0 -0
  27. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/MANIFEST.in +0 -0
  28. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/README.md +0 -0
  29. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/_warnings.py +0 -0
  30. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/adapter/__init__.py +0 -0
  31. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/adapter/discordadapters.py +0 -0
  32. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/adapter/functionadapter.py +0 -0
  33. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/adapter/intadapter.py +0 -0
  34. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/adapter/objectadapter.py +0 -0
  35. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/adapter/stringadapter.py +0 -0
  36. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/block/allowedmentions.py +0 -0
  37. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/block/breakblock.py +0 -0
  38. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/block/control.py +0 -0
  39. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/block/count.py +0 -0
  40. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/block/fiftyfifty.py +0 -0
  41. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/block/loosevariablegetter.py +0 -0
  42. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/block/randomblock.py +0 -0
  43. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/block/range.py +0 -0
  44. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/block/redirect.py +0 -0
  45. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/block/replaceblock.py +0 -0
  46. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/block/require_blacklist.py +0 -0
  47. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/block/shortcutredirect.py +0 -0
  48. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/block/stopblock.py +0 -0
  49. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/block/strictvariablegetter.py +0 -0
  50. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/block/urlencodeblock.py +0 -0
  51. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/exceptions.py +0 -0
  52. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/interface/__init__.py +0 -0
  53. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/interface/adapter.py +0 -0
  54. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/interface/block.py +0 -0
  55. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/py.typed +0 -0
  56. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/utils.py +0 -0
  57. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/TagScriptEngine/verb.py +0 -0
  58. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/pyproject.toml +0 -0
  59. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/setup.cfg +0 -0
  60. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/setup.py +0 -0
  61. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/tests/test_adapters.py +0 -0
  62. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/tests/test_basic.py +0 -0
  63. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/tests/test_edgecase.py +0 -0
  64. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/tests/test_escapes.py +0 -0
  65. {advancedtagscript-3.2.5 → advancedtagscript-3.3.1}/tests/test_verbs.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: AdvancedTagScript
3
- Version: 3.2.5
3
+ Version: 3.3.1
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
@@ -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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: AdvancedTagScript
3
- Version: 3.2.5
3
+ Version: 3.3.1
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
@@ -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.2.5"
184
+ __version__: Final[str] = "3.3.1"
181
185
 
182
186
 
183
187
  class VersionNamedTuple(NamedTuple):
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  import datetime
2
4
  from typing import Any, Dict, Optional, Tuple, cast
3
5
 
@@ -23,12 +25,13 @@ __all__: Tuple[str, ...] = ("RedCommandAdapter", "RedBotAdapter")
23
25
 
24
26
 
25
27
  class RedCommandAdapter(SimpleAdapter["Command"]):
26
- if not _has_redbot:
27
- raise ImportError("A Red-DiscordBot instance is required to use this.", name="redbot")
28
-
29
28
  def __init__(self, base: Command, *, signature: Optional[str] = None) -> None:
30
- super().__init__(base=base)
29
+ if not _has_redbot:
30
+ raise ImportError(
31
+ "A Red-DiscordBot instance is required to use this.", name="redbot"
32
+ )
31
33
  self.signature: Optional[str] = signature
34
+ super().__init__(base=base)
32
35
 
33
36
  def update_attributes(self) -> None:
34
37
  command: Command = self.object
@@ -103,15 +106,14 @@ class RedBotAdapter(SimpleAdapter["Red"]):
103
106
  Percentage of chunked guilds the bot has.
104
107
 
105
108
  .. warning::
106
- Attributes denoting `(*)` can only be used by the bot owner.
109
+ Attributes denoting ``(*)`` can only be used by the bot owner.
107
110
  """
108
111
 
109
- if not _has_redbot:
110
- raise ImportError("A Red-DiscordBot instance is required to use this.")
111
-
112
112
  def __init__(self, base: Red, *, owner: bool = True) -> None:
113
- super().__init__(base=base)
113
+ if not _has_redbot:
114
+ raise ImportError("A Red-DiscordBot instance is required to use this.")
114
115
  self.is_owner: bool = owner
116
+ super().__init__(base=base)
115
117
 
116
118
  def update_attributes(self) -> None:
117
119
  self.user: discord.ClientUser = cast(discord.ClientUser, self.object.user)
@@ -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
- easier_helper_split as easier_helper_split,
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
- "easier_helper_split",
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
  """
@@ -114,7 +114,7 @@ class SequentialGather(Awaitable[T]):
114
114
 
115
115
  Returns
116
116
  -------
117
- `List[T]`
117
+ ``List[T]``
118
118
  the result object.
119
119
  """
120
120
 
@@ -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, easier_helper_split, implicit_bool
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 := easier_helper_split(payload, maxsplit=3)) is None: # type: ignore
63
- raise EmbedParseError("`add_field` payload was not split by |")
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(List[str], helper_split(payload, 2)) # type: ignore
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 = easier_helper_split(payload, maxsplit=2) # type: ignore
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
- ``;`` or ``,`` into either 2 or 3 parts. The first part is the name
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
- {embed(title):my embed title}
167
- {embed({{
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())