PycordViews 1.1.0__py3-none-any.whl → 1.1.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: PycordViews
3
- Version: 1.1.0
3
+ Version: 1.1.2
4
4
  Summary: Views for py-cord library
5
5
  Home-page: https://github.com/BOXERRMD/Py-cord_Views
6
6
  Author: Chronos (alias BOXERRMD)
@@ -0,0 +1,23 @@
1
+ pycordViews/__init__.py,sha256=SihgmXFTu75CxGmvRhVRHsRm4aDjMy8ZgiXfPuE3suE,223
2
+ pycordViews/typeViews.py,sha256=5q_-FTUGMg2QjA7bsjbb2ep41Y4sm2sBPTCOV6b5X1w,122
3
+ pycordViews/menu/__init__.py,sha256=SoAHnpJXxwTYDX5esYkgvSqpPqkuF1hDx22a-_U7ieU,83
4
+ pycordViews/menu/errors.py,sha256=0Um-oH5qMdWSZB_bGlqILsf9WSDtC4n_HwkheekiMV4,480
5
+ pycordViews/menu/menu.py,sha256=piouHpZLhHSo8MtJjx3eUp0zLzZoxj0n05pwdy0EJl4,1786
6
+ pycordViews/menu/selectMenu.py,sha256=lxgMfTFt-pEu1BRm1zqcJJgMpBWHwwuDtY4hOY4deyA,9809
7
+ pycordViews/multibot/__init__.py,sha256=fP7jipm2AfsNyMLGgh4TEhvASA7NrPSLhSl2hU_xkw4,175
8
+ pycordViews/multibot/errors.py,sha256=8C6jRRCOs3Y_tY_cvZIsGvz7XSreCkvWQ5ikj2hOf2s,238
9
+ pycordViews/multibot/process_for_bots.py,sha256=O7Drpyy_A4y1zQq2D3SXLySWLJPnz6WVdynvTPk8gKM,3920
10
+ pycordViews/multibot/process_messages.py,sha256=tt39bcfVOxTgo7_O4FPYA88spQMqx2Dvee1T2FyURmQ,108
11
+ pycordViews/multibot/runner.py,sha256=ZyHTDu-wdZFbnoyEC00qe8MTf-STqFvrXytUE8Hr-Ec,406
12
+ pycordViews/multibot/start_multibot.py,sha256=mHDBhiy7-Z3rvLbr8Ibqe9J9RXe_BusbZxq0aO3a16w,2598
13
+ pycordViews/pagination/__init__.py,sha256=Z9BcdoTWyC1KXGwQ1_C0tu9rkZpdrrjEHwMmjXsckeE,81
14
+ pycordViews/pagination/errors.py,sha256=CYb5gBcXx0kYDUDkNpfUrqSxQAcJE_qfpomWtUFOsTk,316
15
+ pycordViews/pagination/pagination_view.py,sha256=RRx4Ldr7RYp5n6-y7JttAu6fN_kD5QN9ROmuhkMCt_4,4307
16
+ pycordViews/views/__init__.py,sha256=yligptZmw-np8tjKLr76SVmi0807Nk6jCyKkKYLhbCY,89
17
+ pycordViews/views/easy_modified_view.py,sha256=19YYvV7b-Ej0MZnjg10cl9s7MkRkyUZlyKt0AeHGF2I,8146
18
+ pycordViews/views/errors.py,sha256=0NBjBDaSFZChJua1ho9qyfbNzwXy1U6Kcob5CCUxBK8,218
19
+ PycordViews-1.1.2.dist-info/LICENSE,sha256=lNgcw1_xb7QENAQi3uHGymaFtbs0RV-ihiCd7AoLQjA,1082
20
+ PycordViews-1.1.2.dist-info/METADATA,sha256=m9Qvfzm2X2Ubet-_sze-Pb8Fp1Vo3PAofquL_fi0frc,2897
21
+ PycordViews-1.1.2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
22
+ PycordViews-1.1.2.dist-info/top_level.txt,sha256=nqBU40KmnSCjtry8kmv97-RvZC-8xQrhrrloOJX2ROs,91
23
+ PycordViews-1.1.2.dist-info/RECORD,,
@@ -1,4 +1,5 @@
1
1
  pycordViews
