-- | Interaction related utilities
module Calamity.Interactions.Utils (
  respond,
  respondEphemeral,
  followUp,
  followUpEphemeral,
  edit,
  defer,
  deferEphemeral,
  deferComponent,
  pushModal,
  userLocalState,
) where

import Calamity.HTTP
import Calamity.Interactions.Eff (InteractionEff, getInteractionID, getInteractionToken, getInteractionUser, getApplicationID)
import Calamity.Metrics.Eff (MetricEff)
import Calamity.Types.LogEff (LogEff)
import Calamity.Types.Model.Channel.Component (Component (ActionRow'))
import Calamity.Types.Model.User (User)
import Calamity.Types.Snowflake (Snowflake)
import Calamity.Types.Tellable
import Optics
import qualified Data.HashMap.Strict as H
import Data.Text (Text)
import qualified Polysemy as P
import qualified Polysemy.State as P
import System.Random (getStdRandom, uniform)

{- | Provide local state semantics to a running view, the state is keyed to the
 user invoking the interaction
-}
userLocalState ::
  forall r s a.
  P.Member InteractionEff r =>
  -- | Initial state
  s ->
  P.Sem (P.State s ': r) a ->
  P.Sem r a
userLocalState :: forall (r :: EffectRow) s a.
Member InteractionEff r =>
s -> Sem (State s : r) a -> Sem r a
userLocalState s
s =
  forall s (r :: EffectRow) a. s -> Sem (State s : r) a -> Sem r a
P.evalState forall k v. HashMap k v
H.empty
    forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (e1 :: (* -> *) -> * -> *) (e2 :: (* -> *) -> * -> *)
       (r :: EffectRow) a.
FirstOrder e1 "reinterpret" =>
(forall (rInitial :: EffectRow) x.
 e1 (Sem rInitial) x -> Sem (e2 : r) x)
-> Sem (e1 : r) a -> Sem (e2 : r) a
P.reinterpret @(P.State s) @(P.State (H.HashMap (Snowflake User) s))
      ( \case
          State s (Sem rInitial) x
P.Get -> do
            Snowflake User
uid <- forall (r :: EffectRow).
Member InteractionEff r =>
Sem r (Snowflake User)
getInteractionUser
            forall s a (r :: EffectRow).
Member (State s) r =>
(s -> a) -> Sem r a
P.gets (forall k v. (Eq k, Hashable k) => v -> k -> HashMap k v -> v
H.lookupDefault s
s Snowflake User
uid)
          P.Put s
s -> do
            Snowflake User
uid <- forall (r :: EffectRow).
Member InteractionEff r =>
Sem r (Snowflake User)
getInteractionUser
            forall s (r :: EffectRow).
Member (State s) r =>
(s -> s) -> Sem r ()
P.modify' (forall k v.
(Eq k, Hashable k) =>
k -> v -> HashMap k v -> HashMap k v
H.insert Snowflake User
uid s
s)
      )

-- | Respond to an interaction with a globally visible message
respond :: forall t r.
  (P.Members '[InteractionEff, RatelimitEff, TokenEff, LogEff, MetricEff, P.Embed IO] r, ToMessage t) =>
  t ->
  P.Sem r (Either RestError ())
respond :: forall t (r :: EffectRow).
(Members
   '[InteractionEff, RatelimitEff, TokenEff, LogEff, MetricEff,
     Embed IO]
   r,
 ToMessage t) =>
t -> Sem r (Either RestError ())
respond (forall a. ToMessage a => a -> CreateMessageOptions
runToMessage -> CreateMessageOptions
msg) =
  let opts :: InteractionCallbackMessageOptions
opts =
        InteractionCallbackMessageOptions
          { $sel:tts:InteractionCallbackMessageOptions :: Maybe Bool
tts = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "tts" a => a
#tts
          , $sel:content:InteractionCallbackMessageOptions :: Maybe Text
content = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "content" a => a
#content
          , $sel:embeds:InteractionCallbackMessageOptions :: Maybe [Embed]
embeds = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "embeds" a => a
#embeds
          , $sel:allowedMentions:InteractionCallbackMessageOptions :: Maybe AllowedMentions
allowedMentions = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "allowedMentions" a => a
#allowedMentions
          , $sel:ephemeral:InteractionCallbackMessageOptions :: Maybe Bool
ephemeral = forall a. a -> Maybe a
Just Bool
False
          , $sel:suppressEmbeds:InteractionCallbackMessageOptions :: Maybe Bool
suppressEmbeds = forall a. a -> Maybe a
Just Bool
False
          , $sel:components:InteractionCallbackMessageOptions :: Maybe [Component]
components = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "components" a => a
#components
          , $sel:attachments:InteractionCallbackMessageOptions :: Maybe [CreateMessageAttachment]
attachments = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "attachments" a => a
#attachments
          }
   in do
        Snowflake Interaction
interactionID <- forall (r :: EffectRow).
Member InteractionEff r =>
Sem r (Snowflake Interaction)
getInteractionID
        InteractionToken
interactionToken <- forall (r :: EffectRow).
Member InteractionEff r =>
Sem r InteractionToken
getInteractionToken
        forall (r :: EffectRow) a.
(Members '[RatelimitEff, TokenEff, LogEff, MetricEff, Embed IO] r,
 Request a, ReadResponse (Result a)) =>
a -> Sem r (Either RestError (Result a))
invoke forall a b. (a -> b) -> a -> b
$ forall i.
HasID Interaction i =>
i
-> InteractionToken
-> InteractionCallbackMessageOptions
-> InteractionRequest ()
CreateResponseMessage Snowflake Interaction
interactionID InteractionToken
interactionToken InteractionCallbackMessageOptions
opts

-- | Respond to an interaction with an ephemeral message
respondEphemeral :: forall t r.
  (P.Members '[InteractionEff, RatelimitEff, TokenEff, LogEff, MetricEff, P.Embed IO] r, ToMessage t) =>
  t ->
  P.Sem r (Either RestError ())
respondEphemeral :: forall t (r :: EffectRow).
(Members
   '[InteractionEff, RatelimitEff, TokenEff, LogEff, MetricEff,
     Embed IO]
   r,
 ToMessage t) =>
t -> Sem r (Either RestError ())
respondEphemeral (forall a. ToMessage a => a -> CreateMessageOptions
runToMessage -> CreateMessageOptions
msg) =
  let opts :: InteractionCallbackMessageOptions
opts =
        InteractionCallbackMessageOptions
          { $sel:tts:InteractionCallbackMessageOptions :: Maybe Bool
tts = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "tts" a => a
#tts
          , $sel:content:InteractionCallbackMessageOptions :: Maybe Text
content = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "content" a => a
#content
          , $sel:embeds:InteractionCallbackMessageOptions :: Maybe [Embed]
embeds = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "embeds" a => a
#embeds
          , $sel:allowedMentions:InteractionCallbackMessageOptions :: Maybe AllowedMentions
allowedMentions = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "allowedMentions" a => a
#allowedMentions
          , $sel:ephemeral:InteractionCallbackMessageOptions :: Maybe Bool
ephemeral = forall a. a -> Maybe a
Just Bool
True
          , $sel:suppressEmbeds:InteractionCallbackMessageOptions :: Maybe Bool
suppressEmbeds = forall a. a -> Maybe a
Just Bool
False
          , $sel:components:InteractionCallbackMessageOptions :: Maybe [Component]
components = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "components" a => a
#components
          , $sel:attachments:InteractionCallbackMessageOptions :: Maybe [CreateMessageAttachment]
attachments = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "attachments" a => a
#attachments
          }
   in do
        Snowflake Interaction
interactionID <- forall (r :: EffectRow).
Member InteractionEff r =>
Sem r (Snowflake Interaction)
getInteractionID
        InteractionToken
interactionToken <- forall (r :: EffectRow).
Member InteractionEff r =>
Sem r InteractionToken
getInteractionToken
        forall (r :: EffectRow) a.
(Members '[RatelimitEff, TokenEff, LogEff, MetricEff, Embed IO] r,
 Request a, ReadResponse (Result a)) =>
a -> Sem r (Either RestError (Result a))
invoke forall a b. (a -> b) -> a -> b
$ forall i.
HasID Interaction i =>
i
-> InteractionToken
-> InteractionCallbackMessageOptions
-> InteractionRequest ()
CreateResponseMessage Snowflake Interaction
interactionID InteractionToken
interactionToken InteractionCallbackMessageOptions
opts

-- | Respond to an interaction by editing the message that triggered the interaction
edit :: forall t r.
  (P.Members '[InteractionEff, RatelimitEff, TokenEff, LogEff, MetricEff, P.Embed IO] r, ToMessage t) =>
  t ->
  P.Sem r (Either RestError ())
edit :: forall t (r :: EffectRow).
(Members
   '[InteractionEff, RatelimitEff, TokenEff, LogEff, MetricEff,
     Embed IO]
   r,
 ToMessage t) =>
t -> Sem r (Either RestError ())
edit (forall a. ToMessage a => a -> CreateMessageOptions
runToMessage -> CreateMessageOptions
msg) =
  let opts :: InteractionCallbackMessageOptions
opts =
        InteractionCallbackMessageOptions
          { $sel:tts:InteractionCallbackMessageOptions :: Maybe Bool
tts = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "tts" a => a
#tts
          , $sel:content:InteractionCallbackMessageOptions :: Maybe Text
content = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "content" a => a
#content
          , $sel:embeds:InteractionCallbackMessageOptions :: Maybe [Embed]
embeds = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "embeds" a => a
#embeds
          , $sel:allowedMentions:InteractionCallbackMessageOptions :: Maybe AllowedMentions
allowedMentions = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "allowedMentions" a => a
#allowedMentions
          , $sel:ephemeral:InteractionCallbackMessageOptions :: Maybe Bool
ephemeral = forall a. Maybe a
Nothing
          , $sel:suppressEmbeds:InteractionCallbackMessageOptions :: Maybe Bool
suppressEmbeds = forall a. Maybe a
Nothing
          , $sel:components:InteractionCallbackMessageOptions :: Maybe [Component]
components = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "components" a => a
#components
          , $sel:attachments:InteractionCallbackMessageOptions :: Maybe [CreateMessageAttachment]
attachments = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "attachments" a => a
#attachments
          }
   in do
        Snowflake Interaction
interactionID <- forall (r :: EffectRow).
Member InteractionEff r =>
Sem r (Snowflake Interaction)
getInteractionID
        InteractionToken
interactionToken <- forall (r :: EffectRow).
Member InteractionEff r =>
Sem r InteractionToken
getInteractionToken
        forall (r :: EffectRow) a.
(Members '[RatelimitEff, TokenEff, LogEff, MetricEff, Embed IO] r,
 Request a, ReadResponse (Result a)) =>
a -> Sem r (Either RestError (Result a))
invoke forall a b. (a -> b) -> a -> b
$ forall i.
HasID Interaction i =>
i
-> InteractionToken
-> InteractionCallbackMessageOptions
-> InteractionRequest ()
CreateResponseUpdate Snowflake Interaction
interactionID InteractionToken
interactionToken InteractionCallbackMessageOptions
opts

-- | Create a follow up response to an interaction
followUp :: forall t r.
  (P.Members '[InteractionEff, RatelimitEff, TokenEff, LogEff, MetricEff, P.Embed IO] r, ToMessage t) =>
  t ->
  P.Sem r (Either RestError ())
followUp :: forall t (r :: EffectRow).
(Members
   '[InteractionEff, RatelimitEff, TokenEff, LogEff, MetricEff,
     Embed IO]
   r,
 ToMessage t) =>
t -> Sem r (Either RestError ())
followUp (forall a. ToMessage a => a -> CreateMessageOptions
runToMessage -> CreateMessageOptions
msg) =
  let opts :: InteractionCallbackMessageOptions
opts =
        InteractionCallbackMessageOptions
          { $sel:tts:InteractionCallbackMessageOptions :: Maybe Bool
tts = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "tts" a => a
#tts
          , $sel:content:InteractionCallbackMessageOptions :: Maybe Text
content = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "content" a => a
#content
          , $sel:embeds:InteractionCallbackMessageOptions :: Maybe [Embed]
embeds = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "embeds" a => a
#embeds
          , $sel:allowedMentions:InteractionCallbackMessageOptions :: Maybe AllowedMentions
allowedMentions = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "allowedMentions" a => a
#allowedMentions
          , $sel:ephemeral:InteractionCallbackMessageOptions :: Maybe Bool
ephemeral = forall a. Maybe a
Nothing
          , $sel:suppressEmbeds:InteractionCallbackMessageOptions :: Maybe Bool
suppressEmbeds = forall a. Maybe a
Nothing
          , $sel:components:InteractionCallbackMessageOptions :: Maybe [Component]
components = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "components" a => a
#components
          , $sel:attachments:InteractionCallbackMessageOptions :: Maybe [CreateMessageAttachment]
attachments = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "attachments" a => a
#attachments
          }
   in do
        Snowflake Application
applicationID <- forall (r :: EffectRow).
Member InteractionEff r =>
Sem r (Snowflake Application)
getApplicationID
        InteractionToken
interactionToken <- forall (r :: EffectRow).
Member InteractionEff r =>
Sem r InteractionToken
getInteractionToken
        forall (r :: EffectRow) a.
(Members '[RatelimitEff, TokenEff, LogEff, MetricEff, Embed IO] r,
 Request a, ReadResponse (Result a)) =>
a -> Sem r (Either RestError (Result a))
invoke forall a b. (a -> b) -> a -> b
$ forall i.
HasID Application i =>
i
-> InteractionToken
-> InteractionCallbackMessageOptions
-> InteractionRequest ()
CreateFollowupMessage Snowflake Application
applicationID InteractionToken
interactionToken InteractionCallbackMessageOptions
opts

-- | Create an ephemeral follow up response to an interaction
followUpEphemeral :: forall t r.
  (P.Members '[InteractionEff, RatelimitEff, TokenEff, LogEff, MetricEff, P.Embed IO] r, ToMessage t) =>
  t ->
  P.Sem r (Either RestError ())
followUpEphemeral :: forall t (r :: EffectRow).
(Members
   '[InteractionEff, RatelimitEff, TokenEff, LogEff, MetricEff,
     Embed IO]
   r,
 ToMessage t) =>
t -> Sem r (Either RestError ())
followUpEphemeral (forall a. ToMessage a => a -> CreateMessageOptions
runToMessage -> CreateMessageOptions
msg) =
  let opts :: InteractionCallbackMessageOptions
opts =
        InteractionCallbackMessageOptions
          { $sel:tts:InteractionCallbackMessageOptions :: Maybe Bool
tts = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "tts" a => a
#tts
          , $sel:content:InteractionCallbackMessageOptions :: Maybe Text
content = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "content" a => a
#content
          , $sel:embeds:InteractionCallbackMessageOptions :: Maybe [Embed]
embeds = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "embeds" a => a
#embeds
          , $sel:allowedMentions:InteractionCallbackMessageOptions :: Maybe AllowedMentions
allowedMentions = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "allowedMentions" a => a
#allowedMentions
          , $sel:ephemeral:InteractionCallbackMessageOptions :: Maybe Bool
ephemeral = forall a. a -> Maybe a
Just Bool
True
          , $sel:suppressEmbeds:InteractionCallbackMessageOptions :: Maybe Bool
suppressEmbeds = forall a. Maybe a
Nothing
          , $sel:components:InteractionCallbackMessageOptions :: Maybe [Component]
components = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "components" a => a
#components
          , $sel:attachments:InteractionCallbackMessageOptions :: Maybe [CreateMessageAttachment]
attachments = CreateMessageOptions
msg forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "attachments" a => a
#attachments
          }
   in do
        Snowflake Application
applicationID <- forall (r :: EffectRow).
Member InteractionEff r =>
Sem r (Snowflake Application)
getApplicationID
        InteractionToken
interactionToken <- forall (r :: EffectRow).
Member InteractionEff r =>
Sem r InteractionToken
getInteractionToken
        forall (r :: EffectRow) a.
(Members '[RatelimitEff, TokenEff, LogEff, MetricEff, Embed IO] r,
 Request a, ReadResponse (Result a)) =>
a -> Sem r (Either RestError (Result a))
invoke forall a b. (a -> b) -> a -> b
$ forall i.
HasID Application i =>
i
-> InteractionToken
-> InteractionCallbackMessageOptions
-> InteractionRequest ()
CreateFollowupMessage Snowflake Application
applicationID InteractionToken
interactionToken InteractionCallbackMessageOptions
opts

-- | Defer an interaction and show a loading state, use @followUp@ later on
defer :: P.Members '[InteractionEff, RatelimitEff, TokenEff, LogEff, MetricEff, P.Embed IO] r => P.Sem r (Either RestError ())
defer :: forall (r :: EffectRow).
Members
  '[InteractionEff, RatelimitEff, TokenEff, LogEff, MetricEff,
    Embed IO]
  r =>
Sem r (Either RestError ())
defer = do
  Snowflake Interaction
interactionID <- forall (r :: EffectRow).
Member InteractionEff r =>
Sem r (Snowflake Interaction)
getInteractionID
  InteractionToken
interactionToken <- forall (r :: EffectRow).
Member InteractionEff r =>
Sem r InteractionToken
getInteractionToken
  forall (r :: EffectRow) a.
(Members '[RatelimitEff, TokenEff, LogEff, MetricEff, Embed IO] r,
 Request a, ReadResponse (Result a)) =>
a -> Sem r (Either RestError (Result a))
invoke forall a b. (a -> b) -> a -> b
$ forall i.
HasID Interaction i =>
i -> InteractionToken -> Bool -> InteractionRequest ()
CreateResponseDefer Snowflake Interaction
interactionID InteractionToken
interactionToken Bool
False

-- | Defer an interaction and show an ephemeral loading state, use @followUp@
-- later on
deferEphemeral :: P.Members '[InteractionEff, RatelimitEff, TokenEff, LogEff, MetricEff, P.Embed IO] r => P.Sem r (Either RestError ())
deferEphemeral :: forall (r :: EffectRow).
Members
  '[InteractionEff, RatelimitEff, TokenEff, LogEff, MetricEff,
    Embed IO]
  r =>
