dshellInterpreter 0.1.3__py3-none-any.whl → 0.1.4__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.
Potentially problematic release.
This version of dshellInterpreter might be problematic. Click here for more details.
- Dshell/_DshellInterpreteur/dshell_interpreter.py +33 -4
- Dshell/_DshellParser/ast_nodes.py +9 -1
- Dshell/_DshellParser/dshell_parser.py +14 -0
- Dshell/_DshellTokenizer/dshell_keywords.py +2 -2
- Dshell/_DshellTokenizer/dshell_token_type.py +2 -1
- Dshell/_DshellTokenizer/dshell_tokenizer.py +1 -0
- {dshellinterpreter-0.1.3.dist-info → dshellinterpreter-0.1.4.dist-info}/METADATA +1 -1
- dshellinterpreter-0.1.4.dist-info/RECORD +18 -0
- dshellinterpreter-0.1.3.dist-info/RECORD +0 -18
- {dshellinterpreter-0.1.3.dist-info → dshellinterpreter-0.1.4.dist-info}/WHEEL +0 -0
- {dshellinterpreter-0.1.3.dist-info → dshellinterpreter-0.1.4.dist-info}/licenses/LICENSE +0 -0
- {dshellinterpreter-0.1.3.dist-info → dshellinterpreter-0.1.4.dist-info}/top_level.txt +0 -0
|
@@ -2,7 +2,7 @@ from asyncio import sleep
|
|
|
2
2
|
from re import findall
|
|
3
3
|
from typing import TypeVar, Union, Any, Optional, Callable
|
|
4
4
|
|
|
5
|
-
from discord import AutoShardedBot, Embed, Colour
|
|
5
|
+
from discord import AutoShardedBot, Embed, Colour, PermissionOverwrite, Permissions
|
|
6
6
|
from discord.abc import GuildChannel, PrivateChannel
|
|
7
7
|
|
|
8
8
|
from .._DshellTokenizer.dshell_keywords import *
|
|
@@ -23,7 +23,7 @@ class DshellInterpreteur:
|
|
|
23
23
|
"""
|
|
24
24
|
Interpreter Dshell code or AST.
|
|
25
25
|
"""
|
|
26
|
-
self.ast:
|
|
26
|
+
self.ast: list[ASTNode] = parse(DshellTokenizer(ast_or_code).start(), StartNode([]))[0]
|
|
27
27
|
self.env: dict[str, Any] = {}
|
|
28
28
|
self.ctx: context = ctx
|
|
29
29
|
if debug:
|
|
@@ -75,6 +75,9 @@ class DshellInterpreteur:
|
|
|
75
75
|
elif isinstance(first_node, EmbedNode):
|
|
76
76
|
self.env[node.name.value] = build_embed(first_node.body, first_node.fields, self)
|
|
77
77
|
|
|
78
|
+
elif isinstance(first_node, PermissionNode):
|
|
79
|
+
self.env[node.name.value] = build_permission(first_node.body, self)
|
|
80
|
+
|
|
78
81
|
else:
|
|
79
82
|
self.env[node.name.value] = eval_expression(node.body, self)
|
|
80
83
|
|
|
@@ -93,6 +96,7 @@ class DshellInterpreteur:
|
|
|
93
96
|
|
|
94
97
|
await sleep(sleep_time)
|
|
95
98
|
|
|
99
|
+
|
|
96
100
|
elif isinstance(node, EndNode):
|
|
97
101
|
raise RuntimeError(f"Execution interromput -> #end atteint")
|
|
98
102
|
|
|
@@ -110,6 +114,8 @@ class DshellInterpreteur:
|
|
|
110
114
|
return float(token.value)
|
|
111
115
|
elif token.type == DTT.BOOL:
|
|
112
116
|
return token.value.lower() == "true"
|
|
117
|
+
elif token.type == DTT.NONE:
|
|
118
|
+
return None
|
|
113
119
|
elif token.type == DTT.LIST:
|
|
114
120
|
return ListNode(
|
|
115
121
|
[self.eval_data_token(tok) for tok in token.value]) # token.value contient déjà une liste de Token
|
|
@@ -190,7 +196,7 @@ async def call_function(function: Callable, args: ArgsCommandNode, interpreter:
|
|
|
190
196
|
return await function(*absolute_args, **keyword_args)
|
|
191
197
|
|
|
192
198
|
|
|
193
|
-
def regroupe_commandes(body: list[Token], interpreter: DshellInterpreteur) -> dict[Union[str, Token], list[
|
|
199
|
+
def regroupe_commandes(body: list[Token], interpreter: DshellInterpreteur) -> dict[Union[str, Token], list[Any]]:
|
|
194
200
|
"""
|
|
195
201
|
Regroupe les arguments de la commande sous la forme d'un dictionnaire python.
|
|
196
202
|
Sachant que l'on peut spécifier le paramètre que l'on souhaite passer via -- suivit du nom du paramètre. Mais ce n'est pas obligatoire !
|
|
@@ -221,7 +227,7 @@ def build_embed(body: list[Token], fields: list[FieldEmbedNode], interpreter: Ds
|
|
|
221
227
|
"""
|
|
222
228
|
Construit un embed à partir des informations de la commande.
|
|
223
229
|
"""
|
|
224
|
-
args_main_embed: dict[Union[str, Token], list[
|
|
230
|
+
args_main_embed: dict[Union[str, Token], list[Any]] = regroupe_commandes(body, interpreter)
|
|
225
231
|
args_main_embed.pop('*') # on enlève les paramètres non spécifié pour l'embed
|
|
226
232
|
args_main_embed: dict[str, Token] # on précise se qu'il contient dorénavant
|
|
227
233
|
|
|
@@ -242,6 +248,29 @@ def build_embed(body: list[Token], fields: list[FieldEmbedNode], interpreter: Ds
|
|
|
242
248
|
|
|
243
249
|
return embed
|
|
244
250
|
|
|
251
|
+
def build_permission(body: list[Token], interpreter: DshellInterpreteur) -> PermissionOverwrite:
|
|
252
|
+
"""
|
|
253
|
+
Construit un dictionnaire de permissions à partir des informations de la commande.
|
|
254
|
+
"""
|
|
255
|
+
args_permissions: dict[Union[str, Token], list[Any]] = regroupe_commandes(body, interpreter)
|
|
256
|
+
args_permissions.pop('*') # on enlève les paramètres non spécifié pour les permissions
|
|
257
|
+
args_permissions: dict[str, Token] # on précise se qu'il contient dorénavant
|
|
258
|
+
|
|
259
|
+
permissions = PermissionOverwrite()
|
|
260
|
+
|
|
261
|
+
for key, value in args_permissions.items():
|
|
262
|
+
|
|
263
|
+
if key == 'allowed':
|
|
264
|
+
permissions.update(**PermissionOverwrite.from_pair(Permissions(value), Permissions())._values)
|
|
265
|
+
|
|
266
|
+
elif key == 'denied':
|
|
267
|
+
permissions.update(**PermissionOverwrite.from_pair(Permissions(), Permissions(value))._values)
|
|
268
|
+
|
|
269
|
+
else:
|
|
270
|
+
permissions.update(**{key: value})
|
|
271
|
+
|
|
272
|
+
return permissions
|
|
273
|
+
|
|
245
274
|
|
|
246
275
|
class DshellIterator:
|
|
247
276
|
"""
|
|
@@ -17,7 +17,8 @@ __all__ = [
|
|
|
17
17
|
'EmbedNode',
|
|
18
18
|
'SleepNode',
|
|
19
19
|
'IdentOperationNode',
|
|
20
|
-
'ListNode'
|
|
20
|
+
'ListNode',
|
|
21
|
+
'PermissionNode'
|
|
21
22
|
]
|
|
22
23
|
|
|
23
24
|
class ASTNode:
|
|
@@ -121,6 +122,13 @@ class EmbedNode(ASTNode):
|
|
|
121
122
|
def __repr__(self):
|
|
122
123
|
return f"<EMBED> - {self.body}"
|
|
123
124
|
|
|
125
|
+
class PermissionNode(ASTNode):
|
|
126
|
+
def __init__(self, body: list[Token]):
|
|
127
|
+
self.body = body
|
|
128
|
+
|
|
129
|
+
def __repr__(self):
|
|
130
|
+
return f"<PERMISSION> - {self.body}"
|
|
131
|
+
|
|
124
132
|
|
|
125
133
|
class SleepNode(ASTNode):
|
|
126
134
|
def __init__(self, body: list[Token]):
|
|
@@ -21,6 +21,7 @@ from .ast_nodes import (ASTNode,
|
|
|
21
21
|
IdentOperationNode,
|
|
22
22
|
EmbedNode,
|
|
23
23
|
FieldEmbedNode,
|
|
24
|
+
PermissionNode,
|
|
24
25
|
StartNode)
|
|
25
26
|
from .._DshellTokenizer.dshell_token_type import DshellTokenType as DTT
|
|
26
27
|
from .._DshellTokenizer.dshell_token_type import Token
|
|
@@ -157,6 +158,19 @@ def parse(token_lines: list[list[Token]], start_node: ASTNode) -> tuple[list[AST
|
|
|
157
158
|
raise SyntaxError(f'[FIELD] Aucun embed ouvert ligne {first_token_line.position} !')
|
|
158
159
|
last_block.fields.append(FieldEmbedNode(tokens_by_line[1:]))
|
|
159
160
|
|
|
161
|
+
elif first_token_line.value in ('perm', 'permission'):
|
|
162
|
+
perm_node = PermissionNode(body=[])
|
|
163
|
+
var_node = VarNode(tokens_by_line[1], body=[perm_node])
|
|
164
|
+
last_block.body.append(var_node)
|
|
165
|
+
_, p = parse(token_lines[pointeur + 1:], perm_node)
|
|
166
|
+
pointeur += p + 1
|
|
167
|
+
|
|
168
|
+
elif first_token_line.value in ('#perm', '#permission'):
|
|
169
|
+
if not isinstance(last_block, PermissionNode):
|
|
170
|
+
raise SyntaxError(f'[#PERM] Aucun permission ouvert ligne {first_token_line.position} !')
|
|
171
|
+
blocks.pop()
|
|
172
|
+
return blocks, pointeur
|
|
173
|
+
|
|
160
174
|
############################## AUTRE ##############################
|
|
161
175
|
|
|
162
176
|
elif first_token_line.type == DTT.IDENT:
|
|
@@ -14,10 +14,10 @@ dshell_keyword: set[str] = {
|
|
|
14
14
|
'if', 'else', 'elif', 'loop', '#end', 'var', '#loop', '#if', 'sleep'
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
|
|
17
18
|
dshell_discord_keyword: set[str] = {
|
|
18
|
-
'embed', '#embed', 'field'
|
|
19
|
+
'embed', '#embed', 'field', 'perm', 'permission', '#perm', '#permission'
|
|
19
20
|
}
|
|
20
|
-
|
|
21
21
|
dshell_commands: dict[str, Callable] = {
|
|
22
22
|
"sm": dshell_send_message, # send message
|
|
23
23
|
"dm": dshell_delete_message,
|
|
@@ -29,6 +29,7 @@ table_regex: dict[DTT, Pattern] = {
|
|
|
29
29
|
DTT.FLOAT: compile(r"(\d+\.\d+)"),
|
|
30
30
|
DTT.INT: compile(r"(\d+)"),
|
|
31
31
|
DTT.BOOL: compile(r"(True|False)", flags=IGNORECASE),
|
|
32
|
+
DTT.NONE: compile(r"(None)", flags=IGNORECASE),
|
|
32
33
|
DTT.IDENT: compile(rf"([A-Za-z0-9_]+)")
|
|
33
34
|
}
|
|
34
35
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Dshell/__init__.py,sha256=UPvXnewe_8FX9aoevMA78UN1k8AY-u8LTY3vEVxaDxw,72
|
|
2
|
+
Dshell/DISCORD_COMMANDS/__init__.py,sha256=s58iMazDXNPDLZ3Hvymh__C5w7lcgEvaYfX0-SHocRo,62
|
|
3
|
+
Dshell/DISCORD_COMMANDS/dshell_channel.py,sha256=IubzNzBtGEcbgkL_NJOWRY1oqE3Yb-ySDMUmoHKjGzM,2135
|
|
4
|
+
Dshell/DISCORD_COMMANDS/dshell_message.py,sha256=jgSGBeDDHVy8u9fX2WN6wzh7I9WqVkeySlpmbJsBZjs,1919
|
|
5
|
+
Dshell/_DshellInterpreteur/__init__.py,sha256=xy5-J-R3YmY99JF3NBHTRRLsComFxpjnCA5xacISctU,35
|
|
6
|
+
Dshell/_DshellInterpreteur/dshell_interpreter.py,sha256=PvEmcUbXAsMP6mtmTgVJzDsnh3LwEAUQjkDQgJe4HLo,12023
|
|
7
|
+
Dshell/_DshellParser/__init__.py,sha256=ONDfhZMvClqP_6tE8SLjp-cf3pXL-auQYnfYRrHZxC4,56
|
|
8
|
+
Dshell/_DshellParser/ast_nodes.py,sha256=tAoLhxR0koG4iqWx0x9TvgHqamz5VHYisDjpAxnbJVE,5683
|
|
9
|
+
Dshell/_DshellParser/dshell_parser.py,sha256=mA8uA-xBhKcfnSKfLfePwI_fD0GrHbj0VBVeJPbcGas,13956
|
|
10
|
+
Dshell/_DshellTokenizer/__init__.py,sha256=LIQSRhDx2B9pmPx5ADMwwD0Xr9ybneVLhHH8qrJWw_s,172
|
|
11
|
+
Dshell/_DshellTokenizer/dshell_keywords.py,sha256=KR9xVtinuisGe59juHcBngbKOG5jH0f1MFTTd-CBCQA,3663
|
|
12
|
+
Dshell/_DshellTokenizer/dshell_token_type.py,sha256=EG-0I3mq4XznW75JVowOmlrWS3-WsBJPFcE6pjqrXwM,958
|
|
13
|
+
Dshell/_DshellTokenizer/dshell_tokenizer.py,sha256=T-AKxnpFbJa-3rtknZEuNrPyGvCTfFXQeU2GsJqHzt8,5745
|
|
14
|
+
dshellinterpreter-0.1.4.dist-info/licenses/LICENSE,sha256=lNgcw1_xb7QENAQi3uHGymaFtbs0RV-ihiCd7AoLQjA,1082
|
|
15
|
+
dshellinterpreter-0.1.4.dist-info/METADATA,sha256=nH-VEca_4tFl-8Ysy0i5lmw9UiM4FBtccuxdruK0c2g,1093
|
|
16
|
+
dshellinterpreter-0.1.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
17
|
+
dshellinterpreter-0.1.4.dist-info/top_level.txt,sha256=B4CMhtmchGwPQJLuqUy0GhRG-0cUGxKL4GqEbCiB_vE,7
|
|
18
|
+
dshellinterpreter-0.1.4.dist-info/RECORD,,
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
Dshell/__init__.py,sha256=UPvXnewe_8FX9aoevMA78UN1k8AY-u8LTY3vEVxaDxw,72
|
|
2
|
-
Dshell/DISCORD_COMMANDS/__init__.py,sha256=s58iMazDXNPDLZ3Hvymh__C5w7lcgEvaYfX0-SHocRo,62
|
|
3
|
-
Dshell/DISCORD_COMMANDS/dshell_channel.py,sha256=IubzNzBtGEcbgkL_NJOWRY1oqE3Yb-ySDMUmoHKjGzM,2135
|
|
4
|
-
Dshell/DISCORD_COMMANDS/dshell_message.py,sha256=jgSGBeDDHVy8u9fX2WN6wzh7I9WqVkeySlpmbJsBZjs,1919
|
|
5
|
-
Dshell/_DshellInterpreteur/__init__.py,sha256=xy5-J-R3YmY99JF3NBHTRRLsComFxpjnCA5xacISctU,35
|
|
6
|
-
Dshell/_DshellInterpreteur/dshell_interpreter.py,sha256=xMGOPQFm4bEz2mNx-ZEZcQpjf_qgKw-yGv-yHVWZy9Q,10818
|
|
7
|
-
Dshell/_DshellParser/__init__.py,sha256=ONDfhZMvClqP_6tE8SLjp-cf3pXL-auQYnfYRrHZxC4,56
|
|
8
|
-
Dshell/_DshellParser/ast_nodes.py,sha256=ArTyuk7AykJ3xKiW656BOdZg92YEwbfAlzZF1YQeZoA,5483
|
|
9
|
-
Dshell/_DshellParser/dshell_parser.py,sha256=gFSngEyNcuYlpWPAPNyuwWetwIpQKFSQWnS_r1B-dRs,13247
|
|
10
|
-
Dshell/_DshellTokenizer/__init__.py,sha256=LIQSRhDx2B9pmPx5ADMwwD0Xr9ybneVLhHH8qrJWw_s,172
|
|
11
|
-
Dshell/_DshellTokenizer/dshell_keywords.py,sha256=NFa4VdfX26X5lU1Ps05hZkZg5IyBDpG9WgT9L1oTckM,3617
|
|
12
|
-
Dshell/_DshellTokenizer/dshell_token_type.py,sha256=Gp-Vg2P96oTaKpOEKGHAvER7l98mbcuwmapLVJgmoCI,937
|
|
13
|
-
Dshell/_DshellTokenizer/dshell_tokenizer.py,sha256=9ycZhz2X2uvZynE0illgi5AhtNyR_c5o1KX-pwCP1xM,5692
|
|
14
|
-
dshellinterpreter-0.1.3.dist-info/licenses/LICENSE,sha256=lNgcw1_xb7QENAQi3uHGymaFtbs0RV-ihiCd7AoLQjA,1082
|
|
15
|
-
dshellinterpreter-0.1.3.dist-info/METADATA,sha256=2JV6Io5ErRYXuFUAGbRJs_VwyAF1XPwvbR3QIk1I7o0,1093
|
|
16
|
-
dshellinterpreter-0.1.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
17
|
-
dshellinterpreter-0.1.3.dist-info/top_level.txt,sha256=B4CMhtmchGwPQJLuqUy0GhRG-0cUGxKL4GqEbCiB_vE,7
|
|
18
|
-
dshellinterpreter-0.1.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|