mirror of
https://github.com/Rapptz/discord.py.git
synced 2026-11-20 13:29:03 +00:00
Change View callback order to (self, interaction, item)
This is more consistent with the rest of the library which always has the interaction as the first parameter. This has been done before in the command extension as well, the first parameter is always either self or the context.
This commit is contained in:
1 parent
f26d3a7155
commit
968a1f366f
8 files changed
+27
-15
No files matched your search
+14
-2
@@ -23,7 +23,7 @@ DEALINGS IN THE SOFTWARE.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
from typing import Any, Callable, ClassVar, Dict, Iterator, List, Optional, Sequence, TYPE_CHECKING, Tuple
|
||||
from typing import Any, Callable, ClassVar, Coroutine, Dict, Iterator, List, Optional, Sequence, TYPE_CHECKING, Tuple
|
||||
from functools import partial
|
||||
from itertools import groupby
|
||||
|
||||
@@ -127,6 +127,18 @@ class _ViewWeights:
|
||||
self.weights = [0, 0, 0, 0, 0]
|
||||
|
||||
|
||||
class _ViewCallback:
|
||||
__slots__ = ('view', 'callback', 'item')
|
||||
|
||||
def __init__(self, callback: ItemCallbackType[Any, Any], view: View, item: Item[View]) -> None:
|
||||
self.callback: ItemCallbackType[Any, Any] = callback
|
||||
self.view: View = view
|
||||
self.item: Item[View] = item
|
||||
|
||||
def __call__(self, interaction: Interaction) -> Coroutine[Any, Any, Any]:
|
||||
return self.callback(self.view, interaction, self.item)
|
||||
|
||||
|
||||
class View:
|
||||
"""Represents a UI view.
|
||||
|
||||
@@ -169,7 +181,7 @@ class View:
|
||||
children = []
|
||||
for func in self.__view_children_items__:
|
||||
item: Item = func.__discord_ui_model_type__(**func.__discord_ui_model_kwargs__)
|
||||
item.callback = partial(func, self, item) # type: ignore
|
||||
item.callback = _ViewCallback(func, self, item)
|
||||
item._view = self
|
||||
setattr(self, func.__name__, item)
|
||||
children.append(item)
|
||||
|
||||
Reference in new issue
Block a user