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

@@ -1,21 +1,43 @@
1
1
  __all__ = [
2
- 'dshell_respond_interaction'
2
+ 'dshell_respond_interaction',
3
+ 'dshell_defer_interaction'
3
4
  ]
4
5
 
5
6
  from types import NoneType
6
- from discord import Interaction, Embed
7
+ from discord import Interaction, Embed, AllowedMentions
7
8
  from pycordViews import EasyModifiedViews
8
9
 
10
+ from .utils.utils_message import utils_autorised_mentions
9
11
 
10
- async def dshell_respond_interaction(ctx: Interaction, content: str = None, delete=None, mention: bool = None, embeds=None, view=None):
12
+ async def dshell_respond_interaction(ctx: Interaction,
13
+ content: str = None,
14
+ delete=None,
15
+ global_mentions: bool = None,
16
+ everyone_mention: bool = True,
17
+ roles_mentions: bool = True,
18
+ users_mentions: bool = True,
19
+ reply_mention: bool = False,
20
+ hide: bool = False,
21
+ embeds=None,
22
+ view=None) -> int:
11
23
  """
12
24
  Responds to a message interaction on Discord
13
25
  """
14
26
 
27
+ if not isinstance(ctx, Interaction):
28
+ raise Exception(f'Respond to an interaction must be used in an interaction context, not {type(ctx)} !')
29
+
15
30
  if delete is not None and not isinstance(delete, (int, float)):
16
31
  raise Exception(f'Delete parameter must be a number (seconds) or None, not {type(delete)} !')
17
32
 
18
- mention_author = mention if mention is not None else False
33
+ if not isinstance(hide, bool):
34
+ raise Exception(f'Hide parameter must be a boolean, not {type(hide)} !')
35
+
36
+ allowed_mentions = utils_autorised_mentions(global_mentions,
37
+ everyone_mention,
38
+ roles_mentions,
39
+ users_mentions,
40
+ reply_mention)
19
41
 
20
42
  from .._DshellParser.ast_nodes import ListNode
21
43
 
