PycordViews 1.2.15__tar.gz → 1.2.19__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.
Files changed (34) hide show
  1. {pycordviews-1.2.15 → pycordviews-1.2.19}/PKG-INFO +2 -2
  2. {pycordviews-1.2.15 → pycordviews-1.2.19}/PycordViews.egg-info/PKG-INFO +2 -2
  3. {pycordviews-1.2.15 → pycordviews-1.2.19}/README.md +1 -1
  4. {pycordviews-1.2.15 → pycordviews-1.2.19}/pycordViews/kit/confirm.py +1 -1
  5. {pycordviews-1.2.15 → pycordviews-1.2.19}/pycordViews/kit/poll.py +2 -2
  6. {pycordviews-1.2.15 → pycordviews-1.2.19}/pycordViews/pagination/pagination_view.py +1 -1
  7. {pycordviews-1.2.15 → pycordviews-1.2.19}/pycordViews/views/easy_modified_view.py +41 -7
  8. {pycordviews-1.2.15 → pycordviews-1.2.19}/setup.py +1 -1
  9. {pycordviews-1.2.15 → pycordviews-1.2.19}/LICENSE +0 -0
  10. {pycordviews-1.2.15 → pycordviews-1.2.19}/PycordViews.egg-info/SOURCES.txt +0 -0
  11. {pycordviews-1.2.15 → pycordviews-1.2.19}/PycordViews.egg-info/dependency_links.txt +0 -0
  12. {pycordviews-1.2.15 → pycordviews-1.2.19}/PycordViews.egg-info/requires.txt +0 -0
  13. {pycordviews-1.2.15 → pycordviews-1.2.19}/PycordViews.egg-info/top_level.txt +0 -0
  14. {pycordviews-1.2.15 → pycordviews-1.2.19}/pycordViews/__init__.py +0 -0
  15. {pycordviews-1.2.15 → pycordviews-1.2.19}/pycordViews/kit/__init__.py +0 -0
  16. {pycordviews-1.2.15 → pycordviews-1.2.19}/pycordViews/menu/__init__.py +0 -0
  17. {pycordviews-1.2.15 → pycordviews-1.2.19}/pycordViews/menu/errors.py +0 -0
  18. {pycordviews-1.2.15 → pycordviews-1.2.19}/pycordViews/menu/menu.py +0 -0
  19. {pycordviews-1.2.15 → pycordviews-1.2.19}/pycordViews/menu/selectMenu.py +0 -0
  20. {pycordviews-1.2.15 → pycordviews-1.2.19}/pycordViews/modal/__init__.py +0 -0
  21. {pycordviews-1.2.15 → pycordviews-1.2.19}/pycordViews/modal/easy_modal_view.py +0 -0
  22. {pycordviews-1.2.15 → pycordviews-1.2.19}/pycordViews/modal/errors.py +0 -0
  23. {pycordviews-1.2.15 → pycordviews-1.2.19}/pycordViews/multibot/__init__.py +0 -0
  24. {pycordviews-1.2.15 → pycordviews-1.2.19}/pycordViews/multibot/bot.py +0 -0
  25. {pycordviews-1.2.15 → pycordviews-1.2.19}/pycordViews/multibot/errors.py +0 -0
  26. {pycordviews-1.2.15 → pycordviews-1.2.19}/pycordViews/multibot/multibot.py +0 -0
  27. {pycordviews-1.2.15 → pycordviews-1.2.19}/pycordViews/multibot/process.py +0 -0
  28. {pycordviews-1.2.15 → pycordviews-1.2.19}/pycordViews/pagination/__init__.py +0 -0
  29. {pycordviews-1.2.15 → pycordviews-1.2.19}/pycordViews/pagination/errors.py +0 -0
  30. {pycordviews-1.2.15 → pycordviews-1.2.19}/pycordViews/pagination/page.py +0 -0
  31. {pycordviews-1.2.15 → pycordviews-1.2.19}/pycordViews/views/__init__.py +0 -0
  32. {pycordviews-1.2.15 → pycordviews-1.2.19}/pycordViews/views/errors.py +0 -0
  33. {pycordviews-1.2.15 → pycordviews-1.2.19}/pyproject.toml +0 -0
  34. {pycordviews-1.2.15 → pycordviews-1.2.19}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PycordViews
3
- Version: 1.2.15
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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PycordViews
3
- Version: 1.2.15
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
  >
@@ -61,7 +61,7 @@ The SelectMenu instance is used to create drop-down menus that can be easily mod
61
61
  >
62
62
  > > **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
63
63
  >
64
- > > **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
64
+ > > **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
65
65
  >
66
66
  > > **Method** `send(target: Union[Member, TextChannel]) -> Any` : Send the selectmenu in dm member or channels
67
67
  >
@@ -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
  """
@@ -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, data: Optional[dict[str, Any]] = None):
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, _callable=_callable, data=data)
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, _callable: Callable, data: Optional[dict[str, Any]] = None):
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', data={'message': 'Hello !'}))
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:
@@ -5,7 +5,7 @@ with open("README.md", encoding='utf-8') as file:
5
5
 
6
6
  setup(
7
7
  name="PycordViews",
8
- version="1.2.15",
8
+ version="1.2.19",
9
9
  url="https://github.com/BOXERRMD/Py-cord_Views",
10
10
  author="Chronos (alias BOXERRMD)",
11
11
  author_email="vagabonwalybi@gmail.com",
File without changes
File without changes