PycordViews 1.3.0__py3-none-any.whl → 1.3.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/errors.py +5 -1
- pycordViews/multibot/multibot.py +32 -2
- pycordViews/multibot/process.py +46 -3
- pycordViews/views/easy_modified_view.py +3 -3
- {pycordviews-1.3.0.dist-info → pycordviews-1.3.2.dist-info}/METADATA +1 -1
- {pycordviews-1.3.0.dist-info → pycordviews-1.3.2.dist-info}/RECORD +9 -9
- {pycordviews-1.3.0.dist-info → pycordviews-1.3.2.dist-info}/WHEEL +1 -1
- {pycordviews-1.3.0.dist-info → pycordviews-1.3.2.dist-info}/licenses/LICENSE +0 -0
- {pycordviews-1.3.0.dist-info → pycordviews-1.3.2.dist-info}/top_level.txt +0 -0
pycordViews/multibot/errors.py
CHANGED
@@ -27,4 +27,8 @@ class SetupCommandFunctionNotFound(MultibotError):
|
|
27
27
|
|
28
28
|
class CommandFileNotFoundError(MultibotError):
|
29
29
|
def __init__(self, file_name: str):
|
30
|
-
super().__init__(f"'{file_name}' file not found ! Init commands impossible
|
30
|
+
super().__init__(f"'{file_name}' file not found ! Init commands impossible !")
|
31
|
+
|
32
|
+
class ModuleNotFoundError(MultibotError):
|
33
|
+
def __init__(self, module_name: str):
|
34
|
+
super().__init__(f"{module_name} module not found !")
|
pycordViews/multibot/multibot.py
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
from queue import Empty
|
1
2
|
from multiprocessing import get_context
|
2
3
|
from multiprocessing.queues import Queue
|
3
4
|
from .process import ManageProcess
|
@@ -31,8 +32,10 @@ class Multibot:
|
|
31
32
|
try:
|
32
33
|
result = self.__process_queue.get(timeout=self.global_timeout)
|
33
34
|
return result
|
34
|
-
except:
|
35
|
+
except Empty:
|
35
36
|
return {'status': 'error', 'message': 'timeout request exceeded'}
|
37
|
+
except ValueError:
|
38
|
+
return {'status': 'critical error', 'message': 'queue was closed !'}
|
36
39
|
|
37
40
|
def _start_process(self):
|
38
41
|
"""
|
@@ -95,7 +98,15 @@ class Multibot:
|
|
95
98
|
self.__main_queue.put({'type': "RESTART", 'bot_name': bot_name})
|
96
99
|
results.append(self.__get_data_queue())
|
97
100
|
return results
|
98
|
-
|
101
|
+
|
102
|
+
def restart_all(self):
|
103
|
+
"""
|
104
|
+
Stop and restart all bots
|
105
|
+
This function is slow ! It's shutdown all bots properly.
|
106
|
+
"""
|
107
|
+
self.__main_queue.put({'type': "RESTARTALL"})
|
108
|
+
return self.__get_data_queue()
|
109
|
+
|
99
110
|
def start_all(self) -> list[dict[str, list[str]]]:
|
100
111
|
"""
|
101
112
|
Start all bots in the process.
|
@@ -111,6 +122,25 @@ class Multibot:
|
|
111
122
|
self.__main_queue.put({'type': "STOPALL"})
|
112
123
|
return self.__get_data_queue()
|
113
124
|
|
125
|
+
def add_modules(self, *modules_name):
|
126
|
+
"""
|
127
|
+
Adds modules (library) to the process (thus affecting bots).
|
128
|
+
Only previously removed modules can be added again!
|
129
|
+
To be run before launching a bot!
|
130
|
+
:param modules_name: names of modules to be added
|
131
|
+
"""
|
132
|
+
self.__main_queue.put({'type': "ADD_MODULES", 'modules_name': modules_name})
|
133
|
+
return self.__get_data_queue()
|
134
|
+
|
135
|
+
def remove_modules(self, *modules_name):
|
136
|
+
"""
|
137
|
+
Removes modules (library) to the process (thus affecting bots).
|
138
|
+
To be run before launching a bot!
|
139
|
+
:param modules_name: names of modules to be removed
|
140
|
+
"""
|
141
|
+
self.__main_queue.put({'type': "REMOVE_MODULES", 'modules_name': modules_name})
|
142
|
+
return self.__get_data_queue()
|
143
|
+
|
114
144
|
def is_started(self, bot_name: str) -> bool:
|
115
145
|
"""
|
116
146
|
Return the current Websocket connexion status
|
pycordViews/multibot/process.py
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
from multiprocessing import Queue
|
2
|
-
from .errors import BotAlreadyExistError, BotNotFoundError, MultibotError, BotNotStartedError
|
2
|
+
from .errors import BotAlreadyExistError, BotNotFoundError, MultibotError, BotNotStartedError, ModuleNotFoundError
|
3
3
|
from .bot import DiscordBot
|
4
4
|
from discord import Intents
|
5
5
|
from immutableType import Str_
|
6
|
-
from
|
6
|
+
from sys import modules
|
7
|
+
from os import system
|
7
8
|
|
8
9
|
class ManageProcess:
|
9
10
|
|
@@ -14,6 +15,7 @@ class ManageProcess:
|
|
14
15
|
self.__bots: dict[str, DiscordBot] = {}
|
15
16
|
self.main_queue: Queue = main_queue
|
16
17
|
self.process_queue: Queue = process_queue
|
18
|
+
self.removed_modules: dict[str, "ModuleType"] = {}
|
17
19
|
|
18
20
|
self.commandes = {
|
19
21
|
"ADD": self.add_bot_to_process,
|
@@ -26,13 +28,16 @@ class ManageProcess:
|
|
26
28
|
"IS_WS_RATELIMITED": self.is_ws_ratelimited,
|
27
29
|
"STOPALL": self.stop_all_bot_to_process,
|
28
30
|
"STARTALL": self.start_all_bot_to_process,
|
31
|
+
"RESTARTALL": self.restart_all_bot_to_process,
|
29
32
|
"BOT_COUNT": self.bot_count,
|
30
33
|
"STARTED_BOT_COUNT": self.started_bot_count,
|
31
34
|
"SHUTDOWN_BOT_COUNT": self.shutdown_bot_count,
|
32
35
|
"BOTS_bot_name": self.get_bots_bot_name,
|
33
36
|
"RELOAD_COMMANDS": self.reload_all_commands,
|
34
37
|
"ADD_COMMAND_FILE": self.add_pyFile_commands,
|
35
|
-
"MODIFY_COMMAND_FILE": self.modify_pyFile_commands
|
38
|
+
"MODIFY_COMMAND_FILE": self.modify_pyFile_commands,
|
39
|
+
"REMOVE_MODULES": self.remove_modules,
|
40
|
+
"ADD_MODULES": self.add_modules
|
36
41
|
}
|
37
42
|
|
38
43
|
def run(self):
|
@@ -82,6 +87,15 @@ class ManageProcess:
|
|
82
87
|
self.__bots[bot_name].reload_pyFile_commands()
|
83
88
|
return f'{bot_name} bot restarted'
|
84
89
|
|
90
|
+
def restart_all_bot_to_process(self) -> list[str]:
|
91
|
+
"""
|
92
|
+
Redémarre tous les bots du processus
|
93
|
+
"""
|
94
|
+
result = []
|
95
|
+
for bot in self.__bots.keys():
|
96
|
+
result.append(self.restart_bot_to_process(bot))
|
97
|
+
return result
|
98
|
+
|
85
99
|
def start_all_bot_to_process(self) -> list[str]:
|
86
100
|
"""
|
87
101
|
Start tous les bots du processus
|
@@ -166,6 +180,35 @@ class ManageProcess:
|
|
166
180
|
del self.__bots[bot_name]
|
167
181
|
return f'Bot {bot_name} removed'
|
168
182
|
|
183
|
+
def remove_modules(self, modules_name: tuple[str]):
|
184
|
+
"""
|
185
|
+
Enlève les modules (bibliothèque) de tous le processus (affecte donc les bots).
|
186
|
+
A éxécuter avant de lancer un bot !
|
187
|
+
:param modules_name: Tuple contenant les noms des modules à enlever
|
188
|
+
"""
|
189
|
+
for module in modules_name:
|
190
|
+
if module in modules_name:
|
191
|
+
self.removed_modules[module] = modules.pop(module)
|
192
|
+
else:
|
193
|
+
system(f"pip uninstall {module}")
|
194
|
+
#raise ModuleNotFoundError(module)
|
195
|
+
return f"[{', '.join(modules_name)}] modules removed"
|
196
|
+
|
197
|
+
def add_modules(self, modules_name: tuple[str]):
|
198
|
+
"""
|
199
|
+
Ajoute les modules (bibliothèque) de tous le processus (affecte donc les bots).
|
200
|
+
Uniquement les modules enlever au préalable peuvent-être de nouveau ajouter !
|
201
|
+
A éxécuter avant de lancer un bot !
|
202
|
+
:param modules_name: Tuple contenant les noms des modules à ajouter
|
203
|
+
"""
|
204
|
+
for module in modules_name:
|
205
|
+
if module in self.removed_modules.keys():
|
206
|
+
modules[module] = self.removed_modules.pop(module)
|
207
|
+
else:
|
208
|
+
system(f"pip install {module}")
|
209
|
+
#raise ModuleNotFoundError(module)
|
210
|
+
return f"[{', '.join(modules_name)}] modules added"
|
211
|
+
|
169
212
|
def is_started(self, bot_name: str) -> bool:
|
170
213
|
"""
|
171
214
|
Regarde si la connexion au Websocket est effectué
|
@@ -290,14 +290,14 @@ class EasyModifiedViews(View):
|
|
290
290
|
|
291
291
|
await self._update()
|
292
292
|
|
293
|
-
def on_timeout(self) -> None:
|
293
|
+
async def on_timeout(self) -> None:
|
294
294
|
"""
|
295
295
|
Called if timeout view is finished
|
296
296
|
"""
|
297
297
|
if self.__disabled_on_timeout:
|
298
|
-
|
298
|
+
await self.shutdown()
|
299
299
|
if self.__call_on_timeout is not None:
|
300
|
-
|
300
|
+
await self.__call_on_timeout(self.__ctx)
|
301
301
|
|
302
302
|
def call_on_timeout(self, _callable: Callable) -> None:
|
303
303
|
"""
|
@@ -11,18 +11,18 @@ pycordViews/modal/easy_modal_view.py,sha256=sNxfSg6sgoiKa3vc6eKa4RV7vNVNaSrI1XUJ
|
|
11
11
|
pycordViews/modal/errors.py,sha256=nIGYyOS_oWH49Dj8ZGW53nnzaPmbvFbAo7ydikD5xWE,307
|
12
12
|
pycordViews/multibot/__init__.py,sha256=93Q_URiRUMsvwQJIqUnb75aq6SPM83yteSMrH0rmXMg,30
|
13
13
|
pycordViews/multibot/bot.py,sha256=pD-BPXNo7JeJPguTn7qLii0UzBSS4ITvmOPv8htKJG8,8284
|
14
|
-
pycordViews/multibot/errors.py,sha256=
|
15
|
-
pycordViews/multibot/multibot.py,sha256=
|
16
|
-
pycordViews/multibot/process.py,sha256
|
14
|
+
pycordViews/multibot/errors.py,sha256=sPl_mM6b72Q8uuz4JkocO0TKBQ_9R3f0yT5eGhH_-PY,1328
|
15
|
+
pycordViews/multibot/multibot.py,sha256=A_abouhHcellnBNbgN7uF9UheApQwptfUuDt2tZQZZc,9253
|
16
|
+
pycordViews/multibot/process.py,sha256=-rJTw6ACfvMMinoAhQVGqPx76m0Nai5nymtDv1LrnxQ,10239
|
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
|
20
20
|
pycordViews/pagination/pagination_view.py,sha256=t6wvTLNTYg-w4eJQiyiX-LmEeR385SChifUzhiVSZBs,5793
|
21
21
|
pycordViews/views/__init__.py,sha256=yligptZmw-np8tjKLr76SVmi0807Nk6jCyKkKYLhbCY,89
|
22
|
-
pycordViews/views/easy_modified_view.py,sha256=
|
22
|
+
pycordViews/views/easy_modified_view.py,sha256=dOiSZ59zthRUV6s-mzdnql0o-z6hQM2ppKShJjmipu0,13992
|
23
23
|
pycordViews/views/errors.py,sha256=AkhGskuBjbFs0ZQdTDlVyfvAJ1WRMMQx2sAXUnYjmog,360
|
24
|
-
pycordviews-1.3.
|
25
|
-
pycordviews-1.3.
|
26
|
-
pycordviews-1.3.
|
27
|
-
pycordviews-1.3.
|
28
|
-
pycordviews-1.3.
|
24
|
+
pycordviews-1.3.2.dist-info/licenses/LICENSE,sha256=lNgcw1_xb7QENAQi3uHGymaFtbs0RV-ihiCd7AoLQjA,1082
|
25
|
+
pycordviews-1.3.2.dist-info/METADATA,sha256=CPNqQ9wvXSnbUA7CBeZ0nqT_zZ2wMRxFygoNS9upTwY,12417
|
26
|
+
pycordviews-1.3.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
27
|
+
pycordviews-1.3.2.dist-info/top_level.txt,sha256=3NvgH6MjESe7Q6jb6aqHgdYrYb5NhxwxnoDyE6PkThY,125
|
28
|
+
pycordviews-1.3.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|