Skip to content

Commit 22852a8

Browse files
committed
feat: HTTP properly uses the audit log reason header.
1 parent eac3ec1 commit 22852a8

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

interactions/api/http.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ async def request(self, route: Route, **kwargs) -> Optional[Any]:
192192
with Padlock(ratelimit) as lock: # noqa: F841
193193
kwargs["headers"] = {**self.headers, **kwargs.get("headers", {})}
194194
kwargs["headers"]["Content-Type"] = "application/json"
195+
196+
if kwargs.get("reason"):
197+
kwargs["headers"]["X-Audit-Log-Reason"] = kwargs["reason"]
198+
del kwargs["reason"]
199+
195200
async with self.session.request(
196201
route.method, route.__api__ + route.path, **kwargs
197202
) as response:

interactions/models/misc.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
from typing import Dict, List, Optional, Union
1+
from typing import Dict, List, Optional
22

33
from ..api.models.channel import Channel
44
from ..api.models.member import Member
55
from ..api.models.message import Message
66
from ..api.models.misc import DictSerializerMixin, Snowflake
77
from ..api.models.role import Role
88
from ..api.models.user import User
9-
from ..enums import ApplicationCommandType, InteractionType
9+
from ..enums import ApplicationCommandType, ComponentType, InteractionType
1010
from ..models.command import Option
11-
from ..models.component import Component, SelectOption
11+
from ..models.component import SelectOption
1212

1313

1414
class InteractionResolvedData(DictSerializerMixin):
@@ -67,21 +67,21 @@ class InteractionData(DictSerializerMixin):
6767
:ivar str name: The name of the interaction.
6868
:ivar ApplicationCommandType type: The type of command from the interaction.
6969
:ivar Optional[InteractionResolvedData] resolved?: The resolved version of the data.
70-
:ivar Optional[Union[Option, List[Option]]] options?: The options of the interaction.
70+
:ivar Optional[Option, List[Option]] options?: The options of the interaction.
7171
:ivar Optional[str] custom_id?: The custom ID of the interaction.
72-
:ivar Optional[int] component_type?: The type of component from the interaction.
73-
:ivar Optional[Union[SelectOption, List[SelectOption]]] values?: The values of the selected options in the interaction.
72+
:ivar Optional[ComponentType] component_type?: The type of component from the interaction.
73+
:ivar Optional[List[SelectOption]] values?: The values of the selected options in the interaction.
7474
:ivar Optional[str] target_id?: The targeted ID of the interaction.
7575
"""
7676

7777
id: Snowflake
7878
name: str
7979
type: ApplicationCommandType
8080
resolved: Optional[InteractionResolvedData]
81-
options: Optional[Union[Option, List[Option]]]
81+
options: Optional[List[Option]]
8282
custom_id: Optional[str]
83-
component_type: Optional[int]
84-
values: Optional[Union[SelectOption, List[SelectOption]]]
83+
component_type: Optional[ComponentType]
84+
values: Optional[List[SelectOption]]
8585
target_id: Optional[Snowflake]
8686

8787
__slots__ = (
@@ -106,11 +106,14 @@ def __init__(self, **kwargs):
106106
)
107107
self.id = Snowflake(self.id) if self._json.get("id") else None
108108
self.target_id = Snowflake(self.target_id) if self._json.get("target_id") else None
109-
self.components = (
110-
[Component(**component) for component in self.components]
111-
if self._json.get("components")
112-
else None
109+
self.options = (
110+
[Option(**option) for option in self.options] if self._json.get("options") else None
113111
)
112+
self.component_type = ComponentType(self.component_type)
113+
self.values = (
114+
[SelectOption(**value) for value in self.values] if self._json.get("values") else None
115+
)
116+
self._json.update({"component_type": self.component_type.value})
114117

115118

116119
class Interaction(DictSerializerMixin):

0 commit comments

Comments
 (0)