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

@@ -3,4 +3,5 @@ from .dshell_message import *
3
3
  from .dshell_member import *
4
4
  from .dshell_pastbin import *
5
5
  from .dshell_role import *
6
+ from .dshell_interaction import *
6
7
  from .utils import *
@@ -0,0 +1,67 @@
1
+ __all__ = [
2
+ 'dshell_respond_interaction',
3
+ 'dshell_defer_interaction'
4
+ ]
5
+
6
+ from types import NoneType
7
+ from discord import Interaction, Embed
8
+ from pycordViews import EasyModifiedViews
9
+
10
+
11
+ async def dshell_respond_interaction(ctx: Interaction, content: str = None, delete=None, mentions: bool = None, hide: bool = False, embeds=None, view=None) -> int:
12
+ """
13
+ Responds to a message interaction on Discord
14
+ """
15
+
16
+ if not isinstance(ctx, Interaction):
17
+ raise Exception(f'Respond to an interaction must be used in an interaction context, not {type(ctx)} !')
18
+
19
+ if delete is not None and not isinstance(delete, (int, float)):
20
+ raise Exception(f'Delete parameter must be a number (seconds) or None, not {type(delete)} !')
21
+
22
+ if not isinstance(mentions, (NoneType, bool)):
23
+ raise Exception(f'Mention parameter must be a boolean or None, not {type(mentions)} !')
24
+
25
+ if not isinstance(hide, bool):
26
+ raise Exception(f'Hide parameter must be a boolean, not {type(hide)} !')
27
+
28
+ allowed_mentions = mentions if mentions is not None else False
29
+
30
+ from .._DshellParser.ast_nodes import ListNode
31
+
32
+ if not isinstance(embeds, (ListNode, Embed, NoneType)):
33
+ raise Exception(f'Embeds must be a list of Embed objects or a single Embed object, not {type(embeds)} !')
34
+
35
+ if embeds is None:
36
+ embeds = ListNode([])
37
+
38
+ elif isinstance(embeds, Embed):
39
+ embeds = ListNode([embeds])
40
+
41
+ if not isinstance(view, (EasyModifiedViews, NoneType)):
42
+ raise Exception(f'View must be an UI bloc or None, not {type(view)} !')
43
+
44
+ sended_message = await ctx.response.send_message(
45
+ content=str(content),
46
+ ephemeral=hide,
47
+ allowed_mentions=allowed_mentions,
48
+ delete_after=delete,
49
+ embeds=embeds,
50
+ view=view)
51
+
52
+ return sended_message.id
53
+
54
+ async def dshell_defer_interaction(ctx: Interaction, hide: bool = False) -> bool:
55
+ """
56
+ Defer a message interaction on Discord
57
+ """
58
+
59
+ if not isinstance(ctx, Interaction):
60
+ raise Exception(f'Respond to an interaction must be used in an interaction context, not {type(ctx)} !')
61
+
62
+ if not isinstance(hide, bool):
63
+ raise Exception(f'Hide parameter must be a boolean, not {type(hide)} !')
64
+
65
+ await ctx.response.defer(ephemeral=hide)
66
+
67
+ return True
@@ -1,4 +1,5 @@
1
1
  from re import search
2
+ from tkinter import Listbox
2
3
 
3
4
  from discord import Embed, Message, Interaction
4
5
  from discord.ext import commands
