hikari-risa 1.0.0__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.
risa/di.py ADDED
@@ -0,0 +1,75 @@
1
+ # Copyright (c) 2025 Rayakame
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+ """Dependency injection for handlers, through linkd."""
21
+
22
+ from __future__ import annotations
23
+
24
+ import typing
25
+
26
+ import linkd
27
+ import linkd.context
28
+ from linkd import INJECTED
29
+
30
+ __all__ = ("INJECTED", "ComponentContainer", "Contexts", "ModalContainer")
31
+
32
+
33
+ @typing.final
34
+ class ComponentContainer(linkd.Container):
35
+ """The linkd container risa opens for each component interaction it dispatches."""
36
+
37
+ __slots__ = ()
38
+
39
+
40
+ @typing.final
41
+ class ModalContainer(linkd.Container):
42
+ """The linkd container reserved for modal submissions, which risa does not dispatch yet."""
43
+
44
+ __slots__ = ()
45
+
46
+
47
+ @typing.final
48
+ class Contexts:
49
+ """The linkd contexts risa dispatches in.
50
+
51
+ A handler runs inside `DEFAULT` with `COMPONENT` entered on top, so it can be
52
+ injected with anything registered in either. risa adds the `ComponentContext` and the
53
+ `hikari.ComponentInteraction` to `COMPONENT` for every click.
54
+
55
+ Attributes
56
+ ----------
57
+ DEFAULT
58
+ linkd's root context, the one a lightbulb client shares.
59
+ COMPONENT
60
+ Entered for every component interaction.
61
+ MODAL
62
+ Reserved for modal submissions.
63
+ """
64
+
65
+ __slots__ = ()
66
+
67
+ DEFAULT: typing.Final[linkd.context.Context] = linkd.Contexts.ROOT
68
+ COMPONENT: typing.Final[linkd.context.Context] = linkd.global_context_registry.register(
69
+ "risa.contexts.component",
70
+ ComponentContainer,
71
+ )
72
+ MODAL: typing.Final[linkd.context.Context] = linkd.global_context_registry.register(
73
+ "risa.contexts.modal",
74
+ ModalContainer,
75
+ )