Repository: hikari-py/hikari
Pull request #705 (2021-07-23 21:18:36)

Add setting flags for deferred responses
### Summary
Add setting flags for deferred responses

### Checklist
<!-- Make sure to tick all the following boxes by putting an `x` in between (like this `[x]`) -->
- [x] I have run `nox` and all the pipelines have passed.
- [x] I have made unittests according to the code I have added/modified/deleted.

### Related issues
<!--
To mention an issue use `#issue-id` and to mention a merge request use `!merge-request-id`
To close/fix an issue use `Close #issue-id` or `Fix #issue-id` (depending on the merge request)
-->



Patch:
diff --git a/hikari/api/special_endpoints.py b/hikari/api/special_endpoints.py
index 71a23a1a..a419732b 100644
--- a/hikari/api/special_endpoints.py
+++ b/hikari/api/special_endpoints.py
@@ -581,6 +581,40 @@ def type(self) -> base_interactions.DeferredResponseTypesT:
             The type of response this is.
         """
 
+    @property
+    @abc.abstractmethod
+    def flags(self) -> typing.Union[undefined.UndefinedType, int, messages.MessageFlag]:
+        """Message flags this response should have.
+
+        !!! note
+            As of writing the only message flag which can be set here is
+            `hikari.messages.MessageFlag.EPHEMERAL`.
+
+        Returns
+        -------
+        typing.Union[hikari.undefined.UndefinedType, builtins.int, hikari.messages.MessageFlag]
+            The message flags this response should have if set else
+            `hikari.undefined.UNDEFINED`.
+        """
+
+    @abc.abstractmethod
+    def set_flags(self: _T, flags: typing.Union[undefined.UndefinedType, int, messages.MessageFlag], /) -> _T:
+        """Set message flags for this response.
+
+        !!! note
+            As of writing, the only message flag which can be set is EPHEMERAL.
+
+        Parameters
+        ----------
+        flags : typing.Union[hikari.undefined.UndefinedType, builtins.int, hikari.messages.MessageFlag]
+            The message flags to set for this response.
+
+        Returns
+        -------
+        InteractionMessageBuilder
+            Object of this builder.
+        """
+
 
 class InteractionMessageBuilder(InteractionResponseBuilder, abc.ABC):
     """Interface of an interaction message response builder used within REST servers.
diff --git a/hikari/impl/special_endpoints.py b/hikari/impl/special_endpoints.py
index 9bf5c309..5dbea550 100644
--- a/hikari/impl/special_endpoints.py
+++ b/hikari/impl/special_endpoints.py
@@ -71,6 +71,7 @@
 
     _CommandBuilderT = typing.TypeVar("_CommandBuilderT", bound="CommandBuilder")
     _InteractionMessageBuilderT = typing.TypeVar("_InteractionMessageBuilderT", bound="InteractionMessageBuilder")
+    _InteractionDeferredBuilderT = typing.TypeVar("_InteractionDeferredBuilderT", bound="InteractionDeferredBuilder")
 
 
 @typing.final
@@ -691,12 +692,29 @@ class InteractionDeferredBuilder(special_endpoints.InteractionDeferredBuilder):
         validator=attr.validators.in_(base_interactions.DEFERRED_RESPONSE_TYPES),
     )
 
+    _flags: typing.Union[undefined.UndefinedType, int, messages.MessageFlag] = attr.field(
+        default=undefined.UNDEFINED, kw_only=True
+    )
+
     @property
     def type(self) -> base_interactions.DeferredResponseTypesT:
         return self._type
 
+    @property
+    def flags(self) -> typing.Union[undefined.UndefinedType, int, messages.MessageFlag]:
+        return self._flags
+
+    def set_flags(
+        self: _InteractionDeferredBuilderT, flags: typing.Union[undefined.UndefinedType, int, messages.MessageFlag], /
+    ) -> _InteractionDeferredBuilderT:
+        self._flags = flags
+        return self
+
     def build(self, _: entity_factory_.EntityFactory, /) -> data_binding.JSONObject:
-        return {"type": self.type}
+        if self._flags is not undefined.UNDEFINED:
+            return {"type": self._type, "data": {"flags": self._flags}}
+
+        return {"type": self._type}
 
 
 @attr_extensions.with_copy


Test patch:
diff --git a/tests/hikari/impl/test_special_endpoints.py b/tests/hikari/impl/test_special_endpoints.py
index 9042d7ac..594addac 100644
--- a/tests/hikari/impl/test_special_endpoints.py
+++ b/tests/hikari/impl/test_special_endpoints.py
@@ -51,11 +51,26 @@ def test_type_property(self):
 
         assert builder.type == 5
 
+    def test_set_flags(self):
+        builder = special_endpoints.InteractionDeferredBuilder(5).set_flags(32)
+
+        assert builder.flags == 32
+
     def test_build(self):
         builder = special_endpoints.InteractionDeferredBuilder(base_interactions.ResponseType.DEFERRED_MESSAGE_CREATE)
 
         assert builder.build(object()) == {"type": base_interactions.ResponseType.DEFERRED_MESSAGE_CREATE}
 
+    def test_build_with_flags(self):
+        builder = special_endpoints.InteractionDeferredBuilder(
+            base_interactions.ResponseType.DEFERRED_MESSAGE_CREATE
+        ).set_flags(64)
+
+        assert builder.build(object()) == {
+            "type": base_interactions.ResponseType.DEFERRED_MESSAGE_CREATE,
+            "data": {"flags": 64},
+        }
+
 
 class TestInteractionMessageBuilder:
     def test_type_property(self):