Sem r (Either RestError ())
deferEphemeral = do
  Snowflake Interaction
interactionID <- forall (r :: EffectRow).
Member InteractionEff r =>
Sem r (Snowflake Interaction)
getInteractionID
  InteractionToken
interactionToken <- forall (r :: EffectRow).
Member InteractionEff r =>
Sem r InteractionToken
getInteractionToken
  forall (r :: EffectRow) a.
(Members '[RatelimitEff, TokenEff, LogEff, MetricEff, Embed IO] r,
 Request a, ReadResponse (Result a)) =>
a -> Sem r (Either RestError (Result a))
invoke forall a b. (a -> b) -> a -> b
$ forall i.
HasID Interaction i =>
i -> InteractionToken -> Bool -> InteractionRequest ()
CreateResponseDefer Snowflake Interaction
interactionID InteractionToken
interactionToken Bool
True

-- | Defer operation
deferComponent :: P.Members '[InteractionEff, RatelimitEff, TokenEff, LogEff, MetricEff, P.Embed IO] r => P.Sem r (Either RestError ())
deferComponent :: forall (r :: EffectRow).
Members
  '[InteractionEff, RatelimitEff, TokenEff, LogEff, MetricEff,
    Embed IO]
  r =>
Sem r (Either RestError ())
deferComponent = do
  Snowflake Interaction
