dshellInterpreter 0.2.18.3__py3-none-any.whl → 0.2.18.5__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.

@@ -138,7 +138,7 @@ async def utils_regex_sub(ctx: Message, regex: str, replace: str, content: str =
138
138
 
139
139
  return sub(regex, replace, content if content is not None else ctx.content)
140
140
 
141
- async def utils_regex_search(ctx: Message, regex: str, content: str = None) -> bool:
141
+ async def utils_regex_search(ctx: Message, regex: str, content: str = None) -> str:
142
142
  """
143
143
  Search for a regex in a string.
144
144
  :param regex:
@@ -152,4 +152,6 @@ async def utils_regex_search(ctx: Message, regex: str, content: str = None) -> b
152
152
  if content is not None and not isinstance(content, str):
153
153
  raise Exception(f"Content must be a string, not {type(content)}!")
154
154
 
155
- return bool(search(regex, content if content is not None else ctx.content))
155
+ result = search(regex, content if content is not None else ctx.content)
156
+
157
+ return result.group() if result else ''
@@ -57,10 +57,10 @@ class DshellInterpreteur:
57
57
  '__author_id__': message.author.id,
58
58
 
59
59
  '__message__': message.content,
60
- '__message_author__': message.author.id,
61
- '__message_before__': message.content, # same as __message__, but before edit. Can be overwritten by add vars_env parameter
62
60
  '__message_content__': message.content,
63
61
  '__message_id__': message.id,
62
+ '__message_author__': message.author.id,
63
+ '__message_before__': message.content, # same as __message__, but before edit. Can be overwritten by add vars_env parameter
64
64
  '__message_url__': message.jump_url if hasattr(message, 'jump_url') else None,
65
65
  '__last_message__': message.channel.last_message_id,
66
66
 
@@ -90,7 +90,7 @@ class DshellInterpreteur:
90
90
  '__guild_forum_channels__': ListNode([channel.id for channel in message.channel.guild.forum_channels]),
91
91
  '__guild_channels_count__': len(message.channel.guild.channels),
92
92
 
93
- } if message is not None and not debug else {} # {} is used in debug mode, when ctx is None
93
+ } if message is not None and not debug else {'__ret__': None}
94
94
  if vars_env is not None: # add the variables to the environment
95
95
  self.env.update(vars_env)
96
96
  self.vars = vars if vars is not None else ''
@@ -179,9 +179,6 @@ class DshellInterpreteur:
179
179
  else:
180
180
  self.env[node.name.value] = build_ui(first_node, self)
181
181
 
182
- elif isinstance(first_node, LengthNode):
183
- self.env[node.name.value] = length(first_node)
184
-
185
182
  else:
186
183
  self.env[node.name.value] = eval_expression(node.body, self)
187
184
 
@@ -225,8 +222,9 @@ class DshellInterpreteur:
225
222
  if token.value in self.env.keys():
226
223
  return self.env[token.value]
227
224
  return token.value
228
- elif token.type == DTT.CALL_ARGS:
229
- return (self.eval_data_token(tok) for tok in token.value)
225
+ elif token.type == DTT.EVAL_GROUP:
226
+ self.execute(token.value)
227
+ return self.env['__ret__']
230
228
  elif token.type == DTT.STR:
231
229
  for match in findall(rf"\$({'|'.join(self.env.keys())})", token.value):
232
230
  token.value = token.value.replace('$' + match, str(self.env[match]))
@@ -376,8 +374,10 @@ def regroupe_commandes(body: list[Token], interpreter: DshellInterpreteur, norma
376
374
  :param interpreter: The Dshell interpreter instance.
377
375
  :param normalise: If True, normalises the arguments (make value lowercase).
378
376
  """
379
- tokens = {'*': [],
380
- '--*': {}} # tokens to return
377
+ # tokens to return
378
+ tokens = {'*': [], # not specied parameters
379
+ '--*': {}, # get all tokens after --* until reach the end. It's evaluated.
380
+ }
381
381
  current_arg = '*' # the argument keys are the types they belong to. '*' is for all arguments not explicitly specified by a separator and an IDENT
382
382
  n = len(body)
383
383
  list_tokens: list[dict] = [tokens]
@@ -422,19 +422,6 @@ def regroupe_commandes(body: list[Token], interpreter: DshellInterpreteur, norma
422
422
 
423
423
  return list_tokens
424
424
 
425
- def length(variable : LengthNode) -> int:
426
- """
427
- Count characters or items in string/list
428
- :param variable:
429
- :return:
430
- """
431
- if not isinstance(variable.body, ListNode) and variable.body.type not in (DTT.STR, DTT.IDENT):
432
- raise Exception(f'Length take string, ident or list, not {type(variable.body)} !')
433
-
434
- if isinstance(variable.body, ListNode):
435
- return len(variable.body)
436
- else:
437
- return len(variable.body.value)
438
425
 
439
426
  def build_embed_args(body: list[Token], fields: list[FieldEmbedNode], interpreter: DshellInterpreteur) -> tuple[dict, list[dict]]:
440
427
  """
@@ -20,6 +20,7 @@ __all__ = [
20
20
  'SleepNode',
21
21
  'ListNode',
22
22
  'PermissionNode',
23
+ 'EvalGroupNode',
23
24
  'ParamNode',
24
25
  'UiNode',
25
26
  'UiButtonNode',
@@ -405,6 +406,30 @@ class SleepNode(ASTNode):
405
406
  "body": [token.to_dict() for token in self.body]
406
407
  }
407
408
 
409
+ class EvalGroupNode(ASTNode):
410
+ """
411
+ Node representing a group of evaluations in the AST.
412
+ This is used to group multiple evaluations together.
413
+ """
414
+
415
+ def __init__(self, body: list[Token]):
416
+ """
417
+ :param body: list of tokens representing the body of the evaluation group
418
+ """
419
+ self.body = body
420
+
421
+ def __repr__(self):
422
+ return f"<EVAL GROUP> - {self.body}"
423
+
424
+ def to_dict(self):
425
+ """
426
+ Convert the EvalGroupNode to a dictionary representation.
427
+ :return: Dictionary representation of the EvalGroupNode.
428
+ """
429
+ return {
430
+ "type": "EvalGroupNode",
431
+ "body": [token.to_dict() for token in self.body]
432
+ }
408
433
 
409
434
  class ParamNode(ASTNode):
410
435
  """
@@ -432,7 +457,6 @@ class ParamNode(ASTNode):
432
457
  "body": [token.to_dict() for token in self.body]
433
458
  }
434
459
 
435
-
436
460
  class UiButtonNode(ASTNode):
437
461
  """
438
462
  Node representing a UI button component in the AST.
@@ -262,6 +262,8 @@ def parse(token_lines: list[list[Token]], start_node: ASTNode) -> tuple[list[AST
262
262
  elif first_token_line.type == DTT.STR:
263
263
  last_block.body.append(CommandNode(name='sm', body=ArgsCommandNode([first_token_line])))
264
264
 
265
+ elif first_token_line.type == DTT.EVAL_GROUP:
266
+ parse([first_token_line.value], last_block)
265
267
 
266
268
  else:
267
269
  last_block.body += tokens_by_line
@@ -17,7 +17,6 @@ class DshellTokenType(Enum):
17
17
  BOOL = auto(),
18
18
  NONE = auto(),
19
19
  LIST = auto()
20
- CALL_ARGS = auto()
21
20
  DICT = auto()
22
21
  MENTION = auto()
23
22
  IDENT = auto() # nom de variable, fonction
@@ -30,6 +29,7 @@ class DshellTokenType(Enum):
30
29
  MATHS_OPERATOR = auto() # ==, +, -, *, etc.
31
30
  LOGIC_OPERATOR = auto(),
32
31
  LOGIC_WORD_OPERATOR = auto() # and, or, not
32
+ EVAL_GROUP = auto() # `code`
33
33
  COMMENT = auto() # lignes commençant par ##
34
34
 
35
35
 
@@ -17,6 +17,7 @@ table_regex: dict[DTT, Pattern] = {
17
17
  DTT.ENGLOBE_SEPARATOR: compile(rf"--\*\w+\s*(.*?)\s*(?=--|$)"),
18
18
  DTT.STR: compile(r'"((?:[^\\"]|\\.)*)"', flags=DOTALL),
19
19
  DTT.COMMENT: compile(r"::(.*?)$"),
20
+ DTT.EVAL_GROUP: compile(r"`(.*?)`"),
20
21
  DTT.LIST: compile(r"\[(.*?)\]"),
21
22
  DTT.MENTION: compile(r'<(?:@!?|@&|#)([0-9]+)>'),
22
23
  DTT.SEPARATOR: compile(rf"(--)"),
@@ -80,7 +81,7 @@ class DshellTokenizer:
80
81
 
81
82
  if token_type in (
82
83
  DTT.LIST,
83
- DTT.CALL_ARGS): # si c'est un regroupement de donnée, on tokenize ce qu'il contient
84
+ DTT.EVAL_GROUP): # si c'est un regroupement de donnée, on tokenize ce qu'il contient
84
85
  result = self.tokenizer([token.value])
85
86
  token.value = result[0] if len(
86
87
  result) > 0 else result # gère si la structure de donnée est vide ou non
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dshellInterpreter
3
- Version: 0.2.18.3
3
+ Version: 0.2.18.5
4
4
  Summary: A Discord bot interpreter for creating custom commands and automations.
5
5
  Home-page: https://github.com/BOXERRMD/Dshell_Interpreter
6
6
  Author: Chronos
@@ -13,20 +13,20 @@ Dshell/DISCORD_COMMANDS/utils/utils_list.py,sha256=zqImMWvD-1UnbPP1TZewnvZpq7qs1
13
13
  Dshell/DISCORD_COMMANDS/utils/utils_member.py,sha256=1EoHooxwijc7AFJGnuae3ccjQk0x69MELtZ5ES5abLY,1165
14
14
  Dshell/DISCORD_COMMANDS/utils/utils_message.py,sha256=cQvJ15f49ddOjybARwkJKNFe3ITYQciF-pZHERFPkr0,2964
15
15
  Dshell/DISCORD_COMMANDS/utils/utils_permissions.py,sha256=Gi6vpCA2yXUZ20OCay5dkX6HeN4LglVROwcvTWVCsKg,3600
16
- Dshell/DISCORD_COMMANDS/utils/utils_string.py,sha256=WyTJJXjHwxs_76PKclRErjK8b6CFYpZhbZbAlr259HA,4667
16
+ Dshell/DISCORD_COMMANDS/utils/utils_string.py,sha256=2LvJG_PR_VkPdnsw0vKNTwhEQGNog-3gFd_rZIUpGKc,4709
17
17
  Dshell/DISCORD_COMMANDS/utils/utils_thread.py,sha256=tVl4msEwrWHY-0AytI6eY3JSs-eIFUigDSJfK9mT1ww,1457
18
18
  Dshell/_DshellInterpreteur/__init__.py,sha256=jl_gH8MoqerW--I-IHXwUZTo80JOtfr7AOA57xVgeGQ,58
19
- Dshell/_DshellInterpreteur/dshell_interpreter.py,sha256=WrYwJHXv3e7dbWOqsTW3ATjl62Ct2Ly_TKCg1LhJ03s,29613
19
+ Dshell/_DshellInterpreteur/dshell_interpreter.py,sha256=JbCaQmeeWlvv7LE2TMK5Jd9wFoXAMVVog9UA9up0BZk,29105
20
20
  Dshell/_DshellInterpreteur/errors.py,sha256=0PJz_VYZfNZeKR_PEHxw3tRkgKNNUerV0wwrq2r1luA,250
21
21
  Dshell/_DshellParser/__init__.py,sha256=ONDfhZMvClqP_6tE8SLjp-cf3pXL-auQYnfYRrHZxC4,56
22
- Dshell/_DshellParser/ast_nodes.py,sha256=RLlylX9bvbJEG3BDMGS4mnMxU8ufnZYIF59NVf_pW7A,18883
23
- Dshell/_DshellParser/dshell_parser.py,sha256=cpukpWFJlioP1pIZZMGg24GrXfnnz1nuPCIKRNsxAcE,18949
22
+ Dshell/_DshellParser/ast_nodes.py,sha256=6SGRQ4wTniah90f-teCKg-l9q3yNzazIhi7Obm38Vow,19636
23
+ Dshell/_DshellParser/dshell_parser.py,sha256=Rf6g8ZNoQjqCxDPvBRx0SnHfejsgLwNyia9cxjOoQ-I,19061
24
24
  Dshell/_DshellTokenizer/__init__.py,sha256=LIQSRhDx2B9pmPx5ADMwwD0Xr9ybneVLhHH8qrJWw_s,172
25
25
  Dshell/_DshellTokenizer/dshell_keywords.py,sha256=TI5O6y6gAXpM_dKxCW9Fk0H8VR-gmyxxKKOURgcHsCg,7219
26
- Dshell/_DshellTokenizer/dshell_token_type.py,sha256=gYIb2XN2YcgeRgmar_rBDS5CGmwfmxihu8mOW_d6lbE,1533
27
- Dshell/_DshellTokenizer/dshell_tokenizer.py,sha256=AJnUocD6hbU6wvjRAN5uDha5QQieTwXlHzZVtgRGaZQ,7307
28
- dshellinterpreter-0.2.18.3.dist-info/licenses/LICENSE,sha256=lNgcw1_xb7QENAQi3uHGymaFtbs0RV-ihiCd7AoLQjA,1082
29
- dshellinterpreter-0.2.18.3.dist-info/METADATA,sha256=-yx3desFIX3TZ2q4UNcB4PH44cGFcg1Fjhs1hRGY4To,1151
30
- dshellinterpreter-0.2.18.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
31
- dshellinterpreter-0.2.18.3.dist-info/top_level.txt,sha256=B4CMhtmchGwPQJLuqUy0GhRG-0cUGxKL4GqEbCiB_vE,7
32
- dshellinterpreter-0.2.18.3.dist-info/RECORD,,
26
+ Dshell/_DshellTokenizer/dshell_token_type.py,sha256=bkug7eBKjYofkOGmwzPnAH9rQlU14cO0PelZbT0kGoQ,1544
27
+ Dshell/_DshellTokenizer/dshell_tokenizer.py,sha256=aSXdzEyhqoYYLpMLsLwRpeQPp84PA1F5cjm9O1EYBQs,7350
28
+ dshellinterpreter-0.2.18.5.dist-info/licenses/LICENSE,sha256=lNgcw1_xb7QENAQi3uHGymaFtbs0RV-ihiCd7AoLQjA,1082
29
+ dshellinterpreter-0.2.18.5.dist-info/METADATA,sha256=F2brpKTL3vIVVhDdFBiHJrnUpuWB8X_HT6w1I-FeThc,1151
30
+ dshellinterpreter-0.2.18.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
31
+ dshellinterpreter-0.2.18.5.dist-info/top_level.txt,sha256=B4CMhtmchGwPQJLuqUy0GhRG-0cUGxKL4GqEbCiB_vE,7
32
+ dshellinterpreter-0.2.18.5.dist-info/RECORD,,