PycordViews 1.1.3__py3-none-any.whl → 1.2.0__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/__init__.py +2 -2
- pycordViews/menu/__init__.py +1 -1
- pycordViews/menu/menu.py +75 -14
- pycordViews/menu/selectMenu.py +29 -9
- pycordViews/multibot/__init__.py +1 -5
- pycordViews/multibot/bot.py +194 -0
- pycordViews/multibot/errors.py +25 -5
- pycordViews/multibot/multibot.py +206 -0
- pycordViews/multibot/process.py +217 -0
- pycordViews/pagination/pagination_view.py +7 -0
- pycordViews/views/easy_modified_view.py +40 -18
- pycordviews-1.2.0.dist-info/METADATA +241 -0
- pycordviews-1.2.0.dist-info/RECORD +21 -0
- {PycordViews-1.1.3.dist-info → pycordviews-1.2.0.dist-info}/WHEEL +1 -1
- PycordViews-1.1.3.dist-info/METADATA +0 -80
- PycordViews-1.1.3.dist-info/RECORD +0 -23
- pycordViews/multibot/process_for_bots.py +0 -112
- pycordViews/multibot/process_messages.py +0 -7
- pycordViews/multibot/runner.py +0 -14
- pycordViews/multibot/start_multibot.py +0 -80
- pycordViews/typeViews.py +0 -4
- {PycordViews-1.1.3.dist-info → pycordviews-1.2.0.dist-info/licenses}/LICENSE +0 -0
- {PycordViews-1.1.3.dist-info → pycordviews-1.2.0.dist-info}/top_level.txt +0 -0
@@ -1,80 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.2
|
2
|
-
Name: PycordViews
|
3
|
-
Version: 1.1.3
|
4
|
-
Summary: Views for py-cord library
|
5
|
-
Home-page: https://github.com/BOXERRMD/Py-cord_Views
|
6
|
-
Author: Chronos (alias BOXERRMD)
|
7
|
-
Author-email: vagabonwalybi@gmail.com
|
8
|
-
Maintainer: Chronos
|
9
|
-
License: MIT License
|
10
|
-
Classifier: Development Status :: 3 - Alpha
|
11
|
-
Classifier: License :: OSI Approved :: MIT License
|
12
|
-
Classifier: Natural Language :: English
|
13
|
-
Classifier: Operating System :: Microsoft :: Windows :: Windows 11
|
14
|
-
Classifier: Operating System :: Microsoft :: Windows :: Windows 10
|
15
|
-
Classifier: Operating System :: POSIX :: Linux
|
16
|
-
Classifier: Operating System :: MacOS
|
17
|
-
Classifier: Programming Language :: Python :: 3.9
|
18
|
-
Requires-Python: >=3.9
|
19
|
-
Description-Content-Type: text/markdown
|
20
|
-
License-File: LICENSE
|
21
|
-
Requires-Dist: py-cord==2.6.1
|
22
|
-
Dynamic: author
|
23
|
-
Dynamic: author-email
|
24
|
-
Dynamic: classifier
|
25
|
-
Dynamic: description
|
26
|
-
Dynamic: description-content-type
|
27
|
-
Dynamic: home-page
|
28
|
-
Dynamic: license
|
29
|
-
Dynamic: maintainer
|
30
|
-
Dynamic: requires-dist
|
31
|
-
Dynamic: requires-python
|
32
|
-
Dynamic: summary
|
33
|
-
|
34
|
-
# Py-cord_Views
|
35
|
-
Views for py-cord library
|
36
|
-
|
37
|
-
```python
|
38
|
-
from pycordViews.pagination import Pagination
|
39
|
-
from pycordViews.menu import SelectMenu
|
40
|
-
import discord
|
41
|
-
|
42
|
-
intents = discord.Intents.all()
|
43
|
-
bot = discord.AutoShardedBot(intents=intents)
|
44
|
-
|
45
|
-
@bot.command(name="My command paginator", description="...")
|
46
|
-
async def pagination_command(ctx):
|
47
|
-
"""
|
48
|
-
Create a command pagination
|
49
|
-
"""
|
50
|
-
pages: Pagination = Pagination(timeout=None, disabled_on_timeout=False)
|
51
|
-
|
52
|
-
pages.add_page(content="It's my first page !!", embed=None)# reset embed else he show the embed of the page after
|
53
|
-
|
54
|
-
embed = discord.Embed(title="My embed title", description="..........")
|
55
|
-
pages.add_page(content=None, embed=embed) # reset content else he show the content of the page before
|
56
|
-
|
57
|
-
pages.add_page(content="My last page !", embed=None)# reset embed else he show the embed of the page before
|
58
|
-
|
59
|
-
await pages.respond(ctx=ctx) # respond to the command
|
60
|
-
await pages.send(send_to=ctx.author) # send the message to the command author
|
61
|
-
|
62
|
-
@bot.command(name="My command select")
|
63
|
-
async def select_command(ctx):
|
64
|
-
"""
|
65
|
-
Create a command select
|
66
|
-
"""
|
67
|
-
async def your_response(select, interaction):
|
68
|
-
await interaction.response.send(f"You have selected {select.values[0]} !")
|
69
|
-
|
70
|
-
my_selector = SelectMenu(timeout=None, disabled_on_timeout=False) # A basic selector menu
|
71
|
-
my_menu = my_selector.add_string_select_menu(placeholder="Choice anything !") # add string_select UI
|
72
|
-
|
73
|
-
my_menu.add_option(label="My first choice !", emoji="😊", default=True, description="It's the first choice !", value='first choice')
|
74
|
-
my_menu.add_option(label="My second choice !", value='second choice')
|
75
|
-
my_menu.set_callable(your_response)
|
76
|
-
|
77
|
-
await my_selector.respond(ctx)
|
78
|
-
|
79
|
-
bot.run("Your token")
|
80
|
-
```
|
@@ -1,23 +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=8U1TNnfmTQTPCB1MtXGxrrs60qzL8L3JSDEw_PWfci0,9863
|
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=DDtKOKFiSuxeMtb-bzBbwARFdpdBXk8vaD96pd0VW7g,4385
|
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.3.dist-info/LICENSE,sha256=lNgcw1_xb7QENAQi3uHGymaFtbs0RV-ihiCd7AoLQjA,1082
|
20
|
-
PycordViews-1.1.3.dist-info/METADATA,sha256=X-FyiPYkSemLVNroGOi6Eiwxmd1aESuYS80M5PNJCIU,2897
|
21
|
-
PycordViews-1.1.3.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
22
|
-
PycordViews-1.1.3.dist-info/top_level.txt,sha256=nqBU40KmnSCjtry8kmv97-RvZC-8xQrhrrloOJX2ROs,91
|
23
|
-
PycordViews-1.1.3.dist-info/RECORD,,
|
@@ -1,112 +0,0 @@
|
|
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']
|
pycordViews/multibot/runner.py
DELETED
@@ -1,14 +0,0 @@
|
|
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,)
|
@@ -1,80 +0,0 @@
|
|
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
|
-
|
pycordViews/typeViews.py
DELETED
File without changes
|
File without changes
|