@@ -11,7 +12,6 @@ from .._utils import NoneType
11
12
  __all__ = [
12
13
  'dshell_send_message',
13
14
  'dshell_respond_message',
14
- 'dshell_respond_interaction',
15
15
  'dshell_delete_message',
16
16
  'dshell_purge_message',
17
17
  'dshell_edit_message',
@@ -88,39 +88,6 @@ async def dshell_respond_message(ctx: Message, message=None, content: str = None
88
88
 
89
89
  return sended_message.id
90
90
 
91
- async def dshell_respond_interaction(ctx: Interaction, content: str = None, delete=None, mention: bool = None, embeds=None, view=None):
92
- """
93
- Responds to a message interaction on Discord
94
- """
95
-
96
- if delete is not None and not isinstance(delete, (int, float)):
97
- raise Exception(f'Delete parameter must be a number (seconds) or None, not {type(delete)} !')
98
-
99
- mention_author = mention if mention is not None else False
100
-
101
- from .._DshellParser.ast_nodes import ListNode
102
-
103
- if not isinstance(embeds, (ListNode, Embed, NoneType)):
104
- raise Exception(f'Embeds must be a list of Embed objects or a single Embed object, not {type(embeds)} !')
105
-
106
- if embeds is None:
107
- embeds = ListNode([])
108
-
109
- elif isinstance(embeds, Embed):
110
- embeds = ListNode([embeds])
111
-
112
- if not isinstance(view, (EasyModifiedViews, NoneType)):
113
- raise Exception(f'Channel must be an UI or None, not {type(view)} !')
114
-
115
- sended_message = await ctx.response.send_message(
116
- content=str(content),
117
- ephemeral=not mention_author,
118
- delete_after=delete,
119
- embeds=embeds,
120
- view=view)
121
-
122
- return sended_message.id
123
-
124
91
  async def dshell_delete_message(ctx: Message, message=None, reason=None, delay=0):
125
92
  """
126
93
  Deletes a message
@@ -153,7 +120,7 @@ async def dshell_purge_message(ctx: Message, message_number: int, channel=None,
153
120
  await purge_channel.purge(limit=message_number, reason=reason)
154
121
 
155
122
 
156
- async def dshell_edit_message(ctx: Message, message, new_content=None, embeds=None):
123
+ async def dshell_edit_message(ctx: Message, message, new_content=None, embeds=None, view=None) -> int:
157
124
  """
158
125
  Edits a message
159
126
  """
@@ -164,18 +131,21 @@ async def dshell_edit_message(ctx: Message, message, new_content=None, embeds=No
164
131
  if not isinstance(embeds, (ListNode, Embed, NoneType)):
165
132
  raise Exception(f'Embeds must be a list of Embed objects or a single Embed object, not {type(embeds)} !')
166
133
 
134
+ if not isinstance(view, (EasyModifiedViews, NoneType)):
135
+ raise Exception(f'View must be an UI bloc or None, not {type(view)} !')
136
+
167
137
  if embeds is None:
168
138
  embeds = ListNode([])
169
139
 
170
140
  elif isinstance(embeds, Embed):
171
141
  embeds = ListNode([embeds])
172
142
 
173
- await edit_message.edit(content=new_content, embeds=embeds)
143
+ await edit_message.edit(content=new_content, embeds=embeds, view=view)
174
144
 
175
145
  return edit_message.id
176
146
 
177
147
 
178
- async def dshell_get_hystory_messages(ctx: Message, channel=None, limit=None):
148
+ async def dshell_get_hystory_messages(ctx: Message, channel=None, limit=None) -> "ListNode":
179
149
  """
180
150
  Searches for messages matching a regex in a channel
181
151
  """
@@ -21,7 +21,6 @@ from .._DshellTokenizer.dshell_tokenizer import DshellTokenizer
21
21
  All_nodes = TypeVar('All_nodes', IfNode, LoopNode, ElseNode, ElifNode, ArgsCommandNode, VarNode, IdentOperationNode)
22
22
  context = TypeVar('context', AutoShardedBot, Message, PrivateChannel, Interaction)
23
23
  ButtonStyleValues: tuple = tuple(i.name for i in ButtonStyle)
24
- print(ButtonStyleValues)
25
24
 
26
25
  class DshellInterpreteur:
27
26
  """
@@ -41,22 +40,34 @@ class DshellInterpreteur:
41
40
  message = ctx.message if isinstance(ctx, Interaction) else ctx
42
41
  self.env: dict[str, Any] = {
43
42
  '__ret__': None, # environment variables, '__ret__' is used to store the return value of commands
44
- '__guild__': message.channel.guild.name,
45
- '__channel__': message.channel.name,
46
- '__author__': message.author.name,
43
+
44
+ '__author__': message.author.id,
47
45
  '__author_display_name__': message.author.display_name,
48
46
  '__author_avatar__': message.author.display_avatar.url if message.author.display_avatar else None,
49
47
  '__author_discriminator__': message.author.discriminator,
50
48
  '__author_bot__': message.author.bot,
51
49
  '__author_nick__': message.author.nick if hasattr(message.author, 'nick') else None,
52
50
  '__author_id__': message.author.id,
51
+
53
52
  '__message__': message.content,
53
+ '__message_content__': message.content,
54
54
  '__message_id__': message.id,
55
+ '__message_url__': message.jump_url if hasattr(message, 'jump_url') else None,
56
+
57
+ '__channel__': message.channel.id,
55
58
  '__channel_name__': message.channel.name,
56
59
  '__channel_type__': message.channel.type.name if hasattr(message.channel, 'type') else None,
57
60
  '__channel_id__': message.channel.id,
58
61
  '__private_channel__': isinstance(message.channel, PrivateChannel),
59
- } if message is not None else {}
62
+
63
+ '__guild__': message.channel.guild.id,
64
+ '__guild_name__': message.channel.guild.name,
65
+ '__guild_id__': message.channel.guild.id,
66
+ '__guild_member_count__': message.channel.guild.member_count,
67
+ '__guild_icon__': message.channel.guild.icon.url if message.channel.guild.icon else None,
68
+ '__guild_owner_id__': message.channel.guild.owner_id,
69
+ '__guild_description__': message.channel.guild.description,
70
+ } if message is not None or not debug else {} # {} is used in debug mode, when ctx is None
60
71
  self.vars = vars if vars is not None else ''
61
72
  self.ctx: context = ctx
62
73
  if debug:
@@ -393,3 +393,23 @@ def print_ast(ast: list[ASTNode], decalage: int = 0):
393
393
 
394
394
  elif isinstance(i, ParamNode):
395
395
  print(f"{' ' * decalage}PARAM -> {i.body}")
396
+
397
+ elif isinstance(i, UiNode):
398
+ print(f"{' ' * decalage}UI ->")
399
+ print_ast(i.buttons, decalage + 5)
400
+ print_ast(i.selects, decalage + 5)
401
+
402
+ elif isinstance(i, UiButtonNode):
403
+ print(f"{' ' * decalage}BUTTON -> {i.body}")
404
+
405
+ elif isinstance(i, UiSelectNode):
406
+ print(f"{' ' * decalage}SELECT -> {i.body}")
407
+
408
+ elif isinstance(i, SleepNode):
409
+ print(f"{' ' * decalage}SLEEP -> {i.body}")
410
+
411
+ elif isinstance(i, EndNode):
412
+ print(f"{' ' * decalage}END -> ...")
413
+
414
+ else:
415
+ print(f"{' ' * decalage}UNKNOWN NODE {i}")
@@ -15,6 +15,7 @@ from ..DISCORD_COMMANDS.dshell_member import *
15
15
  from ..DISCORD_COMMANDS.dshell_message import *
16
16
  from ..DISCORD_COMMANDS.dshell_pastbin import *
17
17
  from ..DISCORD_COMMANDS.dshell_role import *
18
+ from ..DISCORD_COMMANDS.dshell_interaction import *
18
19
 
19
20
  dshell_keyword: set[str] = {
20
21
  'if', 'else', 'elif', 'loop', '#end', 'var', '#loop', '#if', 'sleep', 'param', '#param'
@@ -30,11 +31,13 @@ dshell_commands: dict[str, Callable] = {
30
31
  "sm": dshell_send_message, # send message
31
32
  "spm": dshell_send_private_message, # send private message
32
33
  "srm": dshell_respond_message, # respond to a message
33
- "sri": dshell_respond_interaction, # respond to an interaction
34
34
  "dm": dshell_delete_message,
35
35
  "pm": dshell_purge_message,
36
36
  "em": dshell_edit_message, # edit message
37
37
 
38
+ "sri": dshell_respond_interaction, # respond to an interaction
39
+ "di": dshell_defer_interaction, # defer an interaction
40
+
38
41
  "cc": dshell_create_text_channel, # create channel
39
42
  "cvc": dshell_create_voice_channel, # create voice channel
40
43
  "dc": dshell_delete_channel, # delete channel
@@ -14,9 +14,9 @@ from .dshell_token_type import Token
14
14
  MASK_CHARACTER = '§'
15
15
 
16
16
  table_regex: dict[DTT, Pattern] = {
17
- DTT.COMMENT: compile(r"::(.*?)"),
18
17
  DTT.ENGLOBE_SEPARATOR: compile(rf"--\*\w+\s*(.*?)\s*(?=--|$)"),
19
- DTT.STR: compile(r'"(.*?)"', flags=DOTALL),
18
+ DTT.STR: compile(r'"((?:[^\\"]|\\.)*)"', flags=DOTALL),
19
+ DTT.COMMENT: compile(r"::(.*?)$"),
20
20
  DTT.LIST: compile(r"\[(.*?)\]"),
21
21
  DTT.CALL_ARGS: compile(r"\((.*?)\)"),
22
22
  DTT.MENTION: compile(r'<(?:@!?|@&|#)([0-9]+)>'),
@@ -76,23 +76,26 @@ class DshellTokenizer:
76
76
  token = Token(token_type, match.group(1), (line_number, start_match)) # on enregistre son token
77
77
  tokens_par_ligne.append(token)
78
78
 
79
- if token_type in (
80
- DTT.LIST,
81
- DTT.CALL_ARGS): # si c'est un regroupement de donnée, on tokenize ce qu'il contient
82
- result = self.tokenizer([token.value])
83
- token.value = result[0] if len(
84
- result) > 0 else result # gère si la structure de donnée est vide ou non
79
+ if token_type == DTT.STR:
80
+ token.value = token.value.replace(r'\"', '"')
85
81
 
86
- for token_in_list in token.value:
87
- token_in_list.position = (line_number, token_in_list.position[1])
82
+ if token_type in (
83
+ DTT.LIST,
84
+ DTT.CALL_ARGS): # si c'est un regroupement de donnée, on tokenize ce qu'il contient
85
+ result = self.tokenizer([token.value])
86
+ token.value = result[0] if len(
87
+ result) > 0 else result # gère si la structure de donnée est vide ou non
88
88
 
89
- for token_in_line in range(len(tokens_par_ligne)-1):
90
- if tokens_par_ligne[token_in_line].position[1] > start_match:
91
- str_tokens_in_list = tokens_par_ligne[token_in_line:-1]
92
- tokens_par_ligne = tokens_par_ligne[:token_in_line] + [tokens_par_ligne[-1]]
93
- token.value.extend(str_tokens_in_list)
94
- token.value.sort(key=lambda t: t.position[1]) # trie les tokens par rapport à leur position
95
- break
89
+ for token_in_list in token.value:
90
+ token_in_list.position = (line_number, token_in_list.position[1])
91
+
92
+ for token_in_line in range(len(tokens_par_ligne)-1):
93
+ if tokens_par_ligne[token_in_line].position[1] > start_match:
94
+ str_tokens_in_list = tokens_par_ligne[token_in_line:-1]
95
+ tokens_par_ligne = tokens_par_ligne[:token_in_line] + [tokens_par_ligne[-1]]
96
+ token.value.extend(str_tokens_in_list)
97
+ token.value.sort(key=lambda t: t.position[1]) # trie les tokens par rapport à leur position
98
+ break
96
99
 
97
100
  len_match = len(match.group(0)) # longueur du match trouvé
98
101
  ligne = ligne[:start_match] + (MASK_CHARACTER * len_match) + ligne[
@@ -112,6 +115,7 @@ class DshellTokenizer:
112
115
  str]:
113
116
  """
114
117
  Sépare les commandes en une liste en respectant les chaînes entre guillemets.
118
+ Echapper les caractères regroupants avec un antislash (\) pour les inclure dans la chaîne.
115
119
  :param commande: La chaîne de caractères à découper.
116
120
  :param global_split: Le séparateur utilisé (par défaut '\n').
117
121
  :param garder_carractere_regroupant: Si False, enlève les guillemets autour des chaînes.
@@ -121,14 +125,13 @@ class DshellTokenizer:
121
125
 
122
126
  commandes: str = commande.strip()
123
127
  remplacement_temporaire = '[REMPLACER]'
124
- entre_caractere_regroupant = findall(fr'({carractere_regroupant}.*?{carractere_regroupant})', commandes,
125
- flags=DOTALL) # repère les parties entre guillemets et les save
126
-
127
- # current_command_text = [i[1: -1] for i in
128
- # entre_carractere_regroupant.copy()] # enregistre les parties entre guillemets pour cette commande
128
+ pattern_find_regrouped_part = compile(fr'({carractere_regroupant}(?:[^\\{carractere_regroupant}]|\\.)*{carractere_regroupant})', flags=DOTALL)
129
+ entre_caractere_regroupant = findall(pattern_find_regrouped_part, commandes) # repère les parties entre guillemets et les save
129
130
 
130
- res = sub(fr'({carractere_regroupant}.*?{carractere_regroupant})', remplacement_temporaire, commandes,
131
- flags=DOTALL) # remplace les parties entre guillemets
131
+ res = sub(pattern_find_regrouped_part,
132
+ remplacement_temporaire,
133
+ commandes,
134
+ ) # remplace les parties entre guillemets
132
135
 
133
136
  res = res.split(global_split) # split les commandes sans les guillemets
134
137
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dshellInterpreter
3
- Version: 0.2.13.12
3
+ Version: 0.2.13.14
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
@@ -1,25 +1,26 @@
1
1
  Dshell/__init__.py,sha256=pGd94FPy8kVXH_jH566HhApQPhbPfMPnZXzH_0dPWh0,93
2
2
  Dshell/_utils.py,sha256=PJ3fwn8IMqUMnW9oTwfr9v4--rzHIhhLQoVVqjwjoJU,23
3
- Dshell/DISCORD_COMMANDS/__init__.py,sha256=8JPQ-6-s8PkaacmOfQgyczUiLM6rUSceHEJ60oNSis0,173
3
+ Dshell/DISCORD_COMMANDS/__init__.py,sha256=87-YpGU74m-m7AqUQni7PGbw73JRlioQkywW_61Whms,208
4
4
  Dshell/DISCORD_COMMANDS/dshell_channel.py,sha256=qpNe3oE5VyLCmOeCjWlt0rvaSBv2yrkmJgrRswrNOZM,15721
5
+ Dshell/DISCORD_COMMANDS/dshell_interaction.py,sha256=f1DsMeMcI8t_54x-a9mW2pF5RSxNV0hf0ZV-Dt7p_qk,2540
5
6
  Dshell/DISCORD_COMMANDS/dshell_member.py,sha256=5Iw-2dydhYMZOw2nx0svZP9JpZWHOXC0qkL9tClJHtw,8840
6
- Dshell/DISCORD_COMMANDS/dshell_message.py,sha256=uwE3T-Bqduqp3r4FkJ3fXVMEG-pAJGeGA2wkEhjavB0,8964
7
+ Dshell/DISCORD_COMMANDS/dshell_message.py,sha256=VsZk-scVn-OgIKNYFCtWnAf5WowG2ODTa_pNG2ZEZgI,7813
7
8
  Dshell/DISCORD_COMMANDS/dshell_pastbin.py,sha256=TkWFGRRTvhhJgvwkDFx9Fz4UM2UUFwxyq0laMVx0mUk,881
8
9
  Dshell/DISCORD_COMMANDS/dshell_role.py,sha256=t_yRZRD0FKE2gT4dIDIsHz2PSZZztDVEkkqkG_OkNh4,5002
9
10
  Dshell/DISCORD_COMMANDS/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
11
  Dshell/DISCORD_COMMANDS/utils/utils_message.py,sha256=Pn0ljyeCvRfY4tlWHrSbIsxSFZZ5J4lDaeVme3WHp9o,1239
11
12
  Dshell/DISCORD_COMMANDS/utils/utils_thread.py,sha256=tVl4msEwrWHY-0AytI6eY3JSs-eIFUigDSJfK9mT1ww,1457
12
13
  Dshell/_DshellInterpreteur/__init__.py,sha256=xy5-J-R3YmY99JF3NBHTRRLsComFxpjnCA5xacISctU,35
13
- Dshell/_DshellInterpreteur/dshell_interpreter.py,sha256=0PSoLIXDoQLuWGHGaBv3h0sq-ajNnGg57v4WSRaAeCk,27039
14
+ Dshell/_DshellInterpreteur/dshell_interpreter.py,sha256=ukWRqOYU9pmflnlxF8tgOuuU5I0dSXf5t95R4D2AJtc,27650
14
15
  Dshell/_DshellParser/__init__.py,sha256=ONDfhZMvClqP_6tE8SLjp-cf3pXL-auQYnfYRrHZxC4,56
15
16
  Dshell/_DshellParser/ast_nodes.py,sha256=CXUG0rIJNh4jzMCgCcRqmQwU0WQoESQ-5FkuVtZZndM,17717
16
- Dshell/_DshellParser/dshell_parser.py,sha256=73eKwY7iBzBtL6n2IxJcvtSz0xkfE5y1qEffZ2YfXXY,16913
17
+ Dshell/_DshellParser/dshell_parser.py,sha256=bNdqNV3A7VEv-hK9CVSDwFFKgS2oPX_7P5uc7TfK2xA,17559
17
18
  Dshell/_DshellTokenizer/__init__.py,sha256=LIQSRhDx2B9pmPx5ADMwwD0Xr9ybneVLhHH8qrJWw_s,172
18
- Dshell/_DshellTokenizer/dshell_keywords.py,sha256=upwwXwS0OaYhDTAnXSpem2-L4boMEYRncKK315Z5rwI,5744
19
+ Dshell/_DshellTokenizer/dshell_keywords.py,sha256=FY9iByZkNSI4r2M6LCDjjx65awZ_iQyFeOvjYmeK-6A,5860
19
20
  Dshell/_DshellTokenizer/dshell_token_type.py,sha256=gYIb2XN2YcgeRgmar_rBDS5CGmwfmxihu8mOW_d6lbE,1533
20
- Dshell/_DshellTokenizer/dshell_tokenizer.py,sha256=LZGs4Ytuyx9Galazqtz32lS4Mmu9yZya1B7AzFQAQOk,7150
21
- dshellinterpreter-0.2.13.12.dist-info/licenses/LICENSE,sha256=lNgcw1_xb7QENAQi3uHGymaFtbs0RV-ihiCd7AoLQjA,1082
22
- dshellinterpreter-0.2.13.12.dist-info/METADATA,sha256=2uFhzKyF6S3Ojbla85JXOM7XQou4W6TRh6I-owhJ304,1152
23
- dshellinterpreter-0.2.13.12.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
24
- dshellinterpreter-0.2.13.12.dist-info/top_level.txt,sha256=B4CMhtmchGwPQJLuqUy0GhRG-0cUGxKL4GqEbCiB_vE,7
25
- dshellinterpreter-0.2.13.12.dist-info/RECORD,,
21
+ Dshell/_DshellTokenizer/dshell_tokenizer.py,sha256=RrJA2XpcFH2vS6SnRIn5Own_uL5orIDvpq74t8xD3og,7350
22
+ dshellinterpreter-0.2.13.14.dist-info/licenses/LICENSE,sha256=lNgcw1_xb7QENAQi3uHGymaFtbs0RV-ihiCd7AoLQjA,1082
23
+ dshellinterpreter-0.2.13.14.dist-info/METADATA,sha256=8e63xZyweFZwrMI-n2DduWjtScIDHp_WelngI3zoD-A,1152
24
+ dshellinterpreter-0.2.13.14.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
25
+ dshellinterpreter-0.2.13.14.dist-info/top_level.txt,sha256=B4CMhtmchGwPQJLuqUy0GhRG-0cUGxKL4GqEbCiB_vE,7
26
+ dshellinterpreter-0.2.13.14.dist-info/RECORD,,