AdvancedTagscript 3.2.3__py3-none-any.whl

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 (48) hide show
  1. TagScriptEngine/__init__.py +227 -0
  2. TagScriptEngine/_warnings.py +88 -0
  3. TagScriptEngine/adapter/__init__.py +50 -0
  4. TagScriptEngine/adapter/discordadapters.py +596 -0
  5. TagScriptEngine/adapter/functionadapter.py +23 -0
  6. TagScriptEngine/adapter/intadapter.py +22 -0
  7. TagScriptEngine/adapter/objectadapter.py +35 -0
  8. TagScriptEngine/adapter/redbotadapters.py +161 -0
  9. TagScriptEngine/adapter/stringadapter.py +47 -0
  10. TagScriptEngine/block/__init__.py +130 -0
  11. TagScriptEngine/block/allowedmentions.py +60 -0
  12. TagScriptEngine/block/assign.py +43 -0
  13. TagScriptEngine/block/breakblock.py +41 -0
  14. TagScriptEngine/block/case.py +63 -0
  15. TagScriptEngine/block/command.py +141 -0
  16. TagScriptEngine/block/comment.py +29 -0
  17. TagScriptEngine/block/control.py +149 -0
  18. TagScriptEngine/block/cooldown.py +95 -0
  19. TagScriptEngine/block/count.py +68 -0
  20. TagScriptEngine/block/embedblock.py +306 -0
  21. TagScriptEngine/block/fiftyfifty.py +34 -0
  22. TagScriptEngine/block/helpers.py +164 -0
  23. TagScriptEngine/block/loosevariablegetter.py +40 -0
  24. TagScriptEngine/block/mathblock.py +164 -0
  25. TagScriptEngine/block/randomblock.py +51 -0
  26. TagScriptEngine/block/range.py +56 -0
  27. TagScriptEngine/block/redirect.py +42 -0
  28. TagScriptEngine/block/replaceblock.py +110 -0
  29. TagScriptEngine/block/require_blacklist.py +79 -0
  30. TagScriptEngine/block/shortcutredirect.py +23 -0
  31. TagScriptEngine/block/stopblock.py +38 -0
  32. TagScriptEngine/block/strf.py +70 -0
  33. TagScriptEngine/block/strictvariablegetter.py +38 -0
  34. TagScriptEngine/block/substr.py +25 -0
  35. TagScriptEngine/block/urlencodeblock.py +41 -0
  36. TagScriptEngine/exceptions.py +105 -0
  37. TagScriptEngine/interface/__init__.py +14 -0
  38. TagScriptEngine/interface/adapter.py +75 -0
  39. TagScriptEngine/interface/block.py +124 -0
  40. TagScriptEngine/interpreter.py +502 -0
  41. TagScriptEngine/py.typed +0 -0
  42. TagScriptEngine/utils.py +71 -0
  43. TagScriptEngine/verb.py +160 -0
  44. advancedtagscript-3.2.3.dist-info/METADATA +99 -0
  45. advancedtagscript-3.2.3.dist-info/RECORD +48 -0
  46. advancedtagscript-3.2.3.dist-info/WHEEL +5 -0
  47. advancedtagscript-3.2.3.dist-info/licenses/LICENSE +1 -0
  48. advancedtagscript-3.2.3.dist-info/top_level.txt +1 -0
