dshellInterpreter 0.2.19.2__py3-none-any.whl → 0.2.19.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.

@@ -6,6 +6,7 @@ from discord.ext import commands
6
6
  from pycordViews import EasyModifiedViews
7
7
 
8
8
  from .utils.utils_message import utils_get_message, utils_autorised_mentions
9
+ from .._DshellInterpreteur.cached_messages import dshell_cached_messages
9
10
  from .._utils import NoneType
10
11
 
11
12
  __all__ = [
@@ -167,7 +168,9 @@ async def dshell_edit_message(ctx: Message, message, new_content=None, embeds=No
167
168
  return edit_message.id
168
169
 
169
170
 
170
- async def dshell_get_history_messages(ctx: Message, channel=None, limit=None) -> "ListNode":
171
+ async def dshell_get_history_messages(ctx: Message,
172
+ channel=None,
173
+ limit=None) -> "ListNode":
171
174
  """
172
175
  Searches for messages matching a regex in a channel
173
176
  """
@@ -182,13 +185,16 @@ async def dshell_get_history_messages(ctx: Message, channel=None, limit=None) ->
182
185
 
183
186
  from .._DshellParser.ast_nodes import ListNode
184
187
 
188
+ cached_messages = dshell_cached_messages.get()
185
189
  messages = ListNode([])
186
190
  async for message in search_channel.history(limit=limit):
187
- messages.add(message.id)
191
+ message_id = message.id
192
+ messages.add(message_id)
193
+ cached_messages[message_id] = message
188
194
 
189
195
  if not messages:
190
196
  raise commands.CommandError(f"No messages in {search_channel.mention}.")
191
-
197
+ dshell_cached_messages.set(cached_messages)
192
198
  return messages
193
199
 
194
200
 
@@ -2,3 +2,7 @@ from .utils_thread import *
2
2
  from .utils_message import *
3
3
  from .utils_list import *
4
4
  from .utils_global import *
5
+ from .utils_permissions import *
6
+ from .utils_member import *
7
+ from .utils_string import *
8
+ from .utils_list import *
@@ -1,16 +1,24 @@
1
1
  from discord import Message, PartialMessage, AllowedMentions
2
- from typing import Union
2
+ from typing import Union, Optional
3
3
  from re import search
4
4
 
5
- def utils_get_message(ctx: Message, message: Union[int, str]) -> PartialMessage:
5
+ from ..._DshellInterpreteur.cached_messages import dshell_cached_messages
6
+
7
+ def utils_get_message(ctx: Message, message: Union[int, str]) -> Union[PartialMessage]:
6
8
  """
7
9
  Returns the message object of the specified message ID or link.
8
10
  Message is only available in the same server as the command and in the same channel.
9
11
  If the message is a link, it must be in the format: https://discord.com/channels/{guild_id}/{channel_id}/{message_id}
10
12
  """
13
+ cached_messages = dshell_cached_messages.get()
11
14
 
12
15
  if isinstance(message, int):
13
- return ctx.channel.get_partial_message(message)
16
+ if message in cached_messages:
17
+ return cached_messages[message]
18
+
19
+ cached_messages[message] = ctx.channel.get_partial_message(message)
20
+ dshell_cached_messages.set(cached_messages)
21
+ return cached_messages[message]
14
22
 
15
23
  elif isinstance(message, str):
16
24
  match = search(r'https://discord\.com/channels/(\d+)/(\d+)/(\d+)', message)
@@ -23,7 +31,9 @@ def utils_get_message(ctx: Message, message: Union[int, str]) -> PartialMessage:
23
31
  if guild_id != ctx.guild.id:
24
32
  raise Exception("The message must be from the same server as the command !")
25
33
 
26
- return ctx.guild.get_channel(channel_id).get_partial_message(message_id)
34
+ cached_messages[message_id] = ctx.guild.get_channel(channel_id).get_partial_message(message_id)
35
+ dshell_cached_messages.set(cached_messages)
36
+ return cached_messages[message_id]
27
37
 
28
38
  raise Exception(f"Message must be an integer or a string, not {type(message)} !")
29
39
 
@@ -40,7 +50,7 @@ def utils_autorised_mentions(global_mentions: bool = None,
40
50
 
41
51
  from discord import AllowedMentions
42
52
 
43
- if not isinstance(global_mentions, (type(None), bool)):
53
+ if global_mentions is not None and not isinstance(global_mentions, bool):
44
54
  raise Exception(f'Mention parameter must be a boolean or None, not {type(global_mentions)} !')
45
55
 
46
56
  if not isinstance(everyone_mention, bool):
@@ -65,4 +75,22 @@ def utils_autorised_mentions(global_mentions: bool = None,
65
75
  return AllowedMentions(everyone=everyone_mention,
66
76
  roles=roles_mentions,
67
77
  users=users_mentions,
68
- replied_user=reply_mention)
78
+ replied_user=reply_mention)
79
+
80
+ async def utils_get_author_id_message(ctx: Message, message: Optional[int] = None):
81
+ """
82
+ Return author ID of the message given (or ctx if message=None)
83
+ :param ctx:
84
+ :param message: message ID
85
+ :return:
86
+ """
87
+ if message is not None and not isinstance(message, int):
88
+ raise Exception(f'Message parameter must be an integer or None, not {type(message)} !')
89
+
90
+ target_message = ctx
91
+ if message is not None:
92
+ try:
93
+ target_message = await utils_get_message(ctx, message).fetch()
94
+ except:
95
+ raise Exception(f"[message_author] Author ID message to get is not found !")
96
+ return target_message.author.id
@@ -1,11 +1,9 @@
1
- from typing import Union, TYPE_CHECKING
1
+ from typing import Union
2
2
  from discord import Guild, Member, Role, Permissions, PermissionOverwrite
3
3
 
4
- from ..._DshellParser.ast_nodes import ListNode
5
4
  from .utils_global import utils_what_discord_type_is, DiscordType
6
5
 
7
6
  class DshellPermissions:
8
-
9
7
  def __init__(self, target: dict[str, list[int]]):
10
8
  """
11
9
  Creates a Dshell permissions object.
@@ -13,7 +11,7 @@ class DshellPermissions:
13
11
  Expected parameters: “allow”, “deny”, ‘members’, “roles”.
14
12
  For “members” and “roles”, values must be ID ListNodes.
15
13
  """
16
- self.target: dict[str, Union[ListNode, int]] = target
14
+ self.target: dict[str, Union["ListNode", int]] = target
17
15
 
18
16
  @staticmethod
19
17
  def get_member(guild, member_id: int) -> Member:
@@ -46,6 +44,7 @@ class DshellPermissions:
46
44
  :param guild: The Discord server
47
45
  :return: A dictionary of PermissionOverwrite objects with members and roles as keys
48
46
  """
47
+ from ..._DshellParser.ast_nodes import ListNode
49
48
  permissions: dict[Union[Member, Role, None], PermissionOverwrite] = {}
50
49
  target_keys = self.target.keys()
51
50
 
@@ -1,2 +1,3 @@
1
1
  from .dshell_interpreter import *
2
2
  from .errors import *
3
+ from .cached_messages import dshell_cached_messages
@@ -0,0 +1,4 @@
1
+ from contextvars import ContextVar
2
+
3
+ # used to save all viewed messages in the current scoop
4
+ dshell_cached_messages = ContextVar('dshell_cached_messages')
@@ -1,4 +1,4 @@
1
- from asyncio import sleep, create_task
1
+ from asyncio import sleep
2
2
  from re import findall
3
3
  from typing import TypeVar, Union, Any, Optional, Callable
4
4
  from copy import deepcopy
@@ -18,6 +18,7 @@ from .._DshellTokenizer.dshell_keywords import *
18
18
  from .._DshellTokenizer.dshell_token_type import DshellTokenType as DTT
19
19
  from .._DshellTokenizer.dshell_token_type import Token
20
20
  from .._DshellTokenizer.dshell_tokenizer import DshellTokenizer
21
+ from .cached_messages import dshell_cached_messages
21
22
 
22
23
  All_nodes = TypeVar('All_nodes', IfNode, LoopNode, ElseNode, ElifNode, ArgsCommandNode, VarNode)
23
24
  context = TypeVar('context', AutoShardedBot, Message, PrivateChannel, Interaction)
@@ -49,6 +50,7 @@ class DshellInterpreteur:
49
50
  '__ret__': None, # environment variables, '__ret__' is used to store the return value of commands
50
51
 
51
52
  '__author__': message.author.id,
53
+ '__author_name__': message.author.name,
52
54
  '__author_display_name__': message.author.display_name,
53
55
  '__author_avatar__': message.author.display_avatar.url if message.author.display_avatar else None,
54
56
  '__author_discriminator__': message.author.discriminator,
@@ -100,8 +102,9 @@ class DshellInterpreteur:
100
102
  } if message is not None and not debug else {'__ret__': None} # {} is used in debug mode, when ctx is None
101
103
  if vars_env is not None: # add the variables to the environment
102
104
  self.env.update(vars_env)
103
- self.vars = vars if vars is not None else ''
105
+ self.vars = vars or ''
104
106
  self.ctx: context = ctx
107
+ dshell_cached_messages.set(dict()) # save all messages view in the current scoop
105
108
  if debug:
106
109
  print_ast(self.ast)
107
110
 
@@ -548,7 +548,7 @@ class ListNode(ASTNode):
548
548
  """
549
549
  self.iterable: list[Any] = body
550
550
  self.len_iterable: int = len(body)
551
- self.iterateur_count: int = 0
551
+ self.iterator_count: int = 0
552
552
 
553
553
  def to_dict(self):
554
554
  """
@@ -564,8 +564,8 @@ class ListNode(ASTNode):
564
564
  """
565
565
  Add a value to the list.
566
566
  """
567
- if self.len_iterable > 10000:
568
- raise PermissionError('The list is too long, it must not exceed 10,000 elements !')
567
+ if self.len_iterable > 1000:
568
+ raise PermissionError('The list is too long, it must not exceed 1000 elements !')
569
569
 
570
570
  self.iterable.append(value)
571
571
  self.len_iterable += 1
@@ -612,7 +612,7 @@ class ListNode(ASTNode):
612
612
  """
613
613
  self.iterable = []
614
614
  self.len_iterable = 0
615
- self.iterateur_count = 0
615
+ self.iterator_count = 0
616
616
 
617
617
  def sort(self, reverse: bool = False):
618
618
  """
@@ -654,12 +654,12 @@ class ListNode(ASTNode):
654
654
  :return: an element from the list.
655
655
  """
656
656
 
657
- if self.iterateur_count >= self.len_iterable:
658
- self.iterateur_count = 0
657
+ if self.iterator_count >= self.len_iterable:
658
+ self.iterator_count = 0
659
659
  raise StopIteration()
660
660
 
661
- v = self.iterable[self.iterateur_count]
662
- self.iterateur_count += 1
661
+ v = self.iterable[self.iterator_count]
662
+ self.iterator_count += 1
663
663
  return v
664
664
 
665
665
  def __len__(self):
@@ -28,8 +28,20 @@ dshell_keyword: set[str] = {
28
28
  dshell_discord_keyword: set[str] = {
29
29
  'embed', '#embed', 'field', 'perm', 'permission', '#perm', '#permission', 'ui', '#ui', 'button', 'select'
30
30
  }
31
+
32
+ async def dshell_debug(ctx, x):
33
+ """
34
+ Print all x parameter
35
+ :param ctx:
36
+ :param x:
37
+ :return:
38
+ """
39
+ print(x)
40
+ return x
41
+
31
42
  dshell_commands: dict[str, Callable] = {
32
43
 
44
+ "debug": dshell_debug,
33
45
  ## global utils
34
46
  'random': utils_random,
35
47
 
@@ -161,57 +173,3 @@ dshell_logical_operators: dict[str, tuple[Callable, int]] = {
161
173
  dshell_operators: dict[str, tuple[Callable, int]] = dshell_logical_operators.copy()
162
174
  dshell_operators.update(dshell_logical_word_operators)
163
175
  dshell_operators.update(dshell_mathematical_operators)
164
-
165
- '''
166
- C_create_var = "var"
167
- C_obligate_var = "ovar" # makes variables mandatory
168
-
169
- # guild
170
- C_create_channel = "cc"
171
- C_create_voice_channel = "cvc"
172
- C_create_forum_channel = "cfc"
173
- C_create_category = "cca"
174
- C_create_role = "cr"
175
-
176
- C_delete_channel = "dc"
177
- C_delete_category = "dca"
178
- C_delete_role = "dr"
179
-
180
- C_edit_channel = "ec"
181
- C_edit_voice_channel = "evc"
182
- C_edit_forum_channel = "efc"
183
- C_edit_category = "eca"
184
- C_edit_role = "er"
185
- C_edit_guild = "eg"
186
-
187
- # forum
188
- C_edit_ForumTag = "eft"
189
- C_create_thread = "ct"
190
- C_delete_tread = "dt"
191
-
192
- # member
193
- C_edit_nickname = "en"
194
- C_ban_member = "bm"
195
- C_unban_member = "um"
196
- C_kick_member = "km"
197
- C_timeout_member = "tm"
198
- C_move_member = "mm"
199
- C_add_roles = "ar"
200
- C_remove_roles = "rr"
201
-
202
- # message
203
- C_send_message = "sm"
204
- C_respond_message = "rm"
205
- C_edit_message = "em"
206
- C_send_user_message = "sum"
207
- C_delete_message = "dm"
208
- C_purge_message = "pm"
209
- C_create_embed = "e"
210
- C_regex = "regex"
211
- C_add_emoji = "ae"
212
- C_remove_emoji = "re"
213
- C_clear_emoji = "ce"
214
- C_remove_reaction = "rre"
215
-
216
- # button
217
- C_create_button = "b"'''
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dshellInterpreter
3
- Version: 0.2.19.2
3
+ Version: 0.2.19.4
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
@@ -4,29 +4,30 @@ Dshell/DISCORD_COMMANDS/__init__.py,sha256=87-YpGU74m-m7AqUQni7PGbw73JRlioQkywW_
4
4
  Dshell/DISCORD_COMMANDS/dshell_channel.py,sha256=Dy2RnoGzxZGNFvD6QErP74NdVXtfgu55w2ARJEmuUGI,18695
5
5
  Dshell/DISCORD_COMMANDS/dshell_interaction.py,sha256=5FA8JZ2_v98ZzOZl6EKyjo_fUQC7FuK6C6hij6ZSP30,3495
6
6
  Dshell/DISCORD_COMMANDS/dshell_member.py,sha256=5Iw-2dydhYMZOw2nx0svZP9JpZWHOXC0qkL9tClJHtw,8840
7
- Dshell/DISCORD_COMMANDS/dshell_message.py,sha256=SI8w3tuVGNsNa4OW9h08POjhmHjUVpSUAi_0a4XBAF4,9095
7
+ Dshell/DISCORD_COMMANDS/dshell_message.py,sha256=1fRbHduh44ovxjulFGepRqS9YBHAFvj_QovQL0NDt6E,9426
8
8
  Dshell/DISCORD_COMMANDS/dshell_pastbin.py,sha256=H0tUJOwdzYBXvxqipK3mzoNZUKrSLcVm4EZlWbBRScs,796
9
9
  Dshell/DISCORD_COMMANDS/dshell_role.py,sha256=t_yRZRD0FKE2gT4dIDIsHz2PSZZztDVEkkqkG_OkNh4,5002
10
- Dshell/DISCORD_COMMANDS/utils/__init__.py,sha256=-amNcYysjgx3YDpDSnbQmJhnm3lbJere9K9aDH-YnJg,115
10
+ Dshell/DISCORD_COMMANDS/utils/__init__.py,sha256=X5F-fFCXD8Y7sia0b2q-7Fr1-MJj-aL5EupT-bAejzc,234
11
11
  Dshell/DISCORD_COMMANDS/utils/utils_global.py,sha256=G_gH9iF6roT-0QR2FUZj6_P1ADr06JrxZgELOy9yIP8,4768
12
12
  Dshell/DISCORD_COMMANDS/utils/utils_list.py,sha256=zqImMWvD-1UnbPP1TZewnvZpq7qs1sOTT1YhbJ5I8h8,3160
13
13
  Dshell/DISCORD_COMMANDS/utils/utils_member.py,sha256=1EoHooxwijc7AFJGnuae3ccjQk0x69MELtZ5ES5abLY,1165
14
- Dshell/DISCORD_COMMANDS/utils/utils_message.py,sha256=cQvJ15f49ddOjybARwkJKNFe3ITYQciF-pZHERFPkr0,2964
15
- Dshell/DISCORD_COMMANDS/utils/utils_permissions.py,sha256=Gi6vpCA2yXUZ20OCay5dkX6HeN4LglVROwcvTWVCsKg,3600
14
+ Dshell/DISCORD_COMMANDS/utils/utils_message.py,sha256=IPSjvEvJ_8UY3PfAVMlgj6AJthLCRfpZRL1aV8D7SrU,4139
15
+ Dshell/DISCORD_COMMANDS/utils/utils_permissions.py,sha256=wBtdKRLkNSgKgfu7tURdiehdcO-npXUvnVx9D82HudM,3593
16
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
- Dshell/_DshellInterpreteur/__init__.py,sha256=jl_gH8MoqerW--I-IHXwUZTo80JOtfr7AOA57xVgeGQ,58
19
- Dshell/_DshellInterpreteur/dshell_interpreter.py,sha256=I9QOEtHNmj40XlQSVmr7peKztikO-MYMiP5Ro3KXgEE,30645
18
+ Dshell/_DshellInterpreteur/__init__.py,sha256=87b2ljRcSbs2Wbebn72eAiOGTF5ye6qud5w3cP4sCgk,111
19
+ Dshell/_DshellInterpreteur/cached_messages.py,sha256=BJuITd--iITD95MMuwCWVo2HPPlolIZ5FZVSLkTLVD4,156
20
+ Dshell/_DshellInterpreteur/dshell_interpreter.py,sha256=VwaBOx_rV1PMEYzkRPl62ZYbd-6Nk6_oCvdoKnYblXM,30806
20
21
  Dshell/_DshellInterpreteur/errors.py,sha256=0PJz_VYZfNZeKR_PEHxw3tRkgKNNUerV0wwrq2r1luA,250
21
22
  Dshell/_DshellParser/__init__.py,sha256=ONDfhZMvClqP_6tE8SLjp-cf3pXL-auQYnfYRrHZxC4,56
22
- Dshell/_DshellParser/ast_nodes.py,sha256=6SGRQ4wTniah90f-teCKg-l9q3yNzazIhi7Obm38Vow,19636
23
+ Dshell/_DshellParser/ast_nodes.py,sha256=vsY_-uGqbB03Bi556QnRM98kx6oOeJFMe9TaAX2Zcz0,19627
23
24
  Dshell/_DshellParser/dshell_parser.py,sha256=sJdrzJV7Voi_OKx3IazdQ9Yg_5Sk6jz2y02TmsV7T88,19080
24
25
  Dshell/_DshellTokenizer/__init__.py,sha256=LIQSRhDx2B9pmPx5ADMwwD0Xr9ybneVLhHH8qrJWw_s,172
25
- Dshell/_DshellTokenizer/dshell_keywords.py,sha256=f3bAIx8-5aVMhO2-3jbSix3r7Q6yvXMi3Xxy21mjJ0w,7325
26
+ Dshell/_DshellTokenizer/dshell_keywords.py,sha256=jPNUVJ4egBVQ3yMx0Tv0fOS3WHwPJA4XbB4OUy-5uCg,6266
26
27
  Dshell/_DshellTokenizer/dshell_token_type.py,sha256=bkug7eBKjYofkOGmwzPnAH9rQlU14cO0PelZbT0kGoQ,1544
27
28
  Dshell/_DshellTokenizer/dshell_tokenizer.py,sha256=aSXdzEyhqoYYLpMLsLwRpeQPp84PA1F5cjm9O1EYBQs,7350
28
- dshellinterpreter-0.2.19.2.dist-info/licenses/LICENSE,sha256=lNgcw1_xb7QENAQi3uHGymaFtbs0RV-ihiCd7AoLQjA,1082
29
- dshellinterpreter-0.2.19.2.dist-info/METADATA,sha256=T634W79HuWx48_Nd-d5BlrX95nvOjqmQ70Rd0LvD8AA,1151
30
- dshellinterpreter-0.2.19.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
31
- dshellinterpreter-0.2.19.2.dist-info/top_level.txt,sha256=B4CMhtmchGwPQJLuqUy0GhRG-0cUGxKL4GqEbCiB_vE,7
32
- dshellinterpreter-0.2.19.2.dist-info/RECORD,,
29
+ dshellinterpreter-0.2.19.4.dist-info/licenses/LICENSE,sha256=lNgcw1_xb7QENAQi3uHGymaFtbs0RV-ihiCd7AoLQjA,1082
30
+ dshellinterpreter-0.2.19.4.dist-info/METADATA,sha256=l3BYyAZaa0VDHtsP5t4wyR3oOLbSM915Esy6bEDCw9s,1151
31
+ dshellinterpreter-0.2.19.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
32
+ dshellinterpreter-0.2.19.4.dist-info/top_level.txt,sha256=B4CMhtmchGwPQJLuqUy0GhRG-0cUGxKL4GqEbCiB_vE,7
33
+ dshellinterpreter-0.2.19.4.dist-info/RECORD,,