dshellInterpreter 0.2.21.7__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.
- Dshell/DISCORD_COMMANDS/__init__.py +7 -0
- Dshell/DISCORD_COMMANDS/dshell_channel.py +612 -0
- Dshell/DISCORD_COMMANDS/dshell_interaction.py +89 -0
- Dshell/DISCORD_COMMANDS/dshell_member.py +274 -0
- Dshell/DISCORD_COMMANDS/dshell_message.py +444 -0
- Dshell/DISCORD_COMMANDS/dshell_pastbin.py +28 -0
- Dshell/DISCORD_COMMANDS/dshell_role.py +128 -0
- Dshell/DISCORD_COMMANDS/utils/__init__.py +8 -0
- Dshell/DISCORD_COMMANDS/utils/utils_global.py +155 -0
- Dshell/DISCORD_COMMANDS/utils/utils_list.py +109 -0
- Dshell/DISCORD_COMMANDS/utils/utils_member.py +30 -0
- Dshell/DISCORD_COMMANDS/utils/utils_message.py +78 -0
- Dshell/DISCORD_COMMANDS/utils/utils_permissions.py +94 -0
- Dshell/DISCORD_COMMANDS/utils/utils_string.py +157 -0
- Dshell/DISCORD_COMMANDS/utils/utils_thread.py +35 -0
- Dshell/_DshellInterpreteur/__init__.py +4 -0
- Dshell/_DshellInterpreteur/cached_messages.py +4 -0
- Dshell/_DshellInterpreteur/dshell_arguments.py +74 -0
- Dshell/_DshellInterpreteur/dshell_interpreter.py +671 -0
- Dshell/_DshellInterpreteur/errors.py +8 -0
- Dshell/_DshellParser/__init__.py +2 -0
- Dshell/_DshellParser/ast_nodes.py +675 -0
- Dshell/_DshellParser/dshell_parser.py +408 -0
- Dshell/_DshellTokenizer/__init__.py +4 -0
- Dshell/_DshellTokenizer/dshell_keywords.py +193 -0
- Dshell/_DshellTokenizer/dshell_token_type.py +58 -0
- Dshell/_DshellTokenizer/dshell_tokenizer.py +146 -0
- Dshell/__init__.py +3 -0
- Dshell/_utils.py +1 -0
- dshellinterpreter-0.2.21.7.dist-info/METADATA +37 -0
- dshellinterpreter-0.2.21.7.dist-info/RECORD +34 -0
- dshellinterpreter-0.2.21.7.dist-info/WHEEL +5 -0
- dshellinterpreter-0.2.21.7.dist-info/licenses/LICENSE +21 -0
- dshellinterpreter-0.2.21.7.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
__all__ = [
|
|
2
|
+
"DshellTokenizer",
|
|
3
|
+
"table_regex",
|
|
4
|
+
"MASK_CHARACTER"
|
|
5
|
+
]
|
|
6
|
+
|
|
7
|
+
from re import DOTALL, IGNORECASE, ASCII
|
|
8
|
+
from re import compile, Pattern, finditer, escape, sub, findall
|
|
9
|
+
|
|
10
|
+
from .dshell_keywords import *
|
|
11
|
+
from .dshell_token_type import DshellTokenType as DTT
|
|
12
|
+
from .dshell_token_type import Token
|
|
13
|
+
|
|
14
|
+
MASK_CHARACTER = '§'
|
|
15
|
+
|
|
16
|
+
table_regex: dict[DTT, Pattern] = {
|
|
17
|
+
DTT.PARAMETERS: compile(rf"--\*\s*(\w+)\s*", flags=ASCII),
|
|
18
|
+
DTT.STR_PARAMETER: compile(rf"--\'\s*(\w+)\s*", flags=ASCII),
|
|
19
|
+
DTT.PARAMETER: compile(rf"--\s*(\w+)\s*", flags=ASCII),
|
|
20
|
+
DTT.STR: compile(r'"((?:[^\\"]|\\.)*)"', flags=DOTALL),
|
|
21
|
+
DTT.COMMENT: compile(r"::(.*?)$"),
|
|
22
|
+
DTT.EVAL_GROUP: compile(r"`(.*?)`"),
|
|
23
|
+
DTT.LIST: compile(r"\[(.*?)\]"),
|
|
24
|
+
DTT.MENTION: compile(r'<(?:@!?|@&|#)([0-9]+)>'),
|
|
25
|
+
DTT.SUB_SEPARATOR: compile(rf"(~~)"),
|
|
26
|
+
DTT.KEYWORD: compile(rf"(?<!\w)(#?{'|'.join(dshell_keyword)})(?!\w)"),
|
|
27
|
+
DTT.DISCORD_KEYWORD: compile(rf"(?<!\w|-)(#?{'|'.join(dshell_discord_keyword)})(?!\w|-)"),
|
|
28
|
+
DTT.COMMAND: compile(rf"\b({'|'.join(dshell_commands.keys())})\b"),
|
|
29
|
+
DTT.MATHS_OPERATOR: compile(rf"({'|'.join([escape(i) for i in dshell_mathematical_operators.keys()])})"),
|
|
30
|
+
DTT.LOGIC_OPERATOR: compile(rf"({'|'.join([escape(i) for i in dshell_logical_operators.keys()])})"),
|
|
31
|
+
DTT.LOGIC_WORD_OPERATOR: compile(rf"(?:^|\s)({'|'.join([escape(i) for i in dshell_logical_word_operators.keys()])})(?:$|\s)"),
|
|
32
|
+
DTT.FLOAT: compile(r"(\d+\.\d+)"),
|
|
33
|
+
DTT.INT: compile(r"(\d+)"),
|
|
34
|
+
DTT.BOOL: compile(r"(True|False)", flags=IGNORECASE),
|
|
35
|
+
DTT.NONE: compile(r"(None)", flags=IGNORECASE),
|
|
36
|
+
DTT.IDENT: compile(rf"([A-Za-z0-9_]+)")
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class DshellTokenizer:
|
|
41
|
+
|
|
42
|
+
def __init__(self, code: str):
|
|
43
|
+
"""
|
|
44
|
+
Init le tokenizer.
|
|
45
|
+
:param code: Le code à tokenizer
|
|
46
|
+
"""
|
|
47
|
+
self.code: str = code
|
|
48
|
+
|
|
49
|
+
def start(self):
|
|
50
|
+
"""
|
|
51
|
+
Démarre le tokenizer pour qu'il traîte le code actuel.
|
|
52
|
+
Renvoie un tableau de tokens par ligne (séparé normalement pas des \n)
|
|
53
|
+
"""
|
|
54
|
+
splited_commandes = self.split(self.code)
|
|
55
|
+
return self.tokenizer(splited_commandes)
|
|
56
|
+
|
|
57
|
+
def tokenizer(self, commandes_lines: list[str]) -> list[list[Token]]:
|
|
58
|
+
"""
|
|
59
|
+
Tokenize chaque ligne de code
|
|
60
|
+
:param commandes_lines: Le code séparé en plusieurs lignes par la méthode split
|
|
61
|
+
"""
|
|
62
|
+
tokens: list[list[Token]] = []
|
|
63
|
+
|
|
64
|
+
line_number = 1
|
|
65
|
+
for ligne in commandes_lines: # iter chaque ligne du code
|
|
66
|
+
tokens_par_ligne: list[Token] = []
|
|
67
|
+
|
|
68
|
+
for token_type, pattern in table_regex.items(): # iter la table de régex pour tous les tester sur la ligne
|
|
69
|
+
|
|
70
|
+
for match in finditer(pattern, ligne): # iter les résultat du match pour avoir leur position
|
|
71
|
+
|
|
72
|
+
start_match = match.start() # position de début du match
|
|
73
|
+
|
|
74
|
+
if token_type != DTT.COMMENT: # si ce n'est pas un commentaire
|
|
75
|
+
token = Token(token_type, match.group(1), (line_number, start_match)) # on enregistre son token
|
|
76
|
+
tokens_par_ligne.append(token)
|
|
77
|
+
|
|
78
|
+
if token_type == DTT.STR:
|
|
79
|
+
token.value = token.value.replace(r'\"', '"')
|
|
80
|
+
|
|
81
|
+
if token_type in (
|
|
82
|
+
DTT.LIST,
|
|
83
|
+
DTT.EVAL_GROUP): # si c'est un regroupement de donnée, on tokenize ce qu'il contient
|
|
84
|
+
result = self.tokenizer([token.value])
|
|
85
|
+
token.value = result[0] if len(
|
|
86
|
+
result) > 0 else result # gère si la structure de donnée est vide ou non
|
|
87
|
+
|
|
88
|
+
for token_in_list in token.value:
|
|
89
|
+
token_in_list.position = (line_number, token_in_list.position[1])
|
|
90
|
+
|
|
91
|
+
for token_in_line in range(len(tokens_par_ligne)-1):
|
|
92
|
+
if tokens_par_ligne[token_in_line].position[1] > start_match:
|
|
93
|
+
str_tokens_in_list = tokens_par_ligne[token_in_line:-1]
|
|
94
|
+
tokens_par_ligne = tokens_par_ligne[:token_in_line] + [tokens_par_ligne[-1]]
|
|
95
|
+
token.value.extend(str_tokens_in_list)
|
|
96
|
+
token.value.sort(key=lambda t: t.position[1]) # trie les tokens par rapport à leur position
|
|
97
|
+
break
|
|
98
|
+
|
|
99
|
+
len_match = len(match.group(0)) # longueur du match trouvé
|
|
100
|
+
ligne = ligne[:start_match] + (MASK_CHARACTER * len_match) + ligne[
|
|
101
|
+
match.end():] # remplace la match qui vient d'avoir lieu pour ne pas le rematch une seconde fois
|
|
102
|
+
|
|
103
|
+
tokens_par_ligne.sort(key=lambda
|
|
104
|
+
token: token.position[1]) # trie la position par rapport aux positions de match des tokens pour les avoir dans l'ordre du code
|
|
105
|
+
if tokens_par_ligne:
|
|
106
|
+
tokens.append(tokens_par_ligne)
|
|
107
|
+
|
|
108
|
+
line_number += 1 # incrémente le numéro de ligne pour la prochaine ligne
|
|
109
|
+
|
|
110
|
+
return tokens
|
|
111
|
+
|
|
112
|
+
@staticmethod
|
|
113
|
+
def split(commande: str, global_split='\n', garder_carractere_regroupant=True, carractere_regroupant='"') -> list[
|
|
114
|
+
str]:
|
|
115
|
+
"""
|
|
116
|
+
Sépare les commandes en une liste en respectant les chaînes entre guillemets.
|
|
117
|
+
Echapper les caractères regroupants avec un antislash (\) pour les inclure dans la chaîne.
|
|
118
|
+
:param commande: La chaîne de caractères à découper.
|
|
119
|
+
:param global_split: Le séparateur utilisé (par défaut '\n').
|
|
120
|
+
:param garder_carractere_regroupant: Si False, enlève les guillemets autour des chaînes.
|
|
121
|
+
:param caractere_regroupant: Le caractère utilisé pour regrouper une chaîne (par défaut '"').
|
|
122
|
+
:return: Une liste des commandes découpées avec les chaînes restaurées.
|
|
123
|
+
"""
|
|
124
|
+
|
|
125
|
+
commandes: str = commande.strip()
|
|
126
|
+
remplacement_temporaire = '[REMPLACER]'
|
|
127
|
+
pattern_find_regrouped_part = compile(fr'({carractere_regroupant}(?:[^\\{carractere_regroupant}]|\\.)*{carractere_regroupant})', flags=DOTALL)
|
|
128
|
+
entre_caractere_regroupant = findall(pattern_find_regrouped_part, commandes) # repère les parties entre guillemets et les save
|
|
129
|
+
|
|
130
|
+
res = sub(pattern_find_regrouped_part,
|
|
131
|
+
remplacement_temporaire,
|
|
132
|
+
commandes,
|
|
133
|
+
) # remplace les parties entre guillemets
|
|
134
|
+
|
|
135
|
+
res = res.split(global_split) # split les commandes sans les guillemets
|
|
136
|
+
|
|
137
|
+
# remet les guillemets à leurs place
|
|
138
|
+
result = []
|
|
139
|
+
for i in res:
|
|
140
|
+
while remplacement_temporaire in i:
|
|
141
|
+
i = i.replace(remplacement_temporaire,
|
|
142
|
+
entre_caractere_regroupant[0][1: -1] if not garder_carractere_regroupant else
|
|
143
|
+
entre_caractere_regroupant[0], 1)
|
|
144
|
+
entre_caractere_regroupant.pop(0)
|
|
145
|
+
result.append(i)
|
|
146
|
+
return result
|
Dshell/__init__.py
ADDED
Dshell/_utils.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
NoneType = type(None)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dshellInterpreter
|
|
3
|
+
Version: 0.2.21.7
|
|
4
|
+
Summary: A Discord bot interpreter for creating custom commands and automations.
|
|
5
|
+
Home-page: https://github.com/BOXERRMD/Dshell_Interpreter
|
|
6
|
+
Author: Chronos
|
|
7
|
+
Author-email: vagabonwalybi@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Bug Tracker, https://github.com/BOXERRMD/Dshell_Interpreter/issues
|
|
10
|
+
Project-URL: Source, https://github.com/BOXERRMD/Dshell_Interpreter
|
|
11
|
+
Keywords: discord bot interpreter automation commands
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Requires-Python: >=3.9
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: py-cord==2.6.1
|
|
19
|
+
Requires-Dist: requests
|
|
20
|
+
Requires-Dist: pycordviews
|
|
21
|
+
Dynamic: author
|
|
22
|
+
Dynamic: author-email
|
|
23
|
+
Dynamic: classifier
|
|
24
|
+
Dynamic: description
|
|
25
|
+
Dynamic: description-content-type
|
|
26
|
+
Dynamic: home-page
|
|
27
|
+
Dynamic: keywords
|
|
28
|
+
Dynamic: license
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
Dynamic: project-url
|
|
31
|
+
Dynamic: requires-dist
|
|
32
|
+
Dynamic: requires-python
|
|
33
|
+
Dynamic: summary
|
|
34
|
+
|
|
35
|
+
# Dshell_Interpreter
|
|
36
|
+
|
|
37
|
+
Python interpreter for Discord.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Dshell/__init__.py,sha256=gEgfeYoyHn4bUepMd0F-MSx36rR8WgQGxNpgDKo2qbA,136
|
|
2
|
+
Dshell/_utils.py,sha256=PJ3fwn8IMqUMnW9oTwfr9v4--rzHIhhLQoVVqjwjoJU,23
|
|
3
|
+
Dshell/DISCORD_COMMANDS/__init__.py,sha256=87-YpGU74m-m7AqUQni7PGbw73JRlioQkywW_61Whms,208
|
|
4
|
+
Dshell/DISCORD_COMMANDS/dshell_channel.py,sha256=Zpgrhh8XGbrG7XGZqyeGsoMJFsVtmIl7Cpw8OtngiI4,23883
|
|
5
|
+
Dshell/DISCORD_COMMANDS/dshell_interaction.py,sha256=5FA8JZ2_v98ZzOZl6EKyjo_fUQC7FuK6C6hij6ZSP30,3495
|
|
6
|
+
Dshell/DISCORD_COMMANDS/dshell_member.py,sha256=5Iw-2dydhYMZOw2nx0svZP9JpZWHOXC0qkL9tClJHtw,8840
|
|
7
|
+
Dshell/DISCORD_COMMANDS/dshell_message.py,sha256=CHbNHF5hInGfL9xjKTID-rnlRZipwyRtTJD9bPxmMUc,15315
|
|
8
|
+
Dshell/DISCORD_COMMANDS/dshell_pastbin.py,sha256=H0tUJOwdzYBXvxqipK3mzoNZUKrSLcVm4EZlWbBRScs,796
|
|
9
|
+
Dshell/DISCORD_COMMANDS/dshell_role.py,sha256=t_yRZRD0FKE2gT4dIDIsHz2PSZZztDVEkkqkG_OkNh4,5002
|
|
10
|
+
Dshell/DISCORD_COMMANDS/utils/__init__.py,sha256=X5F-fFCXD8Y7sia0b2q-7Fr1-MJj-aL5EupT-bAejzc,234
|
|
11
|
+
Dshell/DISCORD_COMMANDS/utils/utils_global.py,sha256=G_gH9iF6roT-0QR2FUZj6_P1ADr06JrxZgELOy9yIP8,4768
|
|
12
|
+
Dshell/DISCORD_COMMANDS/utils/utils_list.py,sha256=zqImMWvD-1UnbPP1TZewnvZpq7qs1sOTT1YhbJ5I8h8,3160
|
|
13
|
+
Dshell/DISCORD_COMMANDS/utils/utils_member.py,sha256=1EoHooxwijc7AFJGnuae3ccjQk0x69MELtZ5ES5abLY,1165
|
|
14
|
+
Dshell/DISCORD_COMMANDS/utils/utils_message.py,sha256=jHHgtUOw_5gTJMawfKlODQveBBRl6yillmJ-uzubh2o,3450
|
|
15
|
+
Dshell/DISCORD_COMMANDS/utils/utils_permissions.py,sha256=sCM7brCBOU4_WmLzcyrGYITgXVI4cdbQGZzWd97YKw8,4232
|
|
16
|
+
Dshell/DISCORD_COMMANDS/utils/utils_string.py,sha256=2LvJG_PR_VkPdnsw0vKNTwhEQGNog-3gFd_rZIUpGKc,4709
|
|
17
|
+
Dshell/DISCORD_COMMANDS/utils/utils_thread.py,sha256=tVl4msEwrWHY-0AytI6eY3JSs-eIFUigDSJfK9mT1ww,1457
|
|
18
|
+
Dshell/_DshellInterpreteur/__init__.py,sha256=03qR_fbu7UqzkQWNTUzSXwJUZgvQGMVJDOn31PHqcAY,158
|
|
19
|
+
Dshell/_DshellInterpreteur/cached_messages.py,sha256=BJuITd--iITD95MMuwCWVo2HPPlolIZ5FZVSLkTLVD4,156
|
|
20
|
+
Dshell/_DshellInterpreteur/dshell_arguments.py,sha256=cV9SHqOLAR-aIvkQocry1WaWc5ujyE5rh92g4Qwgj5A,2605
|
|
21
|
+
Dshell/_DshellInterpreteur/dshell_interpreter.py,sha256=DNF9JybvrVxJ0tVnGZ1enPS_JBkZCR5cqhsPrBSt_CM,31375
|
|
22
|
+
Dshell/_DshellInterpreteur/errors.py,sha256=0PJz_VYZfNZeKR_PEHxw3tRkgKNNUerV0wwrq2r1luA,250
|
|
23
|
+
Dshell/_DshellParser/__init__.py,sha256=ONDfhZMvClqP_6tE8SLjp-cf3pXL-auQYnfYRrHZxC4,56
|
|
24
|
+
Dshell/_DshellParser/ast_nodes.py,sha256=Ld5-Fo8xkj3T5-G6eF2j4EXRJgktRpi9DT9rBHrLdnw,19629
|
|
25
|
+
Dshell/_DshellParser/dshell_parser.py,sha256=QdAWRaYucf9UD7hHQ0Sl4guSuPL0RmY51wZTBDriDW0,19096
|
|
26
|
+
Dshell/_DshellTokenizer/__init__.py,sha256=LIQSRhDx2B9pmPx5ADMwwD0Xr9ybneVLhHH8qrJWw_s,172
|
|
27
|
+
Dshell/_DshellTokenizer/dshell_keywords.py,sha256=KDvq3V6yFNksVi_SBNhkl7QsTyYwjKibN8CqlQlIPms,7360
|
|
28
|
+
Dshell/_DshellTokenizer/dshell_token_type.py,sha256=fjqDg_wIUbmOziGM66iTL7X85axjWbGO_yEUKNIoURE,1573
|
|
29
|
+
Dshell/_DshellTokenizer/dshell_tokenizer.py,sha256=3-YjgX_ESJsCH7osdbQJr13f497nER8EQSAT95bheow,7231
|
|
30
|
+
dshellinterpreter-0.2.21.7.dist-info/licenses/LICENSE,sha256=lNgcw1_xb7QENAQi3uHGymaFtbs0RV-ihiCd7AoLQjA,1082
|
|
31
|
+
dshellinterpreter-0.2.21.7.dist-info/METADATA,sha256=BY1lOCs_D8uQHAdgVWwj6M9jfY4ULumPo-LMB73zvcY,1151
|
|
32
|
+
dshellinterpreter-0.2.21.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
33
|
+
dshellinterpreter-0.2.21.7.dist-info/top_level.txt,sha256=B4CMhtmchGwPQJLuqUy0GhRG-0cUGxKL4GqEbCiB_vE,7
|
|
34
|
+
dshellinterpreter-0.2.21.7.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 BOXER
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Dshell
|