interactionID <- forall (r :: EffectRow).
Member InteractionEff r =>
Sem r (Snowflake Interaction)
getInteractionID
  InteractionToken
interactionToken <- forall (r :: EffectRow).
Member InteractionEff r =>
Sem r InteractionToken
getInteractionToken
  forall (r :: EffectRow) a.
(Members '[RatelimitEff, TokenEff, LogEff, MetricEff, Embed IO] r,
 Request a, ReadResponse (Result a)) =>
a -> Sem r (Either RestError (Result a))
invoke forall a b. (a -> b) -> a -> b
$ forall i.
HasID Interaction i =>
i -> InteractionToken -> InteractionRequest ()
CreateResponseDeferComponent Snowflake Interaction
interactionID InteractionToken
interactionToken

fixupActionRow :: Component -> Component
fixupActionRow :: Component -> Component
fixupActionRow r :: Component
r@(ActionRow' [Component]
_) = Component
r
fixupActionRow Component
x = [Component] -> Component
ActionRow' [Component
x]

{- | Push a modal as a response to an interaction

 You should probably use this with 'Calamity.Interaction.View.runView'
-}
pushModal :: P.Members '[InteractionEff, RatelimitEff, TokenEff, LogEff, MetricEff, P.Embed IO] r => Text -> [Component] -> P.Sem r (Either RestError ())
pushModal :: forall (r :: EffectRow).
Members
  '[InteractionEff, RatelimitEff, TokenEff, LogEff, MetricEff,
    Embed IO]
  r =>