@@ -0,0 +1,160 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Optional, Protocol, Tuple
4
+
5
+ __all__: Tuple[str, ...] = ("Verb",)
6
+
7
+
8
+ class _Verb(Protocol):
9
+ def __init__(
10
+ self, verb_string: Optional[str] = None, *, limit: int = 2000, dot_parameter: bool = False
11
+ ) -> None: ...
12
+
13
+ def __parse(self, verb_string: str, limit: int) -> None: ...
14
+
15
+ def _parse_paranthesis_parameter(self, i: int, v: str) -> bool: ...
16
+
17
+ def _parse_dot_parameter(self, i: int, v: str) -> bool: ...
18
+
19
+ def set_payload(self) -> None: ...
20
+
21
+ def open_parameter(self, i: int) -> None: ...
22
+
23
+ def close_parameter(self, i: int) -> bool: ...
24
+
25
+
26
+ class Verb(_Verb):
27
+ """
28
+ Represents the passed TagScript block.
29
+
30
+ Parameters
31
+ ----------
32
+ verb_string: Optional[str]
33
+ The string to parse into a verb.
34
+ limit: int
35
+ The maximum number of characters to parse.
36
+ dot_parameter: bool
37
+ Whether the parameter should be followed after a "." or use the default of parantheses.
38
+
39
+ Attributes
40
+ ----------
41
+ declaration: Optional[str]
42
+ The text used to declare the block.
43
+ parameter: Optional[str]
44
+ The text passed to the block parameter in the parentheses.
45
+ payload: Optional[str]
46
+ The text passed to the block payload after the colon.
47
+
48
+ Example
49
+ -------
50
+ Below is a visual representation of a block and its attributes::
51
+
52
+ {declaration(parameter):payload}
53
+
54
+ # dot_parameter = True
55
+ {declaration.parameter:payload}
56
+ """
57
+
58
+ __slots__: Tuple[str, ...] = (
59
+ "declaration",
60
+ "parameter",
61
+ "payload",
62
+ "parsed_string",
63
+ "dec_depth",
64
+ "dec_start",
65
+ "skip_next",
66
+ "parsed_length",
67
+ "dot_parameter",
68
+ )
69
+
70
+ def __init__(
71
+ self, verb_string: Optional[str] = None, *, limit: int = 2000, dot_parameter: bool = False
72
+ ) -> None:
73
+ self.declaration: Optional[str] = None
74
+ self.parameter: Optional[str] = None
75
+ self.payload: Optional[str] = None
76
+ self.dot_parameter = dot_parameter
77
+ if verb_string is None:
78
+ return
79
+ self.__parse(verb_string, limit)
80
+
81
+ def __str__(self) -> str:
82
+ """This makes Verb compatible with str(x)"""
83
+ response = "{"
84
+ if self.declaration is not None:
85
+ response += self.declaration
86
+ if self.parameter is not None:
87
+ response += f".{self.parameter}" if self.dot_parameter else f"({self.parameter})"
88
+ if self.payload is not None:
89
+ response += ":" + self.payload
90
+ return response + "}"
91
+
92
+ def __repr__(self) -> str:
93
+ attrs = ("declaration", "parameter", "payload")
94
+ inner = " ".join(f"{attr}={getattr(self, attr)!r}" for attr in attrs)
95
+ return f"<Verb {inner}>"
96
+
97
+ def __parse(self, verb_string: str, limit: int) -> None:
98
+ self.parsed_string = verb_string[1:-1][:limit]
99
+ self.parsed_length = len(self.parsed_string)
100
+ self.dec_depth = 0
101
+ self.dec_start = 0
102
+ self.skip_next = False
103
+
104
+ parse_parameter = (
105
+ self._parse_dot_parameter if self.dot_parameter else self._parse_paranthesis_parameter
106
+ )
107
+
108
+ for i, v in enumerate(self.parsed_string):
109
+ if self.skip_next:
110
+ self.skip_next = False
111
+ continue
112
+ elif v == "\\":
113
+ self.skip_next = True
114
+ continue
115
+
116
+ if v == ":" and not self.dec_depth:
117
+ self.set_payload()
118
+ return
119
+ elif parse_parameter(i, v):
120
+ return
121
+ else:
122
+ self.set_payload()
123
+
124
+ def _parse_paranthesis_parameter(self, i: int, v: str) -> bool:
125
+ if v == "(":
126
+ self.open_parameter(i)
127
+ elif v == ")" and self.dec_depth:
128
+ return self.close_parameter(i)
129
+ return False
130
+
131
+ def _parse_dot_parameter(self, i: int, v: str) -> bool:
132
+ if v == ".":
133
+ self.open_parameter(i)
134
+ elif (v == ":" or i == self.parsed_length - 1) and self.dec_depth:
135
+ return self.close_parameter(i + 1)
136
+ return False
137
+
138
+ def set_payload(self) -> None:
139
+ res = self.parsed_string.split(":", 1)
140
+ if len(res) == 2:
141
+ self.payload = res[1]
142
+ self.declaration = res[0]
143
+
144
+ def open_parameter(self, i: int) -> None:
145
+ self.dec_depth += 1
146
+ if not self.dec_start:
147
+ self.dec_start = i
148
+ self.declaration = self.parsed_string[:i]
149
+
150
+ def close_parameter(self, i: int) -> bool:
151
+ self.dec_depth -= 1
152
+ if self.dec_depth == 0:
153
+ self.parameter = self.parsed_string[self.dec_start + 1 : i]
154
+ try:
155
+ if self.parsed_string[i + 1] == ":":
156
+ self.payload = self.parsed_string[i + 2 :]
157
+ except IndexError:
158
+ pass
159
+ return True
160
+ return False
@@ -0,0 +1,99 @@
1
+ Metadata-Version: 2.4
2
+ Name: AdvancedTagscript
3
+ Version: 3.2.3
4
+ Summary: An easy drop in user-provided Templating system.
5
+ Home-page: https://github.com/cool-aid-man/TagScriptEngine
6
+ Author: cool-aid-man, inthedark.org, PhenoM4n4n
7
+ Author-email: coolaid@duskybot.xyz
8
+ License: Creative Commons Attribution 4.0 International License
9
+ Keywords: tagscript,string-templating,discord.py
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: Freely Distributable
13
+ Classifier: Natural Language :: English
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Topic :: Internet
20
+ Classifier: Topic :: Software Development :: Libraries
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Topic :: Utilities
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.8
25
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
26
+ License-File: LICENSE
27
+ Requires-Dist: pyparsing
28
+ Requires-Dist: typing_extensions
29
+ Provides-Extra: discord
30
+ Requires-Dist: discord.py>=2.4.0; extra == "discord"
31
+ Provides-Extra: all
32
+ Requires-Dist: orjson; extra == "all"
33
+ Requires-Dist: discord.py>=2.4.0; extra == "all"
34
+ Dynamic: license-file
35
+
36
+ ## Information
37
+ <a href="https://pypi.python.org/pypi/AdvancedTagscriptEngine/">
38
+ <img src="https://img.shields.io/pypi/pyversions/AdvancedTagscriptEngine" alt="AdvancedTagScriptEngine" />
39
+ </a>
40
+ <a href="https://pypi.python.org/pypi/AdvancedTagscriptEngine/">
41
+ <img src="https://img.shields.io/pypi/v/AdvancedTagScriptEngine" alt="PyPI - Version">
42
+ </a>
43
+ <a href="https://advancedtagscript.readthedocs.io/en/latest/?badge=latest">
44
+ <img src="https://readthedocs.org/projects/tagscriptengine/badge/?version=latest" alt="Documentation Status" />
45
+ </a>
46
+ <a href="https://pypi.python.org/pypi/AdvancedTagscriptEngine/">
47
+ <img src="https://img.shields.io/pypi/dm/AdvancedTagScriptEngine" alt="PyPI - Downloads" />
48
+
49
+ </a>
50
+
51
+ This repository is a fork of JonSnowbd's [TagScript](https://github.com/JonSnowbd/TagScript), a string templating language.
52
+ This fork adds support for Discord object adapters and a couple Discord related blocks, as
53
+ well as multiple utility blocks. Additionally, several tweaks have been made to the engine's
54
+ behavior.
55
+
56
+ This TagScriptEngine is used on [Dusky, a Discord bot](https://duskybot.xyz/invite).
57
+ An example implementation can be found in the [Tags cog](https://github.com/cool-aid-man/cool-cogs/tree/main/tags).
58
+
59
+ Additional documentation on the TagScriptEngine library can be [found here](https://advancedtagscript.readthedocs.io/en/latest/).
60
+
61
+ ## Installation
62
+
63
+ Download the latest version through pip:
64
+
65
+ ```
66
+ pip(3) install AdvancedTagScriptEngine
67
+ ```
68
+
69
+ Download from a commit:
70
+
71
+ ```
72
+ pip(3) install git+https://github.com/cool-aid-man/TagScriptEngine.git@<COMMIT_HASH>
73
+ ```
74
+
75
+ Install for editing/development:
76
+
77
+ ```
78
+ git clone https://github.com/cool-aid-man/TagScriptEngine.git
79
+ pip(3) install -e ./TagScriptEngine
80
+ ```
81
+
82
+ ## What?
83
+
84
+ AdvancedTagScriptEngine is a drop in easy to use string interpreter that lets you provide users with ways of
85
+ customizing their profiles or chat rooms with interactive text.
86
+
87
+ For example TagScript comes out of the box with a random block that would let users provide
88
+ a template that produces a new result each time its ran, or assign math and variables for later
89
+ use.
90
+
91
+ ## Dependencies
92
+
93
+ `Python 3.8+`
94
+
95
+ `pyparsing`
96
+
97
+ `discord.py`
98
+
99
+ `Red-DiscordBot` [optional]
@@ -0,0 +1,48 @@
1
+ TagScriptEngine/__init__.py,sha256=M4Pyq-cF6NPjDajbQF3qA8cSYXWIhUN6EZgOsP5ba88,5911
2
+ TagScriptEngine/_warnings.py,sha256=pfMXaEVGpIue0eqgzZ6HkLXEka1UGl61-yuH9uEnVe4,2662
3
+ TagScriptEngine/exceptions.py,sha256=lhvskKi2AySE5pul_iAA251jdMv-92QkjodR4X-G27Y,2833
4
+ TagScriptEngine/interpreter.py,sha256=oiyKNXgZCsMmcCTkRnszVIqG_to7PmQKomCn_pX5sb8,16604
5
+ TagScriptEngine/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ TagScriptEngine/utils.py,sha256=Kq7_w6nuJizPYZDJIzXZ51b1ea92_7Vm_YDKbQci7F4,1697
7
+ TagScriptEngine/verb.py,sha256=nk5IenRRGuwzIY7cMyGQn7aVYvmGcNTszztAQTSHP54,5047
8
+ TagScriptEngine/adapter/__init__.py,sha256=9ohds_8-zbVKZobQCE7xb96XrF6Be8lCSjJCJHHSuDM,1266
9
+ TagScriptEngine/adapter/discordadapters.py,sha256=l_6HijmmGDRX7lhahskH6mTteJFpS7IcMEvnKPqIQhY,19005
10
+ TagScriptEngine/adapter/functionadapter.py,sha256=lQlWm0dO-41bTQ2etFpWRaGnG22V1HMy9aiB8FnFZOU,591
11
+ TagScriptEngine/adapter/intadapter.py,sha256=jENx5ah8k0U1PjJccV0NiYFsWFU9ZXTFgz3f-qx30SA,548
12
+ TagScriptEngine/adapter/objectadapter.py,sha256=7bW-Qd6gujq2ALdK3p0ONoCSPWCTv6srkkDNjzkvDEU,1017
13
+ TagScriptEngine/adapter/redbotadapters.py,sha256=AFCu4QZGSHAMwyDFHBPT9XS5aaWVzj9Hu-pwI87DXi8,5934
14
+ TagScriptEngine/adapter/stringadapter.py,sha256=VaJzkm1b8b7w1T90DjR3gOH0DIsZlWtcFe1YG7DOqBQ,1710
15
+ TagScriptEngine/block/__init__.py,sha256=pWsnL9GJ69UmZf-VCxwdAb9Kv89KNyVw_fFM7MV0NkM,2994
16
+ TagScriptEngine/block/allowedmentions.py,sha256=WMGWi1Fe0U_vUBsc4uyiX1XfQjGkhpdlyvq3HhCCLd4,2219
17
+ TagScriptEngine/block/assign.py,sha256=l3DO41BVoXZbGSHsscSdNiSLddT7ggt1bPQoJdM1Iuo,1202
18
+ TagScriptEngine/block/breakblock.py,sha256=nt3T7fDhTxH0jpO8lu0_3oC4XwVuKKg9cmkdLsZwzL8,1288
19
+ TagScriptEngine/block/case.py,sha256=0DDWG9iN1uI5kE_NaZ2Ewfwg5Ki0nph0jHL2W1YQqdY,1442
20
+ TagScriptEngine/block/command.py,sha256=1ljbZd_Mgg6Woqi6giz26coCRej-jyh4ENY_cdTwjK8,4307
21
+ TagScriptEngine/block/comment.py,sha256=wsie7-PTupqDcuHNCflYiVip4sehR7S28GQzuXIJOQo,675
22
+ TagScriptEngine/block/control.py,sha256=tALrHN0vbEXheMhoQOI_C0X_WjL3c-Qqd2zEd0rAZrE,5699
23
+ TagScriptEngine/block/cooldown.py,sha256=F4HmFoIlxIhDWw8Z8PFZqP1FoEEBmAW4aipByZKZocY,4022
24
+ TagScriptEngine/block/count.py,sha256=J_9t1N7huGktOvJTvs9jxS9z8ayK3BpB35MWbmuba2s,1867
25
+ TagScriptEngine/block/embedblock.py,sha256=NbudZCln0lEKO8WD5Zmh3W56E5jzmwBMezEaIbGcyqU,11008
26
+ TagScriptEngine/block/fiftyfifty.py,sha256=QjQP96vpQPRVpuVcF5iI1kTCkM54vUBpKgK2TEZU6vQ,827
27
+ TagScriptEngine/block/helpers.py,sha256=Zevy0tWzDAUKSD9hc6-nW7WTreRhqENgalfySwqhF7U,4386
28
+ TagScriptEngine/block/loosevariablegetter.py,sha256=ym6u9HTWKN-Cgk6OQH5FVIiGnxsND2g5o4r3kRBGH9M,1231
29
+ TagScriptEngine/block/mathblock.py,sha256=r69oCNUAjcGNO0QFBG7w9XCv7mvMrq__GoyhR7pW6fA,5802
30
+ TagScriptEngine/block/randomblock.py,sha256=udC7mCGYrtN_Exg1XZZvqvvi8KkGNnRyTkuh-6rbeSo,1594
31
+ TagScriptEngine/block/range.py,sha256=3dz6jgTIBloZyXgN7eXGsB7SBjK3Y-OJROmHOeOaJT4,1836
32
+ TagScriptEngine/block/redirect.py,sha256=BobWl6xKqVV4FZlihmJoLPwI_i0P6Sn6G6fWFf9d8CE,1140
33
+ TagScriptEngine/block/replaceblock.py,sha256=JbW-TEIQO4EgeZ3KKPKY2oIKKkVOq-syI4sIzN--OVk,3372
34
+ TagScriptEngine/block/require_blacklist.py,sha256=3jFK8Ap_ataHZrqF3MWrmXrBI5CkIXq8G6QMEq0QQXY,2810
35
+ TagScriptEngine/block/shortcutredirect.py,sha256=2F20L_7hYMxJY9s02XwxJQIWXaBQM_dwBNZKsOJQsk8,683
36
+ TagScriptEngine/block/stopblock.py,sha256=eqNmy9ZUgstU-D7Vg5E5aOXxQSD1Dd1D1wH4rcXQEZQ,1090
37
+ TagScriptEngine/block/strf.py,sha256=xL5HL8ADRnb2bYTCaRjZkV4K4y6ZMIb_HEONfTCdT4k,2048
38
+ TagScriptEngine/block/strictvariablegetter.py,sha256=XMwqGad3iy5esB2aTiD5v1EaCLGDFMvB1RF11G0-l2M,1251
39
+ TagScriptEngine/block/substr.py,sha256=QNtoOIBBC-tD2v4vT1NzmrSA5THJ_pOqQLezxWED8ek,835
40
+ TagScriptEngine/block/urlencodeblock.py,sha256=NlCSAbAgfPvG4Jh0L1ct8VyS9i4ow6V_5VXKsM36mNk,1398
41
+ TagScriptEngine/interface/__init__.py,sha256=37lAOMONKmWDLiC5Ox9Y3TNQUQbzW54oUugbQe0e9gc,341
42
+ TagScriptEngine/interface/adapter.py,sha256=4jBBz7hc-8fsRSZ5DWOrUxrhXqS0SvJCdW57TZl8sQo,1967
43
+ TagScriptEngine/interface/block.py,sha256=S0hWRH6uqBz_cYRIh3LGMyo63UK6gNidtf6EiLUKL0c,3653
44
+ advancedtagscript-3.2.3.dist-info/licenses/LICENSE,sha256=NvdimESU3jrNgd_8E4i-eTecQ_jGegRrrWk1v2gOnHY,252
45
+ advancedtagscript-3.2.3.dist-info/METADATA,sha256=3_PWQSnBpRc67XR6oz_r42s1nEztA0gAoI9B-fzor4M,3707
46
+ advancedtagscript-3.2.3.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
47
+ advancedtagscript-3.2.3.dist-info/top_level.txt,sha256=6lY4lZDvWxraERrit1lvDsCCDdfo9e83kk_tBemAJCo,16
48
+ advancedtagscript-3.2.3.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
@@ -0,0 +1 @@
1
+ TagScriptEngine