Commit Graph

97 Commits

Author SHA1 Message Date
50b0d219b5 Add missing versionadded to some BaseView items 2025-08-24 13:22:35 -04:00
9bda89b0d6 Update total count tracking to always consider the wrapper object 2025-08-21 22:20:12 -04:00
0309aac335 Add a swap method for dynamic item's dispatching 2025-08-20 18:52:31 -04:00
44a44e938f Reformat entire project with ruff instead of black 2025-08-18 20:16:10 -04:00
3ef6272e07 Fix error with View.from_message when having multiple items 2025-08-18 19:04:19 -04:00
d58c055c5b Remove unused import 2025-08-18 15:07:44 -04:00
5d49f11709 Remove View.from_dict typing 2025-08-18 15:00:51 -04:00
fc12a41cdf Run black 2025-08-18 14:49:32 -04:00
064cb7af71 Add View.total_children_count 2025-08-18 14:42:55 -04:00
f08c042217 Add content_length method to LayoutView and container items 2025-08-18 14:33:15 -04:00
9ef5b054e5 Refactor total children count to an overrideable method 2025-08-18 04:49:20 -04:00
2a69ac4ca8 Document difference between View and LayoutView 2025-08-18 04:34:24 -04:00
38c6407ffd Maintain a reference to View dispatched tasks 2025-08-14 00:47:55 -04:00
3fb627d078 Add support for label components and select in modals 2025-08-14 00:47:55 -04:00
9fb74fd7a1 Remove unnecessary TypeGuard 2025-08-13 21:27:38 -04:00
50caa3c82c Add support for components V2
Co-authored-by: Michael H <michael@michaelhall.tech>
Co-authored-by: Soheab <33902984+Soheab@users.noreply.github.com>
Co-authored-by: owocado <24418520+owocado@users.noreply.github.com>
Co-authored-by: Jay3332 <40323796+jay3332@users.noreply.github.com>
Co-authored-by: Danny <1695103+Rapptz@users.noreply.github.com>
2025-08-13 20:37:23 -04:00
7f16a06479 Copy Select options when creating View class 2025-06-20 14:24:06 -04:00
8953938a53 Update Pyright to v1.1.394 2025-02-18 03:29:09 -05:00
6ab747f9e5 Add support for sending views in stateless webhooks 2025-02-17 18:37:20 -05:00
2248fc1946 Fix various code around Message.interaction(_metadata) 2024-05-06 18:17:37 -04:00
dc6d33c303 copy over original row position for dynamic items 2024-04-18 03:33:43 -04:00
76666fbcf4 Properly check for maximum number of children 2024-02-17 01:17:31 -05:00
078b500657 Fix dynamic item views having a timeout causing it to evict 2023-12-30 05:00:12 -05:00
698363e76b Refactor from_components for Select classes
Co-authored-by: Danny <1695103+Rapptz@users.noreply.github.com>
2023-09-30 21:21:29 -04:00
e67d00502d Fix View.from_message not creating other Selects 2023-09-12 13:03:29 -04:00
94655cd804 Skip adding views to the synced message store if fully dynamic 2023-09-03 02:52:05 -04:00
f793af0456 Add item parameter to DynamicItem.from_custom_id 2023-09-03 02:52:05 -04:00
7c3868ef3b Add Client.remove_dynamic_items 2023-09-03 02:52:05 -04:00
a852f90358 Add support for dynamic items that parse custom_id for state 2023-09-03 02:52:05 -04:00
f7e9795495 Call super for __init_subclass__ in View
Co-authored-by: Danny <1695103+Rapptz@users.noreply.github.com>
2023-02-12 02:08:39 -05:00
6cb9a84898 Fix views not being removed from message store backing
This uses the original interaction ID if available for cache eviction
2023-01-25 02:37:30 -05:00
5009c83bc9 Implement New Select Types
Co-authored-by: Soheab_ <33902984+Soheab@users.noreply.github.com>
Co-authored-by: rdrescher909 <51489753+rdrescher909@users.noreply.github.com>
Co-authored-by: Danny <1695103+Rapptz@users.noreply.github.com>
2022-10-27 10:03:45 -04:00
95b6bd8782 Add coro tag to docstrings that were missing it 2022-10-02 17:52:18 -04:00
6981eb69c4 Normalize type formatting in TypeError
Normalize most mixed usages of `__class__`, `__class__!r`, 
`__class__.__name__!r` to the standard form of 
`__class__.__name__`
2022-09-12 15:25:55 -04:00
b12b4b18fd Mark public callbacks as positional-only 2022-08-22 15:21:19 -04:00
6327402730 Update View timeout only if interaction_check passes 2022-08-18 18:55:50 -04:00
9c38cf3aef Fix ui.Select.values in modals 2022-08-14 15:25:43 -04:00
efdda635fb Fix View.from_message not respecting ActionRow row order 2022-07-23 15:24:26 -04:00
1be36c9c3e Change View, Modal, and AudioPlayer to use logger instead of stderr 2022-06-22 02:10:02 -04:00
7267d18d9e Improve component typing 2022-05-16 15:30:03 -04:00
a0dfdb9b1d Fix multiple view instances not dispatching in app commands responses
Due to a quirk in InteractionResponse.send_message not returning a
message, all messages sent with an associated View would end up having
no message_id set. When multiple instances of a View are responded to
in a slash command context, this meant that the newest one would
override the storage of the older one. Ultimately leading to the first
view instance causing interaction failures.