Text -> [Component] -> Sem r (Either RestError ())
pushModal Text
title [Component]
c = do
  -- we don't actually use the custom id of the modal. the custom ids of the
  -- sub-components are enough to disambiguate
  CustomID
cid <- forall (m :: * -> *) (r :: EffectRow) a.
Member (Embed m) r =>
m a -> Sem r a
P.embed forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadIO m => (StdGen -> (a, StdGen)) -> m a
getStdRandom forall g a. (RandomGen g, Uniform a) => g -> (a, g)
uniform
  Snowflake Interaction
interactionID <- forall (r :: EffectRow).
Member InteractionEff r =>
Sem r (Snowflake Interaction)
getInteractionID
  InteractionToken
interactionToken <- forall (r :: EffectRow).
Member InteractionEff r =>
Sem r InteractionToken
getInteractionToken
  forall (r :: EffectRow) a.
(Members '[RatelimitEff, TokenEff, LogEff, MetricEff, Embed IO] r,
 Request a, ReadResponse (Result a)) =>
a -> Sem r (Either RestError (Result a))
invoke forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall i.
HasID Interaction i =>
i
-> InteractionToken
-> InteractionCallbackModal
-> InteractionRequest ()
CreateResponseModal Snowflake Interaction
interactionID InteractionToken
interactionToken forall a b. (a -> b) -> a -> b
$ CustomID -> Text -> [Component] -> InteractionCallbackModal
InteractionCallbackModal CustomID
cid Text
title (forall a b. (a -> b) -> [a] -> [b]
map Component -> Component
fixupActionRow [Component]
c)