dshellInterpreter 0.2.14.1__py3-none-any.whl → 0.2.14.3__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.
@@ -304,9 +304,10 @@ async def dshell_create_thread_message(ctx: Message,
304
304
  if not isinstance(slowmode, _MissingSentinel) and slowmode < 0:
305
305
  raise Exception("Slowmode delay must be a positive integer !")
306
306
 
307
- thread = await message.fetch().create_thread(name=name,
308
- auto_archive_duration=archive,
309
- slowmode_delay=slowmode)
307
+ m = await message.fetch()
308
+ thread = await m.create_thread(name=name,
309
+ auto_archive_duration=archive,
310
+ slowmode_delay=slowmode)
310
311
 
311
312
  return thread.id
312
313
 
@@ -1,6 +1,7 @@
1
1
  __all__ = [
2
2
  'dshell_respond_interaction',
3
- 'dshell_defer_interaction'
3
+ 'dshell_defer_interaction',
4
+ 'dshell_delete_original_message'
4
5
  ]
5
6
 
6
7
  from types import NoneType
@@ -76,4 +77,16 @@ async def dshell_defer_interaction(ctx: Interaction, hide: bool = False) -> bool
76
77
 
77
78
  await ctx.response.defer(ephemeral=hide)
78
79
 
79
- return True
80
+ return True
81
+
82
+ async def dshell_delete_original_message(ctx: Interaction) -> int:
83
+ """
84
+ Delete the original message of an interaction on Discord
85
+ """
86
+
87
+ if not isinstance(ctx, Interaction):
88
+ raise Exception(f'Respond to an interaction must be used in an interaction context, not {type(ctx)} !')
89
+
90
+ await ctx.delete_original_message()
91
+
92
+ return ctx.message.id
@@ -1,10 +1,9 @@
1
1
  from asyncio import sleep
2
2
  from re import findall
3
3
  from typing import TypeVar, Union, Any, Optional, Callable
4
- from random import choice
5
- from string import ascii_letters, digits
6
4
  from copy import deepcopy
7
5
  from pycordViews import EasyModifiedViews
6
+ from pycordViews.views.errors import CustomIDNotFound
8
7
 
9
8
  from discord import AutoShardedBot, Embed, Colour, PermissionOverwrite, Permissions, Guild, Member, Role, Message, Interaction, ButtonStyle
10
9
  from discord.ui import Button
@@ -146,7 +145,11 @@ class DshellInterpreteur:
146
145
  self.env[node.name.value] = build_permission(first_node.body, self)
147
146
 
148
147
  elif isinstance(first_node, UiNode):
149
- self.env[node.name.value] = build_ui(first_node, self)
148
+ # rebuild the UI if it already exists
149
+ if node.name.value in self.env and isinstance(self.env[node.name.value], EasyModifiedViews):
150
+ self.env[node.name.value] = rebuild_ui(first_node, self.env[node.name.value], self)
151
+ else:
152
+ self.env[node.name.value] = build_ui(first_node, self)
150
153
 
151
154
  elif isinstance(first_node, LengthNode):
152
155
  self.env[node.name.value] = length(first_node)
@@ -448,37 +451,77 @@ def build_colour(color: Union[int, ListNode]) -> Union[Colour, int]:
448
451
  else:
449
452
  raise TypeError(f"Color must be an integer or a ListNode, not {type(color)} !")
450
453
 
451
-
452
- def build_ui(ui_node: UiNode, interpreter: DshellInterpreteur) -> EasyModifiedViews:
454
+ def build_ui_parameters(ui_node: UiNode, interpreter: DshellInterpreteur):
453
455
  """
454
- Builds a UI component from the UiNode.
456
+ Builds the parameters for a UI component from the UiNode.
455
457
  Can accept buttons and select menus.
456
458
  :param ui_node:
457
459
  :param interpreter:
458
460
  :return:
459
461
  """
460
- view = EasyModifiedViews()
461
-
462
- for component in ui_node.buttons:
463
- args_button: dict[str, list[Any]] = regroupe_commandes(component.body, interpreter, normalise=True)[0]
462
+ for ident_component in range(len(ui_node.buttons)):
463
+ args_button: dict[str, list[Any]] = \
464
+ regroupe_commandes(ui_node.buttons[ident_component].body, interpreter, normalise=True)[0]
464
465
  args_button.pop('--*', ())
465
466
 
466
467
  code = args_button.pop('code', None)
467
468
  style = args_button.pop('style', 'primary').lower()
469
+ custom_id = args_button.pop('custom_id', str(ident_component))
470
+
471
+ if not isinstance(custom_id, str):
472
+ raise TypeError(f"Button custom_id must be a string, not {type(custom_id)} !")
473
+
468
474
  if style not in ButtonStyleValues:
469
475
  raise ValueError(f"Button style must be one of {', '.join(ButtonStyleValues)}, not '{style}' !")
476
+
477
+ args_button['custom_id'] = custom_id
470
478
  args_button['style'] = ButtonStyle[style]
471
479
  args = args_button.pop('*', ())
472
- b = Button(*args, **args_button)
480
+ yield args, args_button, code
481
+
482
+ def build_ui(ui_node: UiNode, interpreter: DshellInterpreteur) -> EasyModifiedViews:
483
+ """
484
+ Builds a UI component from the UiNode.
485
+ Can accept buttons and select menus.
486
+ :param ui_node:
487
+ :param interpreter:
488
+ :return:
489
+ """
490
+ view = EasyModifiedViews()
473
491
 
474
- custom_id = ''.join(choice(ascii_letters + digits) for _ in range(20))
475
- b.custom_id = custom_id
492
+ for args, args_button, code in build_ui_parameters(ui_node, interpreter):
493
+ b = Button(**args_button)
476
494
 
477
495
  view.add_items(b)
478
- view.set_callable(custom_id, _callable=ui_button_callback, data={'code': code})
496
+ view.set_callable(b.custom_id, _callable=ui_button_callback, data={'code': code})
497
+
498
+ return view
499
+
500
+ def rebuild_ui(ui_node : UiNode, view: EasyModifiedViews, interpreter: DshellInterpreteur) -> EasyModifiedViews:
501
+ """
502
+ Rebuilds a UI component from an existing EasyModifiedViews.
503
+ :param view:
504
+ :param interpreter:
505
+ :return:
506
+ """
507
+ for args, args_button, code in build_ui_parameters(ui_node, interpreter):
508
+ try:
509
+ ui = view.get_ui(args_button['custom_id'])
510
+ except CustomIDNotFound:
511
+ raise ValueError(f"Button with custom_id '{args_button['custom_id']}' not found in the view !")
512
+
513
+ ui.view.label = args_button.get('label', ui.view.label)
514
+ ui.view.style = args_button.get('style', ui.view.style)
515
+ ui.view.emoji = args_button.get('emoji', ui.view.emoji)
516
+ ui.view.disabled = args_button.get('disabled', ui.view.disabled)
517
+ ui.view.url = args_button.get('url', ui.view.url)
518
+ ui.view.row = args_button.get('row', ui.view.row)
519
+ new_code = code if code is not None else view.get_callable_data(args_button['custom_id'])['code']
520
+ view.set_callable(args_button['custom_id'], _callable=ui_button_callback, data={'code': args_button.get('code', code)})
479
521
 
480
522
  return view
481
523
 
524
+
482
525
  async def ui_button_callback(button: Button, interaction: Interaction, data: dict[str, Any]):
483
526
  """
484
527
  Callback for UI buttons.
@@ -488,7 +531,6 @@ async def ui_button_callback(button: Button, interaction: Interaction, data: dic
488
531
  :param data:
489
532
  :return:
490
533
  """
491
- print(data)
492
534
  code = data.pop('code', None)
493
535
  if code is not None:
494
536
  local_env = {
@@ -37,6 +37,7 @@ dshell_commands: dict[str, Callable] = {
37
37
 
38
38
  "sri": dshell_respond_interaction, # respond to an interaction
39
39
  "sdi": dshell_defer_interaction, # defer an interaction
40
+ "dom": dshell_delete_original_message, # delete original interaction message
40
41
 
41
42
  "cc": dshell_create_text_channel, # create channel
42
43
  "cvc": dshell_create_voice_channel, # create voice channel
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dshellInterpreter
3
- Version: 0.2.14.1
3
+ Version: 0.2.14.3
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,8 +1,8 @@
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=87-YpGU74m-m7AqUQni7PGbw73JRlioQkywW_61Whms,208
4
- Dshell/DISCORD_COMMANDS/dshell_channel.py,sha256=qpNe3oE5VyLCmOeCjWlt0rvaSBv2yrkmJgrRswrNOZM,15721
5
- Dshell/DISCORD_COMMANDS/dshell_interaction.py,sha256=Gac3J9sCcPRHApIgSoS5MRAMJ0Hd7I-YywVQI0s26p0,3229
4
+ Dshell/DISCORD_COMMANDS/dshell_channel.py,sha256=PDXpxrRRWPSucdp_3ITJk0Ur3coneRJKWEl2i7GZ2EM,15696
5
+ Dshell/DISCORD_COMMANDS/dshell_interaction.py,sha256=gYojAOH5hl-ZL6Y1lEb87-H9MtOa8sb_VAV4_iiYfWA,3649
6
6
  Dshell/DISCORD_COMMANDS/dshell_member.py,sha256=5Iw-2dydhYMZOw2nx0svZP9JpZWHOXC0qkL9tClJHtw,8840
7
7
  Dshell/DISCORD_COMMANDS/dshell_message.py,sha256=zcWl6Y1W31h9MTHS-j9tLDwcrRiE_wGOu78zu2k0y9I,9101
8
8
  Dshell/DISCORD_COMMANDS/dshell_pastbin.py,sha256=H0tUJOwdzYBXvxqipK3mzoNZUKrSLcVm4EZlWbBRScs,796
@@ -11,16 +11,16 @@ Dshell/DISCORD_COMMANDS/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5N
11
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=RHDCLtZ66cqlvy6VKMKHWV3eL26V-CKcQEEN-2TUzhc,28857
14
+ Dshell/_DshellInterpreteur/dshell_interpreter.py,sha256=u89gS8ekT2PJ9ml5CN_T9XXjwNkU7Pw3VrqkMVBeCdQ,30902
15
15
  Dshell/_DshellParser/__init__.py,sha256=ONDfhZMvClqP_6tE8SLjp-cf3pXL-auQYnfYRrHZxC4,56
16
16
  Dshell/_DshellParser/ast_nodes.py,sha256=fU6BVe6w78ZhYib7SGR7iAfTqWqS2kvwZ0d4wMxxOHk,18366
17
17
  Dshell/_DshellParser/dshell_parser.py,sha256=ZSSRheiNNR1zumxBK_tqlnUPjJ7ZIE6S-K5aJPp4TjM,21887
18
18
  Dshell/_DshellTokenizer/__init__.py,sha256=LIQSRhDx2B9pmPx5ADMwwD0Xr9ybneVLhHH8qrJWw_s,172
19
- Dshell/_DshellTokenizer/dshell_keywords.py,sha256=euTckA4AsWBfBGMnFFi1YVz8dvXY1HNsQjNWtvARMR8,5878
19
+ Dshell/_DshellTokenizer/dshell_keywords.py,sha256=7oeSKLXCsPRpyU31skCerOUMzd2cdm-GwofpmgTPkD0,5961
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.14.1.dist-info/licenses/LICENSE,sha256=lNgcw1_xb7QENAQi3uHGymaFtbs0RV-ihiCd7AoLQjA,1082
23
- dshellinterpreter-0.2.14.1.dist-info/METADATA,sha256=R-ZsMvWTCwL1mjgcm6jbohdIYEooLu8WxXcQPl-zK9o,1151
24
- dshellinterpreter-0.2.14.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
25
- dshellinterpreter-0.2.14.1.dist-info/top_level.txt,sha256=B4CMhtmchGwPQJLuqUy0GhRG-0cUGxKL4GqEbCiB_vE,7
26
- dshellinterpreter-0.2.14.1.dist-info/RECORD,,
22
+ dshellinterpreter-0.2.14.3.dist-info/licenses/LICENSE,sha256=lNgcw1_xb7QENAQi3uHGymaFtbs0RV-ihiCd7AoLQjA,1082
23
+ dshellinterpreter-0.2.14.3.dist-info/METADATA,sha256=nLlUFCpjuFHxsm5NGiDfTD3mNSW3oEdO2cSdnC_JrPQ,1151
24
+ dshellinterpreter-0.2.14.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
25
+ dshellinterpreter-0.2.14.3.dist-info/top_level.txt,sha256=B4CMhtmchGwPQJLuqUy0GhRG-0cUGxKL4GqEbCiB_vE,7
26
+ dshellinterpreter-0.2.14.3.dist-info/RECORD,,