PycordViews 1.1.0__tar.gz → 1.1.1__tar.gz
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-1.1.0 → pycordviews-1.1.1}/PKG-INFO +1 -1
- {pycordviews-1.1.0 → pycordviews-1.1.1}/PycordViews.egg-info/PKG-INFO +1 -1
- {pycordviews-1.1.0 → pycordviews-1.1.1}/PycordViews.egg-info/SOURCES.txt +12 -0
- {pycordviews-1.1.0 → pycordviews-1.1.1}/PycordViews.egg-info/top_level.txt +1 -0
- pycordviews-1.1.1/pycordViews/multibot/__init__.py +5 -0
- pycordviews-1.1.1/pycordViews/multibot/errors.py +10 -0
- pycordviews-1.1.1/pycordViews/multibot/process_for_bots.py +112 -0
- pycordviews-1.1.1/pycordViews/multibot/process_messages.py +7 -0
- pycordviews-1.1.1/pycordViews/multibot/runner.py +14 -0
- pycordviews-1.1.1/pycordViews/multibot/start_multibot.py +80 -0
- {pycordviews-1.1.0 → pycordviews-1.1.1}/setup.py +2 -2
- {pycordviews-1.1.0 → pycordviews-1.1.1}/LICENSE +0 -0
- {pycordviews-1.1.0 → pycordviews-1.1.1}/PycordViews.egg-info/dependency_links.txt +0 -0
- {pycordviews-1.1.0 → pycordviews-1.1.1}/PycordViews.egg-info/requires.txt +0 -0
- {pycordviews-1.1.0 → pycordviews-1.1.1}/README.md +0 -0
- {pycordviews-1.1.0 → pycordviews-1.1.1}/pycordViews/__init__.py +0 -0
- {pycordviews-1.1.0 → pycordviews-1.1.1}/pycordViews/menu/__init__.py +0 -0
- {pycordviews-1.1.0 → pycordviews-1.1.1}/pycordViews/menu/errors.py +0 -0
- {pycordviews-1.1.0 → pycordviews-1.1.1}/pycordViews/menu/menu.py +0 -0
- {pycordviews-1.1.0 → pycordviews-1.1.1}/pycordViews/menu/selectMenu.py +0 -0
- {pycordviews-1.1.0 → pycordviews-1.1.1}/pycordViews/pagination/__init__.py +0 -0
- {pycordviews-1.1.0 → pycordviews-1.1.1}/pycordViews/pagination/errors.py +0 -0
- {pycordviews-1.1.0 → pycordviews-1.1.1}/pycordViews/pagination/pagination_view.py +0 -0
- {pycordviews-1.1.0 → pycordviews-1.1.1}/pycordViews/typeViews.py +0 -0
- {pycordviews-1.1.0 → pycordviews-1.1.1}/pycordViews/views/__init__.py +0 -0
- {pycordviews-1.1.0 → pycordviews-1.1.1}/pycordViews/views/easy_modified_view.py +0 -0
- {pycordviews-1.1.0 → pycordviews-1.1.1}/pycordViews/views/errors.py +0 -0
- {pycordviews-1.1.0 → pycordviews-1.1.1}/pyproject.toml +0 -0
- {pycordviews-1.1.0 → pycordviews-1.1.1}/setup.cfg +0 -0
@@ -13,6 +13,12 @@ pycordViews/menu/__init__.py
|
|
13
13
|
pycordViews/menu/errors.py
|
14
14
|
pycordViews/menu/menu.py
|
15
15
|
pycordViews/menu/selectMenu.py
|
16
|
+
pycordViews/multibot/__init__.py
|
17
|
+
pycordViews/multibot/errors.py
|
18
|
+
pycordViews/multibot/process_for_bots.py
|
19
|
+
pycordViews/multibot/process_messages.py
|
20
|
+
pycordViews/multibot/runner.py
|
21
|
+
pycordViews/multibot/start_multibot.py
|
16
22
|
pycordViews/pagination/__init__.py
|
17
23
|
pycordViews/pagination/errors.py
|
18
24
|
pycordViews/pagination/pagination_view.py
|
@@ -23,6 +29,12 @@ pycordViews/menu/__init__.py
|
|
23
29
|
pycordViews/menu/errors.py
|
24
30
|
pycordViews/menu/menu.py
|
25
31
|
pycordViews/menu/selectMenu.py
|
32
|
+
pycordViews/multibot/__init__.py
|
33
|
+
pycordViews/multibot/errors.py
|
34
|
+
pycordViews/multibot/process_for_bots.py
|
35
|
+
pycordViews/multibot/process_messages.py
|
36
|
+
pycordViews/multibot/runner.py
|
37
|
+
pycordViews/multibot/start_multibot.py
|
26
38
|
pycordViews/pagination/__init__.py
|
27
39
|
pycordViews/pagination/errors.py
|
28
40
|
pycordViews/pagination/pagination_view.py
|
@@ -0,0 +1,112 @@
|
|
1
|
+
from discord import AutoShardedBot, Bot
|
2
|
+
from random import choice
|
3
|
+
from string import ascii_letters
|
4
|
+
from asyncio import set_event_loop, new_event_loop, sleep, run, create_task
|
5
|
+
from multiprocessing import Queue
|
6
|
+
|
7
|
+
from .errors import *
|
8
|
+
from .runner import Runner
|
9
|
+
from .process_messages import ProcessMessage
|
10
|
+
|
11
|
+
|
12
|
+
class ProcessBot:
|
13
|
+
|
14
|
+
def __init__(self, queue_parent: Queue, queue_children: Queue, limit_bots_in_tread: int = -1):
|
15
|
+
"""
|
16
|
+
Class to manage process and thread
|
17
|
+
"""
|
18
|
+
self.__threads: dict = {}
|
19
|
+
self.__all_bots: dict = {}
|
20
|
+
|
21
|
+
self.__limit_bots_in_tread: int = limit_bots_in_tread
|
22
|
+
|
23
|
+
self.__queue_parent: Queue = queue_parent
|
24
|
+
self.__queue_children: Queue = queue_children
|
25
|
+
self.__loop = None
|
26
|
+
run(self.run_process())
|
27
|
+
|
28
|
+
async def run_process(self):
|
29
|
+
"""
|
30
|
+
Function run with the process
|
31
|
+
"""
|
32
|
+
await create_task(self.__message_process_receiver()) # Run the process
|
33
|
+
|
34
|
+
async def __message_process_receiver(self):
|
35
|
+
"""
|
36
|
+
Wait message from parent process (always a dict with the key "parent_message")
|
37
|
+
"""
|
38
|
+
while True:
|
39
|
+
await sleep(0.02)
|
40
|
+
while not self.__queue_children.empty():
|
41
|
+
try:
|
42
|
+
message = self.__queue_children.get_nowait()
|
43
|
+
await self.__decode_message(message)
|
44
|
+
except:
|
45
|
+
break
|
46
|
+
|
47
|
+
def __message_process_sender(self, message: dict):
|
48
|
+
"""
|
49
|
+
Send a message to parent process
|
50
|
+
"""
|
51
|
+
self.__queue_parent.put(message)
|
52
|
+
|
53
|
+
async def __decode_message(self, message: dict):
|
54
|
+
"""
|
55
|
+
Decode the current message sent by the parent process
|
56
|
+
:param message: The message.
|
57
|
+
"""
|
58
|
+
action = message['parent_message']
|
59
|
+
|
60
|
+
if ProcessMessage.ADD_BOT.value == action:
|
61
|
+
self.add_bot(**message)
|
62
|
+
|
63
|
+
elif ProcessMessage.RUN_ALL.value == action:
|
64
|
+
print("run all bots")
|
65
|
+
|
66
|
+
def add_bot(self, token: str, *args, autoshared: bool = False, name: str = None, **kwargs) -> None:
|
67
|
+
"""
|
68
|
+
Add a bot in the instance to manage it.
|
69
|
+
Use this function to set the bot's intents and other subtleties.
|
70
|
+
:param name: The name of the bot to find it. If None, a random name is given
|
71
|
+
:param token: The token bot
|
72
|
+
:param autoshared: Autoshare the bot in Discord
|
73
|
+
:param args: all arguments of the Discord class Bot.
|
74
|
+
:param kwargs: all kwargs of the Discord class Bot
|
75
|
+
See : https://docs.pycord.dev/en/stable/api/clients.html#discord.Bot
|
76
|
+
"""
|
77
|
+
print(f"Ajout du bot {name} avec le token {token}")
|
78
|
+
if name is None:
|
79
|
+
name = ''.join([choice(ascii_letters) for _ in range(20)])
|
80
|
+
|
81
|
+
if autoshared:
|
82
|
+
self.__all_bots[name] = {'runner': Runner(AutoShardedBot(*args, **kwargs)),
|
83
|
+
'token': token,
|
84
|
+
'thread': None}
|
85
|
+
|
86
|
+
else:
|
87
|
+
self.__all_bots[name] = {'runner': Runner(Bot(*args, **kwargs)),
|
88
|
+
'token': token,
|
89
|
+
'thread': None}
|
90
|
+
|
91
|
+
print(f"Envoi de la réponse 'coucou' pour {name}")
|
92
|
+
self.__message_process_sender({'children_message': "coucou"})
|
93
|
+
|
94
|
+
|
95
|
+
def get_bots_names(self) -> list[str]:
|
96
|
+
"""
|
97
|
+
Return all bots names registered in the class.
|
98
|
+
"""
|
99
|
+
print('coucou', self.__event)
|
100
|
+
return list(self.__all_bots.keys())
|
101
|
+
|
102
|
+
|
103
|
+
def get_runner(self, name: str) -> "Runner":
|
104
|
+
"""
|
105
|
+
Run the bot runner associated with this name
|
106
|
+
:raise: BotNotFoundError
|
107
|
+
"""
|
108
|
+
|
109
|
+
if name not in self.__all_bots.keys():
|
110
|
+
raise BotNotFoundError(name)
|
111
|
+
|
112
|
+
return self.__all_bots[name]['runner']
|
@@ -0,0 +1,14 @@
|
|
1
|
+
from discord import AutoShardedBot, Bot
|
2
|
+
from typing import Union
|
3
|
+
|
4
|
+
class Runner:
|
5
|
+
|
6
|
+
def __init__(self, bot: Union[AutoShardedBot, Bot]):
|
7
|
+
"""
|
8
|
+
Run the bot
|
9
|
+
"""
|
10
|
+
self.bot: Union[AutoShardedBot, Bot] = bot
|
11
|
+
|
12
|
+
def __reduce__(self):
|
13
|
+
# Renvoyer un tuple avec les informations nécessaires pour reconstruire l'objet
|
14
|
+
return self.__class__, (self.bot,)
|
@@ -0,0 +1,80 @@
|
|
1
|
+
|
2
|
+
from typing import Union, Any
|
3
|
+
from multiprocessing import Process, Queue, set_start_method, get_start_method
|
4
|
+
from asyncio import create_task, sleep
|
5
|
+
from time import sleep as tsleep
|
6
|
+
|
7
|
+
from .process_for_bots import ProcessBot
|
8
|
+
from .process_messages import ProcessMessage
|
9
|
+
|
10
|
+
|
11
|
+
class Multibot:
|
12
|
+
|
13
|
+
def __init__(self, limit_bots_in_tread: int = 10):
|
14
|
+
"""
|
15
|
+
Create an instance of Multibot_asyncio class to manage few bots with asyncio.
|
16
|
+
:param limit_bots_in_tread: Max running bot in a single asyncio loop in a thread.
|
17
|
+
"""
|
18
|
+
if get_start_method() != "spawn":
|
19
|
+
set_start_method("spawn")
|
20
|
+
|
21
|
+
self.__queue_parent: Queue = Queue()
|
22
|
+
self.__queue_children: Queue = Queue()
|
23
|
+
|
24
|
+
self.__process: Union[Process] = Process(target=ProcessBot, args=(self.__queue_parent, self.__queue_children, limit_bots_in_tread)) # Process to run all bots
|
25
|
+
|
26
|
+
async def start_process(self) -> "Multibot":
|
27
|
+
"""
|
28
|
+
Start the process. It is required !
|
29
|
+
"""
|
30
|
+
self.__process.start()
|
31
|
+
create_task(self.__message_process_receiver())
|
32
|
+
|
33
|
+
def __message_process_sender(self, message: dict):
|
34
|
+
"""
|
35
|
+
Send a message to children process
|
36
|
+
"""
|
37
|
+
print(f"Message envoyé par le parent : {message}")
|
38
|
+
self.__queue_children.put(message)
|
39
|
+
|
40
|
+
async def __message_process_receiver(self):
|
41
|
+
"""
|
42
|
+
Wait message from children process (always a dict with the key "children_message")
|
43
|
+
"""
|
44
|
+
while True:
|
45
|
+
await sleep(0.02)
|
46
|
+
while not self.__queue_parent.empty():
|
47
|
+
try:
|
48
|
+
message = self.__queue_parent.get_nowait()
|
49
|
+
await self.__decode_message(message)
|
50
|
+
except:
|
51
|
+
break
|
52
|
+
|
53
|
+
async def __decode_message(self, message: Any):
|
54
|
+
"""
|
55
|
+
Decode the current message sent by the parent process
|
56
|
+
:param message: The message.
|
57
|
+
"""
|
58
|
+
print(message)
|
59
|
+
|
60
|
+
async def add_bot(self, token: str, name: str = None, autoshared: bool = False, **kwargs):
|
61
|
+
"""
|
62
|
+
Add a bot
|
63
|
+
"""
|
64
|
+
data = {
|
65
|
+
'parent_message': ProcessMessage.ADD_BOT.value,
|
66
|
+
'token': token,
|
67
|
+
'name': name,
|
68
|
+
'autoshared': autoshared,
|
69
|
+
}
|
70
|
+
data.update(kwargs)
|
71
|
+
|
72
|
+
self.__message_process_sender(data)
|
73
|
+
|
74
|
+
async def run_all_bots(self):
|
75
|
+
"""
|
76
|
+
Run all bots
|
77
|
+
"""
|
78
|
+
self.__message_process_sender({'parent_message': ProcessMessage.RUN_ALL.value})
|
79
|
+
|
80
|
+
|
@@ -5,7 +5,7 @@ with open("README.md") as file:
|
|
5
5
|
|
6
6
|
setup(
|
7
7
|
name="PycordViews",
|
8
|
-
version="1.1.
|
8
|
+
version="1.1.1",
|
9
9
|
url="https://github.com/BOXERRMD/Py-cord_Views",
|
10
10
|
author="Chronos (alias BOXERRMD)",
|
11
11
|
author_email="vagabonwalybi@gmail.com",
|
@@ -27,6 +27,6 @@ setup(
|
|
27
27
|
install_requires=[
|
28
28
|
"py-cord==2.6.1"
|
29
29
|
],
|
30
|
-
packages=['pycordViews', 'pycordViews/pagination', 'pycordViews/views', 'pycordViews/menu'],
|
30
|
+
packages=['pycordViews', 'pycordViews/pagination', 'pycordViews/views', 'pycordViews/menu', 'pycordViews/multibot'],
|
31
31
|
python_requires='>=3.9'
|
32
32
|
)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|