@@ -29,14 +51,29 @@ async def dshell_respond_interaction(ctx: Interaction, content: str = None, dele
29
51
  embeds = ListNode([embeds])
30
52
 
31
53
  if not isinstance(view, (EasyModifiedViews, NoneType)):
32
- raise Exception(f'Channel must be an UI or None, not {type(view)} !')
54
+ raise Exception(f'View must be an UI bloc or None, not {type(view)} !')
33
55
 
34
56
  sended_message = await ctx.response.send_message(
35
57
  content=str(content),
36
- ephemeral=not mention_author,
58
+ ephemeral=hide,
59
+ allowed_mentions=allowed_mentions,
37
60
  delete_after=delete,
38
61
  embeds=embeds,
39
62
  view=view)
40
63
 
41
64
  return sended_message.id
42
65
 
66
+ async def dshell_defer_interaction(ctx: Interaction, hide: bool = False) -> bool:
67
+ """
68
+ Defer a message interaction on Discord
69
+ """
70
+
71
+ if not isinstance(ctx, Interaction):
72
+ raise Exception(f'Respond to an interaction must be used in an interaction context, not {type(ctx)} !')
73
+
74
+ if not isinstance(hide, bool):
75
+ raise Exception(f'Hide parameter must be a boolean, not {type(hide)} !')
76
+
77
+ await ctx.response.defer(ephemeral=hide)
78
+
79
+ return True
@@ -1,11 +1,11 @@
1
1
  from re import search
2
2
 
3
- from discord import Embed, Message, Interaction
3
+ from discord import Embed, Message
4
4
  from discord.ext import commands
5
5
 
6
6
  from pycordViews import EasyModifiedViews
7
7
 
8
- from .utils.utils_message import utils_get_message
8
+ from .utils.utils_message import utils_get_message, utils_autorised_mentions
9
9
  from .._utils import NoneType
10
10
 
11
11
  __all__ = [
@@ -23,7 +23,17 @@ __all__ = [
23
23
  ]
24
24
 
25
25
 
26
- async def dshell_send_message(ctx: Message, message=None, delete=None, channel=None, embeds=None, view=None) -> int:
26
+ async def dshell_send_message(ctx: Message,
27
+ message=None,
28
+ delete=None,
29
+ channel=None,
30
+ global_mentions: bool = None,
31
+ everyone_mention: bool = True,
32
+ roles_mentions: bool = True,
33
+ users_mentions: bool = True,
34
+ reply_mention: bool = False,
35
+ embeds=None,
36
+ view=None) -> int:
27
37
  """
28
38
  Sends a message on Discord
29
39
  """
@@ -32,6 +42,7 @@ async def dshell_send_message(ctx: Message, message=None, delete=None, channel=N
32
42
  raise Exception(f'Delete parameter must be a number (seconds) or None, not {type(delete)} !')
33
43
 
34
44
  channel_to_send = ctx.channel if channel is None else ctx.channel.guild.get_channel(channel)
45
+ allowed_mentions = utils_autorised_mentions(global_mentions, everyone_mention, roles_mentions, users_mentions, reply_mention)
35
46
 
36
47
  if channel_to_send is None:
37
48
  raise Exception(f'Channel {channel} not found!')
@@ -53,12 +64,22 @@ async def dshell_send_message(ctx: Message, message=None, delete=None, channel=N
53
64
  sended_message = await channel_to_send.send(message,
54
65
  delete_after=delete,
55
66
  embeds=embeds,
67
+ allowed_mentions=allowed_mentions,
56
68
  view=view)
57
69
 
58
70
  return sended_message.id
59
71
 
60
72
 
61
- async def dshell_respond_message(ctx: Message, message=None, content: str = None, delete=None, mention: bool = None, embeds=None):
73
+ async def dshell_respond_message(ctx: Message,
74
+ message=None,
75
+ content: str = None,
76
+ global_mentions: bool = None,
77
+ everyone_mention: bool = True,
78
+ roles_mentions: bool = True,
79
+ users_mentions: bool = True,
80
+ reply_mention: bool = False,
81
+ delete=None,
82
+ embeds=None):
62
83
  """
63
84
  Responds to a message on Discord
64
85
  """
@@ -66,7 +87,8 @@ async def dshell_respond_message(ctx: Message, message=None, content: str = None
66
87
  raise Exception(f'Delete parameter must be a number (seconds) or None, not {type(delete)} !')
67
88
 
68
89
  respond_message = ctx if message is None else utils_get_message(ctx, message) # builds a reference to the message (even if it doesn't exist)
69
- mention_author = mention if mention is not None else False
90
+ autorised_mentions = utils_autorised_mentions(global_mentions, everyone_mention, roles_mentions, users_mentions, reply_mention)
91
+ mention_author = True if reply_mention else False
70
92
 
71
93
  from .._DshellParser.ast_nodes import ListNode
72
94
 
@@ -82,6 +104,7 @@ async def dshell_respond_message(ctx: Message, message=None, content: str = None
82
104
  sended_message = await respond_message.reply(
83
105
  content=str(content),
84
106
  mention_author=mention_author,
107
+ allowed_mentions=autorised_mentions,
85
108
  delete_after=delete,
86
109
  embeds=embeds)
87
110
 
@@ -119,7 +142,7 @@ async def dshell_purge_message(ctx: Message, message_number: int, channel=None,
119
142
  await purge_channel.purge(limit=message_number, reason=reason)
120
143
 
121
144
 
122
- async def dshell_edit_message(ctx: Message, message, new_content=None, embeds=None):
145
+ async def dshell_edit_message(ctx: Message, message, new_content=None, embeds=None, view=None) -> int:
123
146
  """
124
147
  Edits a message
125
148
  """
@@ -130,18 +153,21 @@ async def dshell_edit_message(ctx: Message, message, new_content=None, embeds=No
130
153
  if not isinstance(embeds, (ListNode, Embed, NoneType)):
131
154
  raise Exception(f'Embeds must be a list of Embed objects or a single Embed object, not {type(embeds)} !')
132
155
 
156
+ if not isinstance(view, (EasyModifiedViews, NoneType)):
157
+ raise Exception(f'View must be an UI bloc or None, not {type(view)} !')
158
+
133
159
  if embeds is None:
134
160
  embeds = ListNode([])
135
161
 
136
162
  elif isinstance(embeds, Embed):
137
163
  embeds = ListNode([embeds])
138
164
 
139
- await edit_message.edit(content=new_content, embeds=embeds)
165
+ await edit_message.edit(content=new_content, embeds=embeds, view=view)
140
166
 
141
167
  return edit_message.id
142
168
 
143
169
 
144
- async def dshell_get_hystory_messages(ctx: Message, channel=None, limit=None):
170
+ async def dshell_get_hystory_messages(ctx: Message, channel=None, limit=None) -> "ListNode":
145
171
  """
146
172
  Searches for messages matching a regex in a channel
147
173
  """
@@ -1,4 +1,4 @@
1
- from discord import Message, PartialMessage
1
+ from discord import Message, PartialMessage, AllowedMentions
2
2
  from typing import Union
3
3
  from re import search
4
4
 
@@ -26,3 +26,43 @@ def utils_get_message(ctx: Message, message: Union[int, str]) -> PartialMessage:
26
26
  return ctx.guild.get_channel(channel_id).get_partial_message(message_id)
27
27
 
28
28
  raise Exception(f"Message must be an integer or a string, not {type(message)} !")
29
+
30
+
31
+ def utils_autorised_mentions(global_mentions: bool = None,
32
+ everyone_mention: bool = True,
33
+ roles_mentions: bool = True,
34
+ users_mentions: bool = True,
35
+ reply_mention: bool = False) -> Union[bool, 'AllowedMentions']:
36
+ """
37
+ Returns the AllowedMentions object based on the provided parameters.
38
+ If global_mentions is set to True or False, it overrides all other parameters.
39
+ """
40
+
41
+ from discord import AllowedMentions
42
+
43
+ if not isinstance(global_mentions, (type(None), bool)):
44
+ raise Exception(f'Mention parameter must be a boolean or None, not {type(global_mentions)} !')
45
+
46
+ if not isinstance(everyone_mention, bool):
47
+ raise Exception(f'Everyone mention parameter must be a boolean, not {type(everyone_mention)} !')
48
+
49
+ if not isinstance(roles_mentions, bool):
50
+ raise Exception(f'Roles mention parameter must be a boolean, not {type(roles_mentions)} !')
51
+
52
+ if not isinstance(users_mentions, bool):
53
+ raise Exception(f'Users mention parameter must be a boolean, not {type(users_mentions)} !')
54
+
55
+ if not isinstance(reply_mention, bool):
56
+ raise Exception(f'Reply mention parameter must be a boolean, not {type(reply_mention)} !')
57
+
58
+ if global_mentions is True:
59
+ return AllowedMentions.all()
60
+
61
+ elif global_mentions is False:
62
+ return AllowedMentions.none()
63
+
64
+ else:
65
+ return AllowedMentions(everyone=everyone_mention,
66
+ roles=roles_mentions,
67
+ users=users_mentions,
68
+ replied_user=reply_mention)
@@ -40,22 +40,34 @@ class DshellInterpreteur:
40
40
  message = ctx.message if isinstance(ctx, Interaction) else ctx
41
41
  self.env: dict[str, Any] = {
42
42
  '__ret__': None, # environment variables, '__ret__' is used to store the return value of commands
43
- '__guild__': message.channel.guild.name,
44
- '__channel__': message.channel.name,
45
- '__author__': message.author.name,
43
+
44
+ '__author__': message.author.id,
46
45
  '__author_display_name__': message.author.display_name,
47
46
  '__author_avatar__': message.author.display_avatar.url if message.author.display_avatar else None,
48
47
  '__author_discriminator__': message.author.discriminator,
49
48
  '__author_bot__': message.author.bot,
50
49
  '__author_nick__': message.author.nick if hasattr(message.author, 'nick') else None,
51
50
  '__author_id__': message.author.id,
51
+
52
52
  '__message__': message.content,
53
+ '__message_content__': message.content,
53
54
  '__message_id__': message.id,
55
+ '__message_url__': message.jump_url if hasattr(message, 'jump_url') else None,
56
+
57
+ '__channel__': message.channel.id,
54
58
  '__channel_name__': message.channel.name,
55
59
  '__channel_type__': message.channel.type.name if hasattr(message.channel, 'type') else None,
56
60
  '__channel_id__': message.channel.id,
57
61
  '__private_channel__': isinstance(message.channel, PrivateChannel),
58
- } 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
59
71
  self.vars = vars if vars is not None else ''
60
72
  self.ctx: context = ctx
61
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}")
@@ -31,11 +31,13 @@ dshell_commands: dict[str, Callable] = {
31
31
  "sm": dshell_send_message, # send message
32
32
  "spm": dshell_send_private_message, # send private message
33
33
  "srm": dshell_respond_message, # respond to a message
34
- "sri": dshell_respond_interaction, # respond to an interaction
35
34
  "dm": dshell_delete_message,
36
35
  "pm": dshell_purge_message,
37
36
  "em": dshell_edit_message, # edit message
38
37
 
38
+ "sri": dshell_respond_interaction, # respond to an interaction
39
+ "di": dshell_defer_interaction, # defer an interaction
40
+
39
41
  "cc": dshell_create_text_channel, # create channel
40
42
  "cvc": dshell_create_voice_channel, # create voice channel
41
43
  "dc": dshell_delete_channel, # delete channel
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dshellInterpreter
3
- Version: 0.2.13.13
3
+ Version: 0.2.13.15
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
@@ -2,25 +2,25 @@ Dshell/__init__.py,sha256=pGd94FPy8kVXH_jH566HhApQPhbPfMPnZXzH_0dPWh0,93
2
2
  Dshell/_utils.py,sha256=PJ3fwn8IMqUMnW9oTwfr9v4--rzHIhhLQoVVqjwjoJU,23
3
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=MH0E7cxaZFoaFxZnKNrbv9vwr0ARUsuoy6ECyq2FnFA,1499
5
+ Dshell/DISCORD_COMMANDS/dshell_interaction.py,sha256=Gac3J9sCcPRHApIgSoS5MRAMJ0Hd7I-YywVQI0s26p0,3229
6
6
  Dshell/DISCORD_COMMANDS/dshell_member.py,sha256=5Iw-2dydhYMZOw2nx0svZP9JpZWHOXC0qkL9tClJHtw,8840
7
- Dshell/DISCORD_COMMANDS/dshell_message.py,sha256=9bVEgQlAAuERl5Q9hV9sD8FWLRLPSwEsct_Qym2Dh3E,7597
7
+ Dshell/DISCORD_COMMANDS/dshell_message.py,sha256=zcWl6Y1W31h9MTHS-j9tLDwcrRiE_wGOu78zu2k0y9I,9101
8
8
  Dshell/DISCORD_COMMANDS/dshell_pastbin.py,sha256=TkWFGRRTvhhJgvwkDFx9Fz4UM2UUFwxyq0laMVx0mUk,881
9
9
  Dshell/DISCORD_COMMANDS/dshell_role.py,sha256=t_yRZRD0FKE2gT4dIDIsHz2PSZZztDVEkkqkG_OkNh4,5002
10
10
  Dshell/DISCORD_COMMANDS/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
- Dshell/DISCORD_COMMANDS/utils/utils_message.py,sha256=Pn0ljyeCvRfY4tlWHrSbIsxSFZZ5J4lDaeVme3WHp9o,1239
11
+ Dshell/DISCORD_COMMANDS/utils/utils_message.py,sha256=cQvJ15f49ddOjybARwkJKNFe3ITYQciF-pZHERFPkr0,2964
12
12
  Dshell/DISCORD_COMMANDS/utils/utils_thread.py,sha256=tVl4msEwrWHY-0AytI6eY3JSs-eIFUigDSJfK9mT1ww,1457
13
13
  Dshell/_DshellInterpreteur/__init__.py,sha256=xy5-J-R3YmY99JF3NBHTRRLsComFxpjnCA5xacISctU,35
14
- Dshell/_DshellInterpreteur/dshell_interpreter.py,sha256=b4_qgOaCfF6U3Pk_LO0yhXm3TY1HZjvfJhxUNUfB24E,27013
14
+ Dshell/_DshellInterpreteur/dshell_interpreter.py,sha256=ukWRqOYU9pmflnlxF8tgOuuU5I0dSXf5t95R4D2AJtc,27650
15
15
  Dshell/_DshellParser/__init__.py,sha256=ONDfhZMvClqP_6tE8SLjp-cf3pXL-auQYnfYRrHZxC4,56
16
16
  Dshell/_DshellParser/ast_nodes.py,sha256=CXUG0rIJNh4jzMCgCcRqmQwU0WQoESQ-5FkuVtZZndM,17717
17
- Dshell/_DshellParser/dshell_parser.py,sha256=73eKwY7iBzBtL6n2IxJcvtSz0xkfE5y1qEffZ2YfXXY,16913
17
+ Dshell/_DshellParser/dshell_parser.py,sha256=bNdqNV3A7VEv-hK9CVSDwFFKgS2oPX_7P5uc7TfK2xA,17559
18
18
  Dshell/_DshellTokenizer/__init__.py,sha256=LIQSRhDx2B9pmPx5ADMwwD0Xr9ybneVLhHH8qrJWw_s,172
19
- Dshell/_DshellTokenizer/dshell_keywords.py,sha256=vK7O84tlpLe9qXUsCqKOP3NozXZzQOdPwthD7PD7AIA,5797
19
+ Dshell/_DshellTokenizer/dshell_keywords.py,sha256=FY9iByZkNSI4r2M6LCDjjx65awZ_iQyFeOvjYmeK-6A,5860
20
20
  Dshell/_DshellTokenizer/dshell_token_type.py,sha256=gYIb2XN2YcgeRgmar_rBDS5CGmwfmxihu8mOW_d6lbE,1533
21
21
  Dshell/_DshellTokenizer/dshell_tokenizer.py,sha256=RrJA2XpcFH2vS6SnRIn5Own_uL5orIDvpq74t8xD3og,7350
22
- dshellinterpreter-0.2.13.13.dist-info/licenses/LICENSE,sha256=lNgcw1_xb7QENAQi3uHGymaFtbs0RV-ihiCd7AoLQjA,1082
23
- dshellinterpreter-0.2.13.13.dist-info/METADATA,sha256=RcYSGYACjZQY21bDRa-4wdXd2oaSKFtADaYRncEfIT8,1152
24
- dshellinterpreter-0.2.13.13.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
25
- dshellinterpreter-0.2.13.13.dist-info/top_level.txt,sha256=B4CMhtmchGwPQJLuqUy0GhRG-0cUGxKL4GqEbCiB_vE,7
26
- dshellinterpreter-0.2.13.13.dist-info/RECORD,,
22
+ dshellinterpreter-0.2.13.15.dist-info/licenses/LICENSE,sha256=lNgcw1_xb7QENAQi3uHGymaFtbs0RV-ihiCd7AoLQjA,1082
23
+ dshellinterpreter-0.2.13.15.dist-info/METADATA,sha256=ly2oZrfOh1aGwRLfDgpQQRry_UBjK7l3EUa1SbTzgyc,1152
24
+ dshellinterpreter-0.2.13.15.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
25
+ dshellinterpreter-0.2.13.15.dist-info/top_level.txt,sha256=B4CMhtmchGwPQJLuqUy0GhRG-0cUGxKL4GqEbCiB_vE,7
26
+ dshellinterpreter-0.2.13.15.dist-info/RECORD,,