PycordViews 1.3.6.1__py3-none-any.whl → 1.3.6.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.
- pycordViews/multibot/bot.py +1 -1
- pycordViews/multibot/multibot.py +2 -1
- pycordViews/multibot/process.py +35 -1
- {pycordviews-1.3.6.1.dist-info → pycordviews-1.3.6.2.dist-info}/METADATA +8 -1
- {pycordviews-1.3.6.1.dist-info → pycordviews-1.3.6.2.dist-info}/RECORD +8 -8
- {pycordviews-1.3.6.1.dist-info → pycordviews-1.3.6.2.dist-info}/WHEEL +0 -0
- {pycordviews-1.3.6.1.dist-info → pycordviews-1.3.6.2.dist-info}/licenses/LICENSE +0 -0
- {pycordviews-1.3.6.1.dist-info → pycordviews-1.3.6.2.dist-info}/top_level.txt +0 -0
pycordViews/multibot/bot.py
CHANGED
@@ -77,7 +77,7 @@ class DiscordBot:
|
|
77
77
|
|
78
78
|
def modify_pyFile_commands(self, file: str, setup_function: str):
|
79
79
|
"""
|
80
|
-
Modifie un fichier de
|
80
|
+
Modifie un fichier de commandes et le recharge.
|
81
81
|
Ne recharge que le fichier et non les commandes du bot !
|
82
82
|
:param file: Le chemin d'accès relatif ou absolue du fichier
|
83
83
|
"""
|
pycordViews/multibot/multibot.py
CHANGED
@@ -199,7 +199,7 @@ class Multibot:
|
|
199
199
|
request_type = "RELOAD_COMMANDS"
|
200
200
|
result = []
|
201
201
|
for name in bot_names:
|
202
|
-
self.__main_queue.put({'type': request_type, '
|
202
|
+
self.__main_queue.put({'type': request_type, 'bot_name': name})
|
203
203
|
result.append(self.__get_data_queue(request_type))
|
204
204
|
return result
|
205
205
|
|
@@ -231,6 +231,7 @@ class Multibot:
|
|
231
231
|
Reloads only the file, not the bot commands!
|
232
232
|
:param bot_name: The bot's name
|
233
233
|
:param file: The file's relative or absolute path
|
234
|
+
:param setup_function: Function name called by the process to give the Bot instance. Set to 'setup' by default.
|
234
235
|
"""
|
235
236
|
request_type = "MODIFY_COMMAND_FILE"
|
236
237
|
self.__main_queue.put({'type': request_type,
|
pycordViews/multibot/process.py
CHANGED
@@ -5,6 +5,7 @@ from discord import Intents
|
|
5
5
|
from immutableType import Str_
|
6
6
|
from sys import modules
|
7
7
|
from os import system
|
8
|
+
from psutil import Process
|
8
9
|
|
9
10
|
class ManageProcess:
|
10
11
|
|
@@ -16,6 +17,8 @@ class ManageProcess:
|
|
16
17
|
self.main_queue: Queue = main_queue
|
17
18
|
self.process_queue: Queue = process_queue
|
18
19
|
self.removed_modules: dict[str, "ModuleType"] = {}
|
20
|
+
self.allow_create_subprocess: bool = True
|
21
|
+
self.process: Process = Process()
|
19
22
|
|
20
23
|
self.commandes = {
|
21
24
|
"ADD": self.add_bot_to_process,
|
@@ -37,7 +40,8 @@ class ManageProcess:
|
|
37
40
|
"ADD_COMMAND_FILE": self.add_pyFile_commands,
|
38
41
|
"MODIFY_COMMAND_FILE": self.modify_pyFile_commands,
|
39
42
|
"REMOVE_MODULES": self.remove_modules,
|
40
|
-
"ADD_MODULES": self.add_modules
|
43
|
+
"ADD_MODULES": self.add_modules,
|
44
|
+
"ALLOW_SUBPROCESS": self.allow_subprocess
|
41
45
|
}
|
42
46
|
|
43
47
|
def run(self):
|
@@ -45,6 +49,7 @@ class ManageProcess:
|
|
45
49
|
Boucle principale du processus, écoute la queue principale.
|
46
50
|
Doit comporter aubligatoirement un dictionnaire avec la clé 'type'
|
47
51
|
"""
|
52
|
+
wait_for = 0 # secondes avant de forcer la fermeture des subprocess
|
48
53
|
while True:
|
49
54
|
if not self.main_queue.empty():
|
50
55
|
command: dict = self.main_queue.get()
|
@@ -59,6 +64,16 @@ class ManageProcess:
|
|
59
64
|
except MultibotError as e:
|
60
65
|
self.process_queue.put({'status': 'error', 'message': e, 'type': type_request})
|
61
66
|
|
67
|
+
if not self.allow_create_subprocess and wait_for > 50000 and (childrens_process := self.process.children()):
|
68
|
+
for i in childrens_process:
|
69
|
+
try:
|
70
|
+
i.kill()
|
71
|
+
except Exception:
|
72
|
+
pass
|
73
|
+
finally:
|
74
|
+
wait_for = 0
|
75
|
+
wait_for += 1
|
76
|
+
|
62
77
|
def start_bot_to_process(self, bot_name: str) -> str:
|
63
78
|
"""
|
64
79
|
Lance un unique bot
|
@@ -156,6 +171,15 @@ class ManageProcess:
|
|
156
171
|
file = Str_(file).str_
|
157
172
|
self.__bots[bot_name].modify_pyFile_commands(file=file, setup_function=setup_function)
|
158
173
|
|
174
|
+
def remove_pyFile_commands(self, bot_name: str, file: str):
|
175
|
+
"""
|
176
|
+
Enlève un fichier de commandes et toutes ses commandes du bot.
|
177
|
+
:param bot_name: Le nom du bot
|
178
|
+
:param file: Le chemin d'accès relatif ou absolue du fichier
|
179
|
+
"""
|
180
|
+
self.if_bot_no_exist(bot_name)
|
181
|
+
file = Str_(file).str_
|
182
|
+
self.__bots[bot_name].remove_pyFile_commands(file=file)
|
159
183
|
|
160
184
|
def reload_all_commands(self, bot_name: str):
|
161
185
|
"""
|
@@ -271,3 +295,13 @@ class ManageProcess:
|
|
271
295
|
Renvoie tous les noms des bots entrée par l'utilisateur
|
272
296
|
"""
|
273
297
|
return list(self.__bots.keys())
|
298
|
+
|
299
|
+
def allow_subprocess(self, allow: bool) -> str:
|
300
|
+
"""
|
301
|
+
Permet ou non l'utilisation de subprocess dans les bots.
|
302
|
+
ATTENTION : Peut poser des problèmes de sécurité si un utilisateur malveillant à accès au code.
|
303
|
+
Par défaut, False.
|
304
|
+
:param allow: True pour autoriser, False pour interdire
|
305
|
+
"""
|
306
|
+
self.allow_create_subprocess = allow
|
307
|
+
return f'Subprocess allowed: {allow}'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: PycordViews
|
3
|
-
Version: 1.3.6.
|
3
|
+
Version: 1.3.6.2
|
4
4
|
Summary: Views and multibot for py-cord library
|
5
5
|
Home-page: https://github.com/BOXERRMD/Py-cord_Views
|
6
6
|
Author: Chronos (alias BOXERRMD)
|
@@ -19,6 +19,7 @@ Requires-Python: >=3.9
|
|
19
19
|
Description-Content-Type: text/markdown
|
20
20
|
License-File: LICENSE
|
21
21
|
Requires-Dist: immutable-Python-type
|
22
|
+
Requires-Dist: psutil
|
22
23
|
Dynamic: author
|
23
24
|
Dynamic: author-email
|
24
25
|
Dynamic: classifier
|
@@ -35,6 +36,10 @@ Dynamic: summary
|
|
35
36
|
# Py-cord_Views
|
36
37
|
Views for py-cord library
|
37
38
|
|
39
|
+
DO NOT USE **MULTIBOT** CLASS FOR COMMERCIAL PURPOSES!
|
40
|
+
BOTS ARE NOT SEPARATED FROM EACH OTHER WHEN THEY ARE IN THE SAME PROCESS.
|
41
|
+
EACH BOT CAN ACCESS INFORMATION FROM OTHER BOTS CONTAINED IN THE SAME PROCESS.
|
42
|
+
|
38
43
|
# Paginator
|
39
44
|
The paginator instance is used to create a view acting as a “book”, with pages that can be turned using buttons.
|
40
45
|
## `Paginator`
|
@@ -226,6 +231,8 @@ Each instance of this class creates a process where bots can be added. These bot
|
|
226
231
|
> > ```
|
227
232
|
>
|
228
233
|
> > **Method** `modify_pyFile_commands(bot_name: str, file: str, setup_function: str = 'setup') -> dict[str, str]` : Modify python discord command file and setup function. This method doesn't reload automatically commands on the bot. Use `reload_commands` after. `file` parameter require a file path, absolute or not.
|
234
|
+
>
|
235
|
+
> > **Method** `allow_subprocess(allow: bool) -> dict[str, str]` : Allow or disallow the use of subprocess to all bots in the current process. By default, it's allowed.
|
229
236
|
>
|
230
237
|
> > **@property** `bot_count -> int` : Return the total number of bots
|
231
238
|
>
|
@@ -10,10 +10,10 @@ pycordViews/modal/__init__.py,sha256=TFUX3z25oInBhBzoOQhnLbKmwArXo4IVVqBfN6y11Bo
|
|
10
10
|
pycordViews/modal/easy_modal_view.py,sha256=sNxfSg6sgoiKa3vc6eKa4RV7vNVNaSrI1XUJ9RMSD80,4281
|
11
11
|
pycordViews/modal/errors.py,sha256=nIGYyOS_oWH49Dj8ZGW53nnzaPmbvFbAo7ydikD5xWE,307
|
12
12
|
pycordViews/multibot/__init__.py,sha256=93Q_URiRUMsvwQJIqUnb75aq6SPM83yteSMrH0rmXMg,30
|
13
|
-
pycordViews/multibot/bot.py,sha256=
|
13
|
+
pycordViews/multibot/bot.py,sha256=kjT-PDi2bRPuDWY-lX7aUiv7aki8pNdu8MszeWQsWJ8,8285
|
14
14
|
pycordViews/multibot/errors.py,sha256=sPl_mM6b72Q8uuz4JkocO0TKBQ_9R3f0yT5eGhH_-PY,1328
|
15
|
-
pycordViews/multibot/multibot.py,sha256=
|
16
|
-
pycordViews/multibot/process.py,sha256=
|
15
|
+
pycordViews/multibot/multibot.py,sha256=V8h500AnPHrArSCCbbnl2sqVHbR7bpnxbWC9DkWFtcE,10884
|
16
|
+
pycordViews/multibot/process.py,sha256=GrxNe336IQZhNl0OqWsTzXlbshjkczRTicRs6O8rP78,11821
|
17
17
|
pycordViews/pagination/__init__.py,sha256=rvOp-nGXZ6EX_ojK1_1lcOHYUcrB0LG3DL7zwatkRPY,105
|
18
18
|
pycordViews/pagination/errors.py,sha256=CYb5gBcXx0kYDUDkNpfUrqSxQAcJE_qfpomWtUFOsTk,316
|
19
19
|
pycordViews/pagination/page.py,sha256=sKi_gCFt1euY7uJKWgMnxEqP1B4LMhUysxQ8oQbhNVQ,1147
|
@@ -21,8 +21,8 @@ pycordViews/pagination/pagination_view.py,sha256=t6wvTLNTYg-w4eJQiyiX-LmEeR385SC
|
|
21
21
|
pycordViews/views/__init__.py,sha256=yligptZmw-np8tjKLr76SVmi0807Nk6jCyKkKYLhbCY,89
|
22
22
|
pycordViews/views/easy_modified_view.py,sha256=3WM3dFflPjIK6_8cXrSsLK27dAqnEZ0kKDq4-wQ8HMo,14042
|
23
23
|
pycordViews/views/errors.py,sha256=AkhGskuBjbFs0ZQdTDlVyfvAJ1WRMMQx2sAXUnYjmog,360
|
24
|
-
pycordviews-1.3.6.
|
25
|
-
pycordviews-1.3.6.
|
26
|
-
pycordviews-1.3.6.
|
27
|
-
pycordviews-1.3.6.
|
28
|
-
pycordviews-1.3.6.
|
24
|
+
pycordviews-1.3.6.2.dist-info/licenses/LICENSE,sha256=lNgcw1_xb7QENAQi3uHGymaFtbs0RV-ihiCd7AoLQjA,1082
|
25
|
+
pycordviews-1.3.6.2.dist-info/METADATA,sha256=riItVkeXhPrN5wxLOYVtkCN-T1XG2Ll0Awp0ojFKYpg,13435
|
26
|
+
pycordviews-1.3.6.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
27
|
+
pycordviews-1.3.6.2.dist-info/top_level.txt,sha256=3NvgH6MjESe7Q6jb6aqHgdYrYb5NhxwxnoDyE6PkThY,125
|
28
|
+
pycordviews-1.3.6.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|