Since fetching the original message is an unacceptable solution to the
problem due to incurred requests, the next best thing is to store an
intermediate interaction_id as a stop gap to differentiate between
the multiple instances. This change however, came with its own set of
complications.

Due to the interaction_id being an intermediate stop gap, the
underlying storage of the view store had to be changed to accommodate
the different way of accessing the data. Mainly, the interaction_id
key had to be quick to swap and remove to another key. This solution
attempts to change the interaction_id interim key with
a full fledged message_id key when it receives one if it's possible.

Note that the only way to obtain the interaction_id back from the
component interaction is to retrieve it from the MessageInteraction
data structure. This is because using the interaction_id of the button
press would be a different interaction ID than the one set as an
interim key. As a consequence, this stop gap only works for application
command based interactions. I am not aware of this bug manifesting in
component based interactions.

This patch also fixes a bug with ViewStore.remove_view not working due
to a bug being suppressed by a type: ignore comment. It also removes
the older __verify_integrity helper method since clean-up is already
done through View.stop() or View timeout.

Hopefully in the near future, the `/callback` endpoint will return
actual message data and this stop gap fix will no longer be necessary.
2022-04-28 12:24:57 -04:00
e198a0e7e6 Avoid re-creating View children on edit
The older code attempted to be clever and sync component additions and
removals with what the message edit is doing. In some cases, this led
to the re-creation of those components causing lost attributes to be
dropped such as `_rendered_row` which would mess up handling of view
weights.

Instead of recreating the children list every time and keeping track
of additions and removals, this change just updates the old state with
the new state while ignoring any new or removed additions. This should
work fine in theory due to additions or removals already being present
before editing the View instance in the first place.

Closes #7231 #7511
2022-04-27 01:24:10 -04:00
0fa9bfc925 Correct order of arguments in View.on_error 2022-04-12 21:15:16 -04:00
c68ea67213 Properly handle inheritance overriding in View subclasses 2022-04-05 09:41:48 -04:00
1458251736 Change View.children to be a property
This allows users to call remove_item in a loop. Likewise, it prevents
the footgun of doing children.append(...) which does not uphold the
invariants with the weight system.
2022-04-03 20:13:42 -04:00
b4fbb08818 Allow runtime modification of timeout expiry at runtime
This is done through setting View.timeout while it's running
2022-03-31 01:54:13 -04:00
968a1f366f 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.
2022-03-24 23:00:50 -04:00
515d17405a Fix typos in some View methods' docstrings 2022-03-20 12:59:23 -04:00
Pat
94f4da9248 Change View child mutators to be fluent-style methods 2022-03-19 04:48:50 -04:00
26457b6d50 Remove automatic defer behaviour from View and Modal
This doesn't make as much sense anymore now that
InteractionResponse.edit_message exists.
2022-03-15 10:30:19 -04:00