68 Commits

Author SHA1 Message Date
Takagi Tasuku
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
Rapptz
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
Trevor
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
ster
95b6bd8782
Add coro tag to docstrings that were missing it 2022-10-02 17:52:18 -04:00
Ionite
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
Bryan Forbes
b12b4b18fd
Mark public callbacks as positional-only 2022-08-22 15:21:19 -04:00
Rapptz
6327402730 Update View timeout only if interaction_check passes 2022-08-18 18:55:50 -04:00
Mikey
9c38cf3aef
Fix ui.Select.values in modals 2022-08-14 15:25:43 -04:00
Rapptz
efdda635fb Fix View.from_message not respecting ActionRow row order 2022-07-23 15:24:26 -04:00
mniip
1be36c9c3e
Change View, Modal, and AudioPlayer to use logger instead of stderr 2022-06-22 02:10:02 -04:00
Lilly Rose Berner
7267d18d9e
Improve component typing 2022-05-16 15:30:03 -04:00
Rapptz
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
Rapptz
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
Snaptraks
0fa9bfc925
Correct order of arguments in View.on_error 2022-04-12 21:15:16 -04:00
Rapptz
c68ea67213 Properly handle inheritance overriding in View subclasses 2022-04-05 09:41:48 -04:00
Rapptz
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
Rapptz
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
Rapptz
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
chromacoat dreamkey
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
Rapptz
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
Rapptz
934ab4151a Mark state refresh methods as private with an underscore
People kept wondering what it is or what it does.
2022-03-14 07:50:25 -04:00
Stocker
5aa696ccfa
Fix typing issues and improve typing completeness across the library
Co-authored-by: Danny <Rapptz@users.noreply.github.com>
Co-authored-by: Josh <josh.ja.butt@gmail.com>
2022-03-13 23:52:10 -04:00
Rapptz
c0890bfbc1 Remove unused View._expires_at private function 2022-03-13 11:50:09 -04:00
Han Seung Min - 한승민
93af158b0c
Refactor loop code to allow usage of asyncio.run 2022-03-13 04:54:14 -04:00
Stella
2b600241a4
Fix Modal.stop sometimes not removing from the store 2022-03-07 17:39:00 -05:00
Rapptz
4c8b1f9abd Remove unused imports 2022-03-05 21:40:42 -05:00
Josh
d409ddd227
Alter return-type of button/select decorators 2022-02-21 21:54:44 -05:00
Rapptz
88b520b5ab Reformat code using black
Segments where readability was hampered were fixed by appropriate
format skipping directives. New code should hopefully be black
compatible. The moment they remove the -S option is probably the moment
I stop using black though.
2022-02-20 08:04:58 -05:00
Josh
19c6687b55
Add support for Modal Interactions 2022-02-20 04:57:44 -05:00
Rapptz
c22f058fa0 Fix views not being removed upon timeout 2022-02-17 07:35:12 -05:00
Rapptz
0cc67e58ed Fallback to None message_id searches in View dispatch
Not all persistent views have an associated message_id attached to
them.

Fix #7319
2021-08-01 03:30:45 -04:00
Rapptz
b87d306a70 Remove unused variable in view 2021-08-01 02:40:11 -04:00
Rapptz
e795d341e7 Change View dispatch mechanism to be keyed by message_id as well
If different persistent view instances are used within different
message_ids their callbacks will get called without differentiating
between them, leading to potential issues such as 404 errors. This
change makes it so N views with custom IDs bound to N message_ids
will no longer conflict with one another.
2021-07-31 23:08:05 -04:00
scrazzz
a0e5e062c9
Add versionadded to ui.View and ui.Item 2021-07-21 02:47:52 -04:00
Kaylynn Morgan
feed302269
Fix documentation note for interaction_check 2021-07-21 02:46:52 -04:00
Rapptz
8df35c83a9 Remove extraneous dict assignment from view store 2021-07-07 20:19:17 -04:00
Rapptz
074f34a5fa Specify View timeouts is in seconds 2021-07-04 07:07:38 -04:00
Rapptz
d7ed884593 Rework view timeouts to work as documented 2021-07-02 09:17:32 -04:00
Josh
d001b9d0ee
[docs] Fix more references
Co-Authored-By: Riley Shaw <30989490+ShineyDev@users.noreply.github.com>
2021-07-01 07:48:37 -04:00
Rapptz
c1f1c67eed Change timeout parameter in View.from_message to keyword only 2021-06-30 03:15:45 -04:00
Rapptz
d8075d5412 Add View.from_message to convert message components to a View 2021-06-30 03:06:51 -04:00
Rapptz
157caaec7c Add conversion routine for SelectMenu to ui.Select 2021-06-30 02:55:03 -04:00
Rapptz
04573c3c06 Make View timeout parameter keyword-only 2021-06-10 09:06:04 -04:00
UP929312
4724943861
Grammatical improvements in View documentation 2021-06-08 06:54:10 -04:00
Rapptz
81e9d70b7b Add pre-conditions to avoid on_timeout being called after stop()
Apparently the cancellation request for a TimerHandle doesn't
necessarily have to be honoured despite large periods of time passing
2021-06-06 07:05:17 -04:00
Rapptz
876b1e0f3e Add View.on_error callback for swallowed exceptions 2021-06-05 08:22:44 -04:00
Rapptz
dbd9ed2c41 Add View.is_dispatching to detect whether a view has been added 2021-06-04 04:30:19 -04:00
Rapptz
78275023cc Add Client.persistent_views to get all persistent views 2021-05-31 23:15:12 -04:00
Rapptz
7c40e83d10 Ensure views added to Client.add_view are persistent views 2021-05-31 23:08:08 -04:00