dshellInterpreter 0.2.3__py3-none-any.whl → 0.2.4.1__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.
- Dshell/DISCORD_COMMANDS/__init__.py +1 -0
- Dshell/DISCORD_COMMANDS/dshell_pastbin.py +1 -1
- Dshell/DISCORD_COMMANDS/dshell_role.py +119 -0
- Dshell/_DshellInterpreteur/dshell_interpreter.py +27 -6
- Dshell/_DshellTokenizer/dshell_keywords.py +5 -0
- {dshellinterpreter-0.2.3.dist-info → dshellinterpreter-0.2.4.1.dist-info}/METADATA +2 -1
- {dshellinterpreter-0.2.3.dist-info → dshellinterpreter-0.2.4.1.dist-info}/RECORD +10 -9
- {dshellinterpreter-0.2.3.dist-info → dshellinterpreter-0.2.4.1.dist-info}/WHEEL +0 -0
- {dshellinterpreter-0.2.3.dist-info → dshellinterpreter-0.2.4.1.dist-info}/licenses/LICENSE +0 -0
- {dshellinterpreter-0.2.3.dist-info → dshellinterpreter-0.2.4.1.dist-info}/top_level.txt +0 -0
|
@@ -22,7 +22,7 @@ async def dshell_get_pastbin(ctx: Message, code: str):
|
|
|
22
22
|
|
|
23
23
|
for line in response.iter_lines(decode_unicode=True, chunk_size=512):
|
|
24
24
|
len_content = len(content)
|
|
25
|
-
if
|
|
25
|
+
if len_content < 4000 and len_content + len(line) <= 4000:
|
|
26
26
|
content += line + '\n'
|
|
27
27
|
else:
|
|
28
28
|
break
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
from discord import MISSING, Message, PermissionOverwrite
|
|
2
|
+
from discord.utils import _MissingSentinel
|
|
3
|
+
|
|
4
|
+
from typing import TYPE_CHECKING
|
|
5
|
+
if TYPE_CHECKING:
|
|
6
|
+
from .._DshellInterpreteur.dshell_interpreter import build_colour, ListNode
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
'dshell_create_role',
|
|
10
|
+
'dshell_delete_roles',
|
|
11
|
+
'dshell_edit_role'
|
|
12
|
+
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
async def dshell_create_role(ctx: Message,
|
|
16
|
+
name: str = MISSING,
|
|
17
|
+
permissions: dict[None, PermissionOverwrite] = MISSING,
|
|
18
|
+
color: int = MISSING,
|
|
19
|
+
hoist: bool = MISSING,
|
|
20
|
+
mentionable: bool = MISSING,
|
|
21
|
+
reason: str = None):
|
|
22
|
+
"""
|
|
23
|
+
Creates a role on the server.
|
|
24
|
+
"""
|
|
25
|
+
if not isinstance(name, (str, _MissingSentinel)):
|
|
26
|
+
raise Exception(f"Name must be a string, not {type(name)} !")
|
|
27
|
+
|
|
28
|
+
if not isinstance(permissions, (dict, _MissingSentinel)):
|
|
29
|
+
raise Exception(f"Permissions must be a PermissionNode, not {type(permissions)} !")
|
|
30
|
+
|
|
31
|
+
colour = build_colour(color)
|
|
32
|
+
|
|
33
|
+
if not isinstance(hoist, (bool, _MissingSentinel)):
|
|
34
|
+
raise Exception(f"Hoist must be a boolean, not {type(permissions)} !")
|
|
35
|
+
|
|
36
|
+
if not isinstance(mentionable, (bool, _MissingSentinel)):
|
|
37
|
+
raise Exception(f"Mentionable must be a boolean, not {type(permissions)} !")
|
|
38
|
+
|
|
39
|
+
if isinstance(permissions, dict):
|
|
40
|
+
if None in permissions:
|
|
41
|
+
allow, deny = permissions[None].pair()
|
|
42
|
+
permissions = allow
|
|
43
|
+
|
|
44
|
+
created_role = await ctx.guild.create_role(name=name,
|
|
45
|
+
permissions=permissions,
|
|
46
|
+
colour=colour,
|
|
47
|
+
hoist=hoist,
|
|
48
|
+
mentionable=mentionable,
|
|
49
|
+
reason=str(reason))
|
|
50
|
+
|
|
51
|
+
return created_role.id
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
async def dshell_delete_roles(ctx: Message, roles, reason=None):
|
|
55
|
+
"""
|
|
56
|
+
Delete the role on the server
|
|
57
|
+
"""
|
|
58
|
+
roles: int | ListNode
|
|
59
|
+
if not isinstance(roles, (int, ListNode)):
|
|
60
|
+
raise Exception(f"Role must be a int, role mention or NodeList of both, not {type(roles)} !")
|
|
61
|
+
|
|
62
|
+
if isinstance(roles, int):
|
|
63
|
+
roles: tuple = (roles, )
|
|
64
|
+
|
|
65
|
+
for i in roles:
|
|
66
|
+
role_to_delete = ctx.guild.get_role(i)
|
|
67
|
+
|
|
68
|
+
if role_to_delete is None:
|
|
69
|
+
raise Exception(f'Role {i} not found in the server !')
|
|
70
|
+
|
|
71
|
+
await role_to_delete.delete(reason=str(reason))
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
async def dshell_edit_role(ctx: Message,
|
|
75
|
+
role,
|
|
76
|
+
name=None,
|
|
77
|
+
permissions: dict[None, PermissionOverwrite]=None,
|
|
78
|
+
color=None,
|
|
79
|
+
hoist=None,
|
|
80
|
+
mentionable=None,
|
|
81
|
+
position=None,
|
|
82
|
+
reason=None,):
|
|
83
|
+
"""
|
|
84
|
+
Edit the current role
|
|
85
|
+
"""
|
|
86
|
+
if not isinstance(role, int):
|
|
87
|
+
raise Exception(f"Role must be a int or role mention not {type(role)} !")
|
|
88
|
+
|
|
89
|
+
role_to_edit = ctx.guild.get_role(role)
|
|
90
|
+
|
|
91
|
+
if not isinstance(name, (str, None)):
|
|
92
|
+
raise Exception(f"Name must be a string, not {type(name)} !")
|
|
93
|
+
|
|
94
|
+
if not isinstance(permissions, (dict, None)):
|
|
95
|
+
raise Exception(f"Permissions must be a PermissionNode, not {type(permissions)} !")
|
|
96
|
+
|
|
97
|
+
if isinstance(permissions, dict):
|
|
98
|
+
if None in permissions:
|
|
99
|
+
allow, deny = permissions[None].pair()
|
|
100
|
+
permissions = allow
|
|
101
|
+
|
|
102
|
+
colour = build_colour(color)
|
|
103
|
+
|
|
104
|
+
if not isinstance(hoist, (bool, None)):
|
|
105
|
+
raise Exception(f"Hoist must be a boolean, not {type(permissions)} !")
|
|
106
|
+
|
|
107
|
+
if not isinstance(mentionable, (bool, None)):
|
|
108
|
+
raise Exception(f"Mentionable must be a boolean, not {type(permissions)} !")
|
|
109
|
+
|
|
110
|
+
if not isinstance(position, (int, None)):
|
|
111
|
+
raise Exception(f"Position must be an integer, not {type(permissions)} !")
|
|
112
|
+
|
|
113
|
+
await role_to_edit.edit(name=name if name is not None else role_to_edit.name,
|
|
114
|
+
permissions=permissions if permissions is not None else role_to_edit.permissions,
|
|
115
|
+
colour=colour if color is not None else role_to_edit.colour,
|
|
116
|
+
hoist=hoist if hoist is not None else role_to_edit.hoist,
|
|
117
|
+
mentionable=mentionable if mentionable is not None else role_to_edit.mentionable,
|
|
118
|
+
position=position if position is not None else role_to_edit.position,
|
|
119
|
+
reason=str(reason))
|
|
@@ -366,9 +366,8 @@ def build_embed(body: list[Token], fields: list[FieldEmbedNode], interpreter: Ds
|
|
|
366
366
|
a: dict[str, Token]
|
|
367
367
|
args_fields.append(a)
|
|
368
368
|
|
|
369
|
-
if 'color' in args_main_embed
|
|
370
|
-
|
|
371
|
-
args_main_embed['color'] = Colour.from_rgb(*args_main_embed['color'])
|
|
369
|
+
if 'color' in args_main_embed:
|
|
370
|
+
args_main_embed['color'] = build_colour(args_main_embed['color']) # convert color to Colour object or int
|
|
372
371
|
|
|
373
372
|
embed = Embed(**args_main_embed) # build the main embed
|
|
374
373
|
for field in args_fields:
|
|
@@ -376,6 +375,21 @@ def build_embed(body: list[Token], fields: list[FieldEmbedNode], interpreter: Ds
|
|
|
376
375
|
|
|
377
376
|
return embed
|
|
378
377
|
|
|
378
|
+
def build_colour(color: Union[int, ListNode]) -> Union[Colour, int]:
|
|
379
|
+
"""
|
|
380
|
+
Builds a Colour object from an integer or a ListNode.
|
|
381
|
+
:param color: The color to build.
|
|
382
|
+
:return: A Colour object.
|
|
383
|
+
"""
|
|
384
|
+
if isinstance(color, int):
|
|
385
|
+
return color
|
|
386
|
+
elif isinstance(color, (ListNode, list)):
|
|
387
|
+
if not len(color) == 3:
|
|
388
|
+
raise ValueError(f"Color must be a list of 3 integers, not {len(color)} elements !")
|
|
389
|
+
return Colour.from_rgb(*color)
|
|
390
|
+
else:
|
|
391
|
+
raise TypeError(f"Color must be an integer or a ListNode, not {type(color)} !")
|
|
392
|
+
|
|
379
393
|
|
|
380
394
|
def build_permission(body: list[Token], interpreter: DshellInterpreteur) -> dict[
|
|
381
395
|
Union[Member, Role], PermissionOverwrite]:
|
|
@@ -446,9 +460,12 @@ class DshellPermissions:
|
|
|
446
460
|
if member is not None:
|
|
447
461
|
return member
|
|
448
462
|
|
|
449
|
-
|
|
463
|
+
elif role is not None:
|
|
450
464
|
return role
|
|
451
465
|
|
|
466
|
+
else:
|
|
467
|
+
raise ValueError(f"No member or role found with ID {target_id} in guild {guild.name}.")
|
|
468
|
+
|
|
452
469
|
@staticmethod
|
|
453
470
|
def get_member(guild: Guild, target_id: int) -> Member:
|
|
454
471
|
"""
|
|
@@ -480,10 +497,11 @@ class DshellPermissions:
|
|
|
480
497
|
def get_permission_overwrite(self, guild: Guild) -> dict[Union[Member, Role], PermissionOverwrite]:
|
|
481
498
|
"""
|
|
482
499
|
Returns a PermissionOverwrite object with member and role permissions.
|
|
500
|
+
If no members or roles are specified, it returns a PermissionOverwrite with None key.
|
|
483
501
|
:param guild: The Discord server
|
|
484
502
|
:return: A dictionary of PermissionOverwrite objects with members and roles as keys
|
|
485
503
|
"""
|
|
486
|
-
permissions: dict[Union[Member, Role], PermissionOverwrite] = {}
|
|
504
|
+
permissions: dict[Union[Member, Role, None], PermissionOverwrite] = {}
|
|
487
505
|
target_keys = self.target.keys()
|
|
488
506
|
|
|
489
507
|
if 'members' in target_keys:
|
|
@@ -506,6 +524,9 @@ class DshellPermissions:
|
|
|
506
524
|
deny=Permissions(permissions=self.target.get('deny', 0))
|
|
507
525
|
)
|
|
508
526
|
else:
|
|
509
|
-
|
|
527
|
+
permissions[None] = PermissionOverwrite.from_pair(
|
|
528
|
+
allow=Permissions(permissions=self.target.get('allow', 0)),
|
|
529
|
+
deny=Permissions(permissions=self.target.get('deny', 0))
|
|
530
|
+
)
|
|
510
531
|
|
|
511
532
|
return permissions
|
|
@@ -13,6 +13,7 @@ from ..DISCORD_COMMANDS.dshell_channel import *
|
|
|
13
13
|
from ..DISCORD_COMMANDS.dshell_member import *
|
|
14
14
|
from ..DISCORD_COMMANDS.dshell_message import *
|
|
15
15
|
from ..DISCORD_COMMANDS.dshell_pastbin import *
|
|
16
|
+
from ..DISCORD_COMMANDS.dshell_role import *
|
|
16
17
|
|
|
17
18
|
dshell_keyword: set[str] = {
|
|
18
19
|
'if', 'else', 'elif', 'loop', '#end', 'var', '#loop', '#if', 'sleep', 'param', '#param'
|
|
@@ -49,6 +50,10 @@ dshell_commands: dict[str, Callable] = {
|
|
|
49
50
|
"ec": dshell_edit_text_channel, # edit text channel
|
|
50
51
|
"evc": dshell_edit_voice_channel, # edit voice channel
|
|
51
52
|
|
|
53
|
+
"cr": dshell_create_role,
|
|
54
|
+
"dr": dshell_delete_roles,
|
|
55
|
+
"er": dshell_edit_role,
|
|
56
|
+
|
|
52
57
|
"amr": dshell_add_reactions, # add reactions to a message
|
|
53
58
|
"rmr": dshell_remove_reactions, # remove reactions from a message
|
|
54
59
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dshellInterpreter
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4.1
|
|
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
|
|
@@ -16,6 +16,7 @@ Requires-Python: >=3.9
|
|
|
16
16
|
Description-Content-Type: text/markdown
|
|
17
17
|
License-File: LICENSE
|
|
18
18
|
Requires-Dist: py-cord==2.6.1
|
|
19
|
+
Requires-Dist: requests
|
|
19
20
|
Dynamic: author
|
|
20
21
|
Dynamic: author-email
|
|
21
22
|
Dynamic: classifier
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
Dshell/__init__.py,sha256=UPvXnewe_8FX9aoevMA78UN1k8AY-u8LTY3vEVxaDxw,72
|
|
2
|
-
Dshell/DISCORD_COMMANDS/__init__.py,sha256=
|
|
2
|
+
Dshell/DISCORD_COMMANDS/__init__.py,sha256=_oo_aMEju4gZg-MIbF8bKMVM6CWAF0AO9DxAlemaXMw,149
|
|
3
3
|
Dshell/DISCORD_COMMANDS/dshell_channel.py,sha256=2qnbI2tUu5sowJVOVkY4p-l6Gu-5Gw9BEP3MItScvV8,8939
|
|
4
4
|
Dshell/DISCORD_COMMANDS/dshell_member.py,sha256=KEdI14VTmDJm3zb4Mt-cFe71Jdsrolj6O8673Vzw4n8,5943
|
|
5
5
|
Dshell/DISCORD_COMMANDS/dshell_message.py,sha256=fLxj_Ns-krZgXEPijhWvBFLorvmbleR6JpVOR72BIa8,5180
|
|
6
|
-
Dshell/DISCORD_COMMANDS/dshell_pastbin.py,sha256=
|
|
6
|
+
Dshell/DISCORD_COMMANDS/dshell_pastbin.py,sha256=TkWFGRRTvhhJgvwkDFx9Fz4UM2UUFwxyq0laMVx0mUk,881
|
|
7
|
+
Dshell/DISCORD_COMMANDS/dshell_role.py,sha256=wnhBzaxs53pH5q1OPPuYGSKIblylFcs1B7j1agims9E,4700
|
|
7
8
|
Dshell/_DshellInterpreteur/__init__.py,sha256=xy5-J-R3YmY99JF3NBHTRRLsComFxpjnCA5xacISctU,35
|
|
8
|
-
Dshell/_DshellInterpreteur/dshell_interpreter.py,sha256=
|
|
9
|
+
Dshell/_DshellInterpreteur/dshell_interpreter.py,sha256=dJS8frzNhKEvs-WdC7kwcZMZKefraWO4t8vLrFctjvA,22805
|
|
9
10
|
Dshell/_DshellParser/__init__.py,sha256=ONDfhZMvClqP_6tE8SLjp-cf3pXL-auQYnfYRrHZxC4,56
|
|
10
11
|
Dshell/_DshellParser/ast_nodes.py,sha256=2qwL_M0ELPia6L6gqwgV5hqprvyuo97cx3Zk2dVz09U,15341
|
|
11
12
|
Dshell/_DshellParser/dshell_parser.py,sha256=bdnVhx-MchM61J88fa9PimpAdwPtQumywJd-GoMqS8Q,15514
|
|
12
13
|
Dshell/_DshellTokenizer/__init__.py,sha256=LIQSRhDx2B9pmPx5ADMwwD0Xr9ybneVLhHH8qrJWw_s,172
|
|
13
|
-
Dshell/_DshellTokenizer/dshell_keywords.py,sha256=
|
|
14
|
+
Dshell/_DshellTokenizer/dshell_keywords.py,sha256=G9qdXr-d05QtmBdwTGa1qMDm7TDbIEkbx_-ERU97Ods,4664
|
|
14
15
|
Dshell/_DshellTokenizer/dshell_token_type.py,sha256=pWzvmj6EFGkDwNHooOAjdyysi1vZRVEostFIZSW1Ais,1483
|
|
15
16
|
Dshell/_DshellTokenizer/dshell_tokenizer.py,sha256=-EhwrfbcOcnAxOHWBE89531t25u6c6HmJuT1AKFn9Ew,7032
|
|
16
|
-
dshellinterpreter-0.2.
|
|
17
|
-
dshellinterpreter-0.2.
|
|
18
|
-
dshellinterpreter-0.2.
|
|
19
|
-
dshellinterpreter-0.2.
|
|
20
|
-
dshellinterpreter-0.2.
|
|
17
|
+
dshellinterpreter-0.2.4.1.dist-info/licenses/LICENSE,sha256=lNgcw1_xb7QENAQi3uHGymaFtbs0RV-ihiCd7AoLQjA,1082
|
|
18
|
+
dshellinterpreter-0.2.4.1.dist-info/METADATA,sha256=J6IIRHnxoBBXUyY9KE9cE2Li3xQhm2AI5RWgkf0lZYE,1122
|
|
19
|
+
dshellinterpreter-0.2.4.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
20
|
+
dshellinterpreter-0.2.4.1.dist-info/top_level.txt,sha256=B4CMhtmchGwPQJLuqUy0GhRG-0cUGxKL4GqEbCiB_vE,7
|
|
21
|
+
dshellinterpreter-0.2.4.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|