PycordViews 1.2.15__py3-none-any.whl → 1.2.19__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/kit/confirm.py +1 -1
- pycordViews/kit/poll.py +2 -2
- pycordViews/pagination/pagination_view.py +1 -1
- pycordViews/views/easy_modified_view.py +41 -7
- {pycordviews-1.2.15.dist-info → pycordviews-1.2.19.dist-info}/METADATA +2 -2
- {pycordviews-1.2.15.dist-info → pycordviews-1.2.19.dist-info}/RECORD +9 -9
- {pycordviews-1.2.15.dist-info → pycordviews-1.2.19.dist-info}/WHEEL +1 -1
- {pycordviews-1.2.15.dist-info → pycordviews-1.2.19.dist-info}/licenses/LICENSE +0 -0
- {pycordviews-1.2.15.dist-info → pycordviews-1.2.19.dist-info}/top_level.txt +0 -0
pycordViews/kit/confirm.py
CHANGED
@@ -23,7 +23,7 @@ class Confirm:
|
|
23
23
|
|
24
24
|
self.__future: Future = get_event_loop().create_future()
|
25
25
|
|
26
|
-
async def _confirm(self, button: Button, interaction: Interaction):
|
26
|
+
async def _confirm(self, button: Button, interaction: Interaction, data):
|
27
27
|
"""
|
28
28
|
Base asynchronous _confirm function called when button is pressed
|
29
29
|
"""
|
pycordViews/kit/poll.py
CHANGED
@@ -100,7 +100,7 @@ class Poll:
|
|
100
100
|
if _callable is not None:
|
101
101
|
self.__view.set_callable(self.__button_no.custom_id, _callable=_callable)
|
102
102
|
|
103
|
-
async def yes(self, button, interaction):
|
103
|
+
async def yes(self, button, interaction, data):
|
104
104
|
"""
|
105
105
|
Base asynchronous function when "yes" button is pressed.
|
106
106
|
Increment “yes_count” attribute when pressed and respond with an ephemeral message.
|
@@ -113,7 +113,7 @@ class Poll:
|
|
113
113
|
self.__clicked_members.append(interaction.user.id)
|
114
114
|
await interaction.response.send_message(f"You have selected : {button.label}", ephemeral=True)
|
115
115
|
|
116
|
-
async def no(self, button, interaction):
|
116
|
+
async def no(self, button, interaction, data):
|
117
117
|
"""
|
118
118
|
Base asynchronous function when "no" button is pressed.
|
119
119
|
Increment “yes_count” attribute when pressed and respond with an ephemeral message.
|
@@ -60,7 +60,7 @@ class Pagination:
|
|
60
60
|
self.__view.get_ui('counter').label = f"{self.__current_page+1}/{len(self.__pages)}"
|
61
61
|
return self
|
62
62
|
|
63
|
-
async def __turn_page(self, button, interaction: Interaction):
|
63
|
+
async def __turn_page(self, button, interaction: Interaction, data):
|
64
64
|
"""
|
65
65
|
Turn the page when button is pressed
|
66
66
|
"""
|
@@ -1,5 +1,5 @@
|
|
1
1
|
from __future__ import annotations
|
2
|
-
from discord import Interaction, ApplicationContext, Message, Member
|
2
|
+
from discord import Interaction, ApplicationContext, Message, Member, Role
|
3
3
|
from discord.abc import GuildChannel
|
4
4
|
from discord.ui import View, Item
|
5
5
|
from typing import Union, Callable, TYPE_CHECKING, Optional, Any
|
@@ -68,11 +68,14 @@ class EasyModifiedViews(View):
|
|
68
68
|
|
69
69
|
if type(ui).__name__ in ('SelectMenu', 'Pagination', 'Confirm', 'Poll', 'EasyModifiedViews'):
|
70
70
|
for item in ui.get_view.items:
|
71
|
+
if type(ui).__name__ in ('SelectMenu', 'Pagination', 'Confirm', 'Poll', 'EasyModifiedViews'):
|
72
|
+
self.add_items(item)
|
73
|
+
continue
|
71
74
|
self.add_items(item)
|
72
75
|
self.set_callable(item.custom_id, _callable=ui.get_callable(item.custom_id), data=ui.get_callable_data(item.custom_id))
|
73
76
|
|
74
77
|
else:
|
75
|
-
self.__callback[ui.custom_id] = {'ui': ui, 'func': None, 'data': {}}
|
78
|
+
self.__callback[ui.custom_id] = {'ui': ui, 'func': None, 'data': {}, 'autorised_roles': None, 'autorised_key': None}
|
76
79
|
self.add_item(ui)
|
77
80
|
|
78
81
|
return self
|
@@ -96,7 +99,10 @@ class EasyModifiedViews(View):
|
|
96
99
|
await self._update()
|
97
100
|
return self
|
98
101
|
|
99
|
-
def set_callable_decorator(self, custom_id: str,
|
102
|
+
def set_callable_decorator(self, custom_id: str,
|
103
|
+
data: Optional[dict[str, Any]] = None,
|
104
|
+
autorised_roles : Optional[list[Union[int, Role]]] = None,
|
105
|
+
autorised_key: Optional[Callable] = None):
|
100
106
|
"""
|
101
107
|
Decorator to set up a callable for the item
|
102
108
|
|
@@ -114,31 +120,43 @@ class EasyModifiedViews(View):
|
|
114
120
|
|
115
121
|
:param custom_id: item ID of the view
|
116
122
|
:param data: Add any data to pass in called function.
|
123
|
+
:param autorised_roles: Any role ID allowed to interact with the view
|
124
|
+
:param autorised_key: Callable function to check anything. The function get the current interaction passed in parameter
|
117
125
|
"""
|
118
126
|
|
119
127
|
def decorator(_callable: Callable):
|
120
|
-
self.set_callable(custom_id,
|
128
|
+
self.set_callable(custom_id,
|
129
|
+
_callable=_callable,
|
130
|
+
data=data,
|
131
|
+
autorised_roles=autorised_roles,
|
132
|
+
autorised_key=autorised_key)
|
121
133
|
return _callable
|
122
134
|
|
123
135
|
return decorator
|
124
136
|
|
125
|
-
def set_callable(self, *custom_ids: str,
|
137
|
+
def set_callable(self, *custom_ids: str,
|
138
|
+
_callable: Callable,
|
139
|
+
data: Optional[dict[str, Any]] = None,
|
140
|
+
autorised_roles : Optional[list[Union[int, Role]]] = None,
|
141
|
+
autorised_key: Optional[Callable] = None):
|
126
142
|
"""
|
127
143
|
set up a callable for items
|
128
144
|
:param custom_ids: items IDs of the view
|
129
145
|
:param _callable: The asynchronous callable linked. Take UI (Button, Select...) and Interaction parameters.
|
130
146
|
:param data: Add any data to pass in called function.
|
147
|
+
:param autorised_roles: Any role ID allowed to interact with the view
|
148
|
+
:param autorised_key: Callable function to check anything. The function get the current interaction passed in parameter
|
131
149
|
|
132
150
|
**UI and Interaction parameter is required in callable function !**
|
133
151
|
|
134
152
|
view = EasyModifiedViews(None)
|
135
153
|
|
136
|
-
view.add_view(discord.ui.Button(label='coucou', custom_id='test_ID'
|
154
|
+
view.add_view(discord.ui.Button(label='coucou', custom_id='test_ID'))
|
137
155
|
|
138
156
|
async def rep(**UI**, **interaction**, data: dict[str, Any]):
|
139
157
|
await interaction.response.send_message(data['message'])
|
140
158
|
|
141
|
-
view.set_callable(custom_id='test_ID', callable=rep)
|
159
|
+
view.set_callable(custom_id='test_ID', callable=rep, data={'message': 'Hello !'})
|
142
160
|
await ctx.respond('coucou', view=view)
|
143
161
|
"""
|
144
162
|
for custom_id in custom_ids:
|
@@ -146,6 +164,11 @@ class EasyModifiedViews(View):
|
|
146
164
|
|
147
165
|
self.__callback[custom_id]['func'] = _callable
|
148
166
|
self.__callback[custom_id]['data'] = data if data is not None else {}
|
167
|
+
self.__callback[custom_id]['autorised_key'] = autorised_key
|
168
|
+
if autorised_roles is not None:
|
169
|
+
self.__callback[custom_id]['autorised_roles'] = [role.id if isinstance(role, Role) else role for role in autorised_roles if isinstance(role, (Role, int))]
|
170
|
+
else:
|
171
|
+
self.__callback[custom_id]['autorised_roles'] = None
|
149
172
|
|
150
173
|
def get_callable(self, custom_id: str) -> Union[Callable, None]:
|
151
174
|
"""
|
@@ -161,8 +184,19 @@ class EasyModifiedViews(View):
|
|
161
184
|
"""
|
162
185
|
func = self.__callback[interaction.custom_id]['func']
|
163
186
|
data = self.__callback[interaction.custom_id]['data']
|
187
|
+
autorised_roles = self.__callback[interaction.custom_id]['autorised_roles']
|
188
|
+
autorised_key = self.__callback[interaction.custom_id]['autorised_key']
|
164
189
|
|
165
190
|
if func is not None:
|
191
|
+
if autorised_roles is not None: # si des rôles sont obligatoires
|
192
|
+
if not (set(autorised_roles) & set([i.id for i in interaction.user.roles])): # si aucun rôle de l'user est dans les rôles aubligatoires
|
193
|
+
await interaction.response.defer(invisible=True)
|
194
|
+
return False
|
195
|
+
|
196
|
+
if autorised_key is not None: # si une fonction est config pour la vérification
|
197
|
+
if not autorised_key(interaction): # Si la fonction renvoie False
|
198
|
+
return False
|
199
|
+
|
166
200
|
return await func(self.__callback[interaction.custom_id]['ui'], interaction, data)
|
167
201
|
|
168
202
|
else:
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: PycordViews
|
3
|
-
Version: 1.2.
|
3
|
+
Version: 1.2.19
|
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)
|
@@ -95,7 +95,7 @@ The SelectMenu instance is used to create drop-down menus that can be easily mod
|
|
95
95
|
>
|
96
96
|
> > **Method** `add_mentionnable_select_menu(custom_id: str = None, placeholder: str = None, min_values: int = 1, max_values: int = 1, disabled=False, row=None) -> Menu` : Add a mentionable select menu in the ui. Return Menu instance to set options
|
97
97
|
>
|
98
|
-
> > **Method** `set_callable(*custom_ids: str, _callable: Union[Callable, None]) -> SelectMenu` : Set a callable for menus associated with custom_ids. This callable _(async function)_ will be set to respond at selected menus interactions
|
98
|
+
> > **Method** `set_callable(*custom_ids: str, _callable: Union[Callable, None], data: Optional[dict[str, Any]]) -> SelectMenu` : Set a callable for menus associated with custom_ids. This callable _(async function)_ will be set to respond at selected menus interactions. _data_ parameter is a dict fill with any values to pass in _(async function)_ parameters
|
99
99
|
>
|
100
100
|
> > **Method** `send(target: Union[Member, TextChannel]) -> Any` : Send the selectmenu in dm member or channels
|
101
101
|
>
|
@@ -1,7 +1,7 @@
|
|
1
1
|
pycordViews/__init__.py,sha256=UHIqRdzmyqyZPByJRpLvS3sjMxCmcve34mgcYEhf_8k,297
|
2
2
|
pycordViews/kit/__init__.py,sha256=N5yCdv-jwHAoGfDlc1By4hCtHK5cJaQFqnlHbHKmq7U,54
|
3
|
-
pycordViews/kit/confirm.py,sha256=
|
4
|
-
pycordViews/kit/poll.py,sha256=
|
3
|
+
pycordViews/kit/confirm.py,sha256=lc0T8HxVtQdkMo42_3CJPYT7Q501348WGG7FUvPFNBM,2875
|
4
|
+
pycordViews/kit/poll.py,sha256=9PQfeEUvNZUmO8-NsWbERZwCpw5BudUGBvDG-rVwt2g,7092
|
5
5
|
pycordViews/menu/__init__.py,sha256=QUXA9ezyeTScvS1kxMNFgKEbZMsPq5yUnWWgbXCytCk,97
|
6
6
|
pycordViews/menu/errors.py,sha256=0Um-oH5qMdWSZB_bGlqILsf9WSDtC4n_HwkheekiMV4,480
|
7
7
|
pycordViews/menu/menu.py,sha256=3D13C5Vs69w9SlrnixBfF0riY48jORi8JcYte65YFPs,4306
|
@@ -17,12 +17,12 @@ pycordViews/multibot/process.py,sha256=wp5jS4Y69pyhm-gM3iq6epobpUHf1Pb-CtZt8I05J
|
|
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
|
-
pycordViews/pagination/pagination_view.py,sha256=
|
20
|
+
pycordViews/pagination/pagination_view.py,sha256=kkbOhTqkIckAOvKL2Dli2v1ABjv5NzWh8XoV6cPm3mQ,5610
|
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=gDi_yIO8R1Xoh-lEgsu57E9ln2O9cK5qtQb3NrpPlSA,14142
|
23
23
|
pycordViews/views/errors.py,sha256=AkhGskuBjbFs0ZQdTDlVyfvAJ1WRMMQx2sAXUnYjmog,360
|
24
|
-
pycordviews-1.2.
|
25
|
-
pycordviews-1.2.
|
26
|
-
pycordviews-1.2.
|
27
|
-
pycordviews-1.2.
|
28
|
-
pycordviews-1.2.
|
24
|
+
pycordviews-1.2.19.dist-info/licenses/LICENSE,sha256=lNgcw1_xb7QENAQi3uHGymaFtbs0RV-ihiCd7AoLQjA,1082
|
25
|
+
pycordviews-1.2.19.dist-info/METADATA,sha256=VWOh_lAYyRL1gZLkRUejhw9nYxoD0kkIBqTV4idFYMI,11947
|
26
|
+
pycordviews-1.2.19.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
|
27
|
+
pycordviews-1.2.19.dist-info/top_level.txt,sha256=3NvgH6MjESe7Q6jb6aqHgdYrYb5NhxwxnoDyE6PkThY,125
|
28
|
+
pycordviews-1.2.19.dist-info/RECORD,,
|
File without changes
|
File without changes
|