2
2
  pycordViews/menu
3
+ pycordViews/multibot
3
4
  pycordViews/pagination
4
5
  pycordViews/views
@@ -0,0 +1,5 @@
1
+ from .start_multibot import Multibot
2
+ from .errors import *
3
+ from .runner import Runner
4
+ from .process_for_bots import ProcessBot
5
+ from .process_messages import ProcessMessage
@@ -0,0 +1,10 @@
1
+ class MultibotError(Exception):
2
+ pass
3
+
4
+
5
+ class BotNotFoundError(MultibotError):
6
+ """
7
+ If the bot is not found with the given name
8
+ """
9
+ def __init__(self, name: str):
10
+ super().__init__(f"{name} is not found")
@@ -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,7 @@
1
+ from enum import Enum
2
+
3
+
4
+ class ProcessMessage(Enum):
5
+
6
+ ADD_BOT = "add bot"
7
+ RUN_ALL = "run all"
@@ -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
+
@@ -135,7 +135,7 @@ class EasyModifiedViews(View):
135
135
  func = self.__callback[interaction.custom_id]['func']
136
136
 
137
137
  if func is not None:
138
- await func(self.__callback[interaction.custom_id]['ui'], interaction)
138
+ return await func(self.__callback[interaction.custom_id]['ui'], interaction)
139
139
 
140
140
  else:
141
141
  await interaction.response.defer(invisible=True)
@@ -1,17 +0,0 @@
1
- pycordViews/__init__.py,sha256=SihgmXFTu75CxGmvRhVRHsRm4aDjMy8ZgiXfPuE3suE,223
2
- pycordViews/typeViews.py,sha256=5q_-FTUGMg2QjA7bsjbb2ep41Y4sm2sBPTCOV6b5X1w,122
3
- pycordViews/menu/__init__.py,sha256=SoAHnpJXxwTYDX5esYkgvSqpPqkuF1hDx22a-_U7ieU,83
4
- pycordViews/menu/errors.py,sha256=0Um-oH5qMdWSZB_bGlqILsf9WSDtC4n_HwkheekiMV4,480
5
- pycordViews/menu/menu.py,sha256=piouHpZLhHSo8MtJjx3eUp0zLzZoxj0n05pwdy0EJl4,1786
6
- pycordViews/menu/selectMenu.py,sha256=lxgMfTFt-pEu1BRm1zqcJJgMpBWHwwuDtY4hOY4deyA,9809
7
- pycordViews/pagination/__init__.py,sha256=Z9BcdoTWyC1KXGwQ1_C0tu9rkZpdrrjEHwMmjXsckeE,81
8
- pycordViews/pagination/errors.py,sha256=CYb5gBcXx0kYDUDkNpfUrqSxQAcJE_qfpomWtUFOsTk,316
9
- pycordViews/pagination/pagination_view.py,sha256=RRx4Ldr7RYp5n6-y7JttAu6fN_kD5QN9ROmuhkMCt_4,4307
10
- pycordViews/views/__init__.py,sha256=yligptZmw-np8tjKLr76SVmi0807Nk6jCyKkKYLhbCY,89
11
- pycordViews/views/easy_modified_view.py,sha256=umura9gYSt15z6nc5-YfRAF80ZtfmHJ88mYqdTgpxzM,8139
12
- pycordViews/views/errors.py,sha256=0NBjBDaSFZChJua1ho9qyfbNzwXy1U6Kcob5CCUxBK8,218
13
- PycordViews-1.1.0.dist-info/LICENSE,sha256=lNgcw1_xb7QENAQi3uHGymaFtbs0RV-ihiCd7AoLQjA,1082
14
- PycordViews-1.1.0.dist-info/METADATA,sha256=XpezVMLNGPJeKlApWAhmRhSssz-D3f0Q-0m18zhgEnE,2897
15
- PycordViews-1.1.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
16
- PycordViews-1.1.0.dist-info/top_level.txt,sha256=kxuqvBlttJ3GI36DSbicXMygUS1AEOoA0WzzeYriSjE,70
17
- PycordViews-1.1.0.dist-info/RECORD,,