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

@@ -2,9 +2,11 @@ from asyncio import sleep
2
2
  from re import search
3
3
  from typing import Union
4
4
 
5
- from discord import MISSING, PermissionOverwrite, Member, Role, Message, Thread
5
+ from discord import MISSING, PermissionOverwrite, Member, Role, Message
6
6
  from discord.utils import _MissingSentinel
7
- from discord import NotFound
7
+
8
+ from .utils.utils_message import utils_get_message
9
+ from .utils.utils_thread import utils_get_thread
8
10
 
9
11
  __all__ = [
10
12
  'dshell_get_channel',
@@ -22,60 +24,6 @@ __all__ = [
22
24
  'dshell_edit_thread'
23
25
  ]
24
26
 
25
- async def utils_get_message(ctx: Message, message: Union[int, str]) -> Message:
26
- """
27
- Returns the message object of the specified message ID or link.
28
- Message is only available in the same server as the command and in the same channel.
29
- If the message is a link, it must be in the format: https://discord.com/channels/{guild_id}/{channel_id}/{message_id}
30
- """
31
-
32
- if isinstance(message, int):
33
- return await ctx.channel.fetch_message(message)
34
-
35
- elif isinstance(message, str):
36
- match = search(r'https://discord\.com/channels/(\d+)/(\d+)/(\d+)', message)
37
- if not match:
38
- raise Exception("Invalid message link format. Use a valid Discord message link.")
39
- guild_id = int(match.group(1))
40
- channel_id = int(match.group(2))
41
- message_id = int(match.group(3))
42
-
43
- if guild_id != ctx.guild.id:
44
- raise Exception("The message must be from the same server as the command !")
45
-
46
- return await ctx.guild.get_channel(channel_id).fetch_message(message_id)
47
-
48
- raise Exception(f"Message must be an integer or a string, not {type(message)} !")
49
-
50
- async def utils_get_thread(ctx: Message, thread: Union[int, str]) -> Thread:
51
- """
52
- Returns the thread object of the specified thread ID or link.
53
- Thread is only available in the same server as the command and in the same channel.
54
- If the thread is a link, it must be in the format: https://discord.com/channels/{guild_id}/{channel_id}/{message_id}
55
- """
56
-
57
- if isinstance(thread, int):
58
- return ctx.channel.get_thread(thread)
59
-
60
- elif isinstance(thread, str):
61
- match = search(r'https://discord\.com/channels/(\d+)/(\d+)(/\d+)?', thread)
62
- if not match:
63
- raise Exception("Invalid thread link format. Use a valid Discord thread link.")
64
- guild_id = int(match.group(1))
65
- message_id = int(match.group(2))
66
- channel_id = ctx.channel.id if len(match.groups()) == 3 else ctx.channel.id
67
-
68
- if guild_id != ctx.guild.id:
69
- raise Exception("The thread must be from the same server as the command !")
70
-
71
- try:
72
- c = await ctx.guild.get_channel(channel_id).fetch_message(message_id)
73
- return c.thread
74
- except NotFound:
75
- raise Exception(f"Thread with ID {message_id} not found in channel {channel_id} !")
76
-
77
- raise Exception(f"Thread must be an integer or a string, not {type(thread)} !")
78
-
79
27
 
80
28
  async def dshell_get_channel(ctx: Message, name):
81
29
  """
@@ -338,7 +286,7 @@ async def dshell_create_thread_message(ctx: Message,
338
286
  if message is None:
339
287
  message = ctx.id
340
288
 
341
- message = await utils_get_message(ctx, message)
289
+ message = utils_get_message(ctx, message)
342
290
 
343
291
 
344
292
  if not isinstance(name, str):
@@ -1,8 +1,9 @@
1
1
  from datetime import timedelta, datetime, UTC
2
2
 
3
- from discord import MISSING, Message, Member, Permissions, Role
3
+ from discord import MISSING, Message, Member, Permissions, Role, Embed
4
4
 
5
5
  __all__ = [
6
+ "dshell_send_private_message",
6
7
  "dshell_ban_member",
7
8
  "dshell_unban_member",
8
9
  "dshell_kick_member",
@@ -16,6 +17,35 @@ __all__ = [
16
17
  "dshell_remove_member_roles"
17
18
  ]
18
19
 
20
+ async def dshell_send_private_message(ctx: Message, message: str = None, member: int = None, delete: int = None, embeds = None, ):
21
+ """
22
+ Sends a private message to a member.
23
+ If member is None, sends the message to the author of the command.
24
+ If delete is specified, deletes the message after the specified time in seconds.
25
+ """
26
+ if delete is not None and not isinstance(delete, (int, float)):
27
+ raise Exception(f'Delete parameter must be a number (seconds) or None, not {type(delete)} !')
28
+
29
+ member_to_send = ctx.author if member is None else ctx.channel.guild.get_member(member)
30
+
31
+ if member_to_send is None:
32
+ raise Exception(f'Member {member} not found!')
33
+
34
+ from .._DshellParser.ast_nodes import ListNode
35
+
36
+ if embeds is None:
37
+ embeds = ListNode([])
38
+
39
+ elif isinstance(embeds, Embed):
40
+ embeds = ListNode([embeds])
41
+
42
+ else:
43
+ raise Exception(f'Embeds must be a list of Embed objects or a single Embed object, not {type(embeds)} !')
44
+
45
+ sended_message = await member_to_send.send(message, delete_after=delete, embeds=embeds)
46
+
47
+ return sended_message.id
48
+
19
49
 
20
50
  async def dshell_ban_member(ctx: Message, member: int, reason: str = MISSING):
21
51
  """
@@ -3,8 +3,11 @@ from re import search
3
3
  from discord import Embed, Message, NotFound
4
4
  from discord.ext import commands
5
5
 
6
+ from .utils.utils_message import utils_get_message
7
+
6
8
  __all__ = [
7
9
  'dshell_send_message',
10
+ 'dshell_respond_message',
8
11
  'dshell_delete_message',
9
12
  'dshell_purge_message',
10
13
  'dshell_edit_message',
@@ -47,13 +50,41 @@ async def dshell_send_message(ctx: Message, message=None, delete=None, channel=N
47
50
  return sended_message.id
48
51
 
49
52
 
53
+ async def dshell_respond_message(ctx: Message, message=None, content: str = None, delete=None, mention: bool = None, embeds=None):
54
+ """
55
+ Responds to a message on Discord
56
+ """
57
+ if delete is not None and not isinstance(delete, (int, float)):
58
+ raise Exception(f'Delete parameter must be a number (seconds) or None, not {type(delete)} !')
59
+
60
+ 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)
61
+ mention_author = mention if mention is not None else False
62
+
63
+ from .._DshellParser.ast_nodes import ListNode
64
+
65
+ if embeds is None:
66
+ embeds = ListNode([])
67
+
68
+ elif isinstance(embeds, Embed):
69
+ embeds = ListNode([embeds])
70
+
71
+ else:
72
+ raise Exception(f'Embeds must be a list of Embed objects or a single Embed object, not {type(embeds)} !')
73
+
74
+ sended_message = await ctx.reply(reference=respond_message,
75
+ content=content,
76
+ mention_author=mention_author,
77
+ delete_after=delete,
78
+ embeds=embeds)
79
+
80
+ return sended_message.id
81
+
50
82
  async def dshell_delete_message(ctx: Message, message=None, reason=None, delay=0):
51
83
  """
52
84
  Deletes a message
53
85
  """
54
86
 
55
- delete_message = ctx if message is None else ctx.channel.get_partial_message(
56
- message) # builds a reference to the message (even if it doesn't exist)
87
+ delete_message = ctx if message is None else utils_get_message(ctx, message)
57
88
 
58
89
  if not isinstance(delay, int):
59
90
  raise Exception(f'Delete delay must be an integer, not {type(delay)} !')
@@ -64,7 +95,7 @@ async def dshell_delete_message(ctx: Message, message=None, reason=None, delay=0
64
95
  await delete_message.delete(delay=delay, reason=reason)
65
96
 
66
97
 
67
- async def dshell_purge_message(ctx: Message, message_number, channel=None, reason=None):
98
+ async def dshell_purge_message(ctx: Message, message_number: int, channel=None, reason=None):
68
99
  """
69
100
  Purges messages from a channel
70
101
  """
@@ -84,8 +115,7 @@ async def dshell_edit_message(ctx: Message, message, new_content=None, embeds=No
84
115
  """
85
116
  Edits a message
86
117
  """
87
- edit_message = ctx.channel.get_partial_message(
88
- message) # builds a reference to the message (even if it doesn't exist)
118
+ edit_message = utils_get_message(ctx, message)
89
119
 
90
120
  if embeds is None:
91
121
  embeds = []
@@ -141,8 +171,7 @@ async def dshell_add_reactions(ctx: Message, reactions, message=None):
141
171
  """
142
172
  Adds reactions to a message
143
173
  """
144
- message = ctx if message is None else ctx.channel.get_partial_message(
145
- message) # builds a reference to the message (even if it doesn't exist)
174
+ message = ctx if message is None else utils_get_message(ctx, message)
146
175
 
147
176
  if isinstance(reactions, str):
148
177
  reactions = (reactions,)
@@ -157,8 +186,7 @@ async def dshell_remove_reactions(ctx: Message, reactions, message=None):
157
186
  """
158
187
  Removes reactions from a message
159
188
  """
160
- message = ctx if message is None else ctx.channel.get_partial_message(
161
- message) # builds a reference to the message (even if it doesn't exist)
189
+ message = ctx if message is None else utils_get_message(ctx, message)
162
190
 
163
191
  if isinstance(reactions, str):
164
192
  reactions = [reactions]
@@ -172,29 +200,21 @@ async def dshell_clear_message_reactions(ctx: Message, message):
172
200
  """
173
201
  Clear all reaction on the target message
174
202
  """
175
- if not isinstance(message, int):
176
- raise Exception(f'Message must be integer, not {type(message)}')
203
+ message = ctx if message is None else utils_get_message(ctx, message)
177
204
 
178
- target_message = await ctx.channel.fetch_message(message)
179
-
180
- if target_message is None:
205
+ if message is None:
181
206
  raise Exception(f'Message not found !')
182
207
 
183
- await target_message.clear_reactions()
208
+ await message.clear_reactions()
184
209
 
185
210
  async def dshell_clear_one_reactions(ctx: Message, message, emoji):
186
211
  """
187
212
  Clear one emoji on the target message
188
213
  """
189
- if not isinstance(message, int):
190
- raise Exception(f'Message must be integer, not {type(message)}')
191
214
 
192
215
  if not isinstance(emoji, str):
193
216
  raise Exception(f'Emoji must be string, not {type(emoji)}')
194
217
 
195
- try:
196
- target_message = await ctx.channel.fetch_message(message)
197
- except NotFound:
198
- raise Exception(f'Message not found !')
218
+ target_message = ctx if message is None else utils_get_message(ctx, message)
199
219
 
200
220
  await target_message.clear_reaction(emoji)
@@ -1,5 +1,6 @@
1
1
  from discord import MISSING, Message, PermissionOverwrite
2
2
  from discord.utils import _MissingSentinel
3
+ from typing import Union
3
4
  from .._utils import NoneType
4
5
 
5
6
  __all__ = [
@@ -56,7 +57,7 @@ async def dshell_delete_roles(ctx: Message, roles, reason=None):
56
57
  Delete the role on the server
57
58
  """
58
59
  from .._DshellInterpreteur.dshell_interpreter import ListNode
59
- roles: int | ListNode
60
+ roles: Union[int, ListNode]
60
61
  if not isinstance(roles, (int, ListNode)):
61
62
  raise Exception(f"Role must be a int, role mention or NodeList of both, not {type(roles)} !")
62
63
 
@@ -28,6 +28,8 @@ dshell_commands: dict[str, Callable] = {
28
28
  "gp": dshell_get_pastbin, # get pastbin
29
29
 
30
30
  "sm": dshell_send_message, # send message
31
+ "spm": dshell_send_private_message, # send private message
32
+ "srm": dshell_respond_message, # respond to a message
31
33
  "dm": dshell_delete_message,
32
34
  "pm": dshell_purge_message,
33
35
  "em": dshell_edit_message, # edit message
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dshellInterpreter
3
- Version: 0.2.9
3
+ Version: 0.2.9.2
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,22 +1,22 @@
1
1
  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=_oo_aMEju4gZg-MIbF8bKMVM6CWAF0AO9DxAlemaXMw,149
4
- Dshell/DISCORD_COMMANDS/dshell_channel.py,sha256=kjSTJnTTXHprCURESlO_62jv3Yu832lUELJi47PyWdo,18538
5
- Dshell/DISCORD_COMMANDS/dshell_member.py,sha256=L3Ud4nza_55n9R02kfL-iNK9ybBczx6SDkccUTWxv3s,7646
6
- Dshell/DISCORD_COMMANDS/dshell_message.py,sha256=SvX9I4nYMWm8ACE56QJBM5yEiZoXIKbTLkIOyrENd5o,6253
4
+ Dshell/DISCORD_COMMANDS/dshell_channel.py,sha256=__vRngQD0USGBuJIuvHQckrtbhbufn5etaqXgNS90IA,16124
5
+ Dshell/DISCORD_COMMANDS/dshell_member.py,sha256=5Iw-2dydhYMZOw2nx0svZP9JpZWHOXC0qkL9tClJHtw,8840
6
+ Dshell/DISCORD_COMMANDS/dshell_message.py,sha256=KoR5hLQiGdkmBjMUJvdItsGximA0mUJ2MmNGV_1-1b8,6942
7
7
  Dshell/DISCORD_COMMANDS/dshell_pastbin.py,sha256=TkWFGRRTvhhJgvwkDFx9Fz4UM2UUFwxyq0laMVx0mUk,881
8
- Dshell/DISCORD_COMMANDS/dshell_role.py,sha256=fotsYWGHebgIx157q-zRbcCd90Y7jIuKCZ8udQoEzSU,4970
8
+ Dshell/DISCORD_COMMANDS/dshell_role.py,sha256=t_yRZRD0FKE2gT4dIDIsHz2PSZZztDVEkkqkG_OkNh4,5002
9
9
  Dshell/_DshellInterpreteur/__init__.py,sha256=xy5-J-R3YmY99JF3NBHTRRLsComFxpjnCA5xacISctU,35
10
10
  Dshell/_DshellInterpreteur/dshell_interpreter.py,sha256=sYQ9qIVjRedwkfITEeVAFN0RdHjiY7RGO6z0j4D7eno,23072
11
11
  Dshell/_DshellParser/__init__.py,sha256=ONDfhZMvClqP_6tE8SLjp-cf3pXL-auQYnfYRrHZxC4,56
12
12
  Dshell/_DshellParser/ast_nodes.py,sha256=heOMQzAchQ8UroQaMSfU_6SYEXw-nme0jGcoVkCXPUs,15284
13
13
  Dshell/_DshellParser/dshell_parser.py,sha256=RxS5GgmTel10pH9HII0X_8XZnVyIQGd9ThZZcZDpEqc,15545
14
14
  Dshell/_DshellTokenizer/__init__.py,sha256=LIQSRhDx2B9pmPx5ADMwwD0Xr9ybneVLhHH8qrJWw_s,172
15
- Dshell/_DshellTokenizer/dshell_keywords.py,sha256=V4WU7PBvP9o7qxbE0Xsd8RmT_jxVRzZa1SOr2JeTyIg,5517
15
+ Dshell/_DshellTokenizer/dshell_keywords.py,sha256=yBTXKBCb7NZa-DGDeeyIZrl_CS1Y4WCmwshUdBHQhlo,5642
16
16
  Dshell/_DshellTokenizer/dshell_token_type.py,sha256=gYIb2XN2YcgeRgmar_rBDS5CGmwfmxihu8mOW_d6lbE,1533
17
17
  Dshell/_DshellTokenizer/dshell_tokenizer.py,sha256=LZGs4Ytuyx9Galazqtz32lS4Mmu9yZya1B7AzFQAQOk,7150
18
- dshellinterpreter-0.2.9.dist-info/licenses/LICENSE,sha256=lNgcw1_xb7QENAQi3uHGymaFtbs0RV-ihiCd7AoLQjA,1082
19
- dshellinterpreter-0.2.9.dist-info/METADATA,sha256=IafKmA2w0eQvRLUnEydFgseeujbmQAfKjp7CJSc0WFk,1120
20
- dshellinterpreter-0.2.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
21
- dshellinterpreter-0.2.9.dist-info/top_level.txt,sha256=B4CMhtmchGwPQJLuqUy0GhRG-0cUGxKL4GqEbCiB_vE,7
22
- dshellinterpreter-0.2.9.dist-info/RECORD,,
18
+ dshellinterpreter-0.2.9.2.dist-info/licenses/LICENSE,sha256=lNgcw1_xb7QENAQi3uHGymaFtbs0RV-ihiCd7AoLQjA,1082
19
+ dshellinterpreter-0.2.9.2.dist-info/METADATA,sha256=8yS0LBpjnf_2Md5wd9uXk-Cs5cfNJ3G2TQJWB9SWALQ,1122
20
+ dshellinterpreter-0.2.9.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
21
+ dshellinterpreter-0.2.9.2.dist-info/top_level.txt,sha256=B4CMhtmchGwPQJLuqUy0GhRG-0cUGxKL4GqEbCiB_vE,7
22
+ dshellinterpreter-0.2.9.2.dist-info/RECORD,,