calamity-0.3.0.0: A library for writing discord bots in haskell
Safe HaskellNone
LanguageHaskell2010

Calamity.Interactions.View

Synopsis

Documentation

data ViewEff ret inp sendResp m a where Source #

Constructors

EndView :: ret -> ViewEff ret inp sendResp m ()

Mark the view as finished and set the return value.

This doesn't trigger the immediate exit from the code it is used in, the view will exit before it would wait for the next event.

ReplaceView :: View inp -> ([Component] -> m ()) -> ViewEff ret inp sendResp m ()

Given a view and a way to display the rendered view to discord, show the view and start tracking the new view

This works for both message components and modals

GetSendResponse :: ViewEff ret inp sendResp m sendResp

Get the result of the action that sent a value

endView :: forall ret inp sendResp r. Member (ViewEff ret inp sendResp) r => ret -> Sem r () Source #

replaceView :: forall ret inp sendResp r. Member (ViewEff ret inp sendResp) r => View inp -> ([Component] -> Sem r ()) -> Sem r () Source #

getSendResponse :: forall ret inp sendResp r. Member (ViewEff ret inp sendResp) r => Sem r sendResp Source #

data View a Source #

A view containing one or more components

This has an applicative interface to allow for easy composition of components.

Instances

Instances details
(TypeError MonadViewMessage :: Constraint) => Monad View Source # 
Instance details

Defined in Calamity.Interactions.View

Methods

(>>=) :: View a -> (a -> View b) -> View b #

(>>) :: View a -> View b -> View b #

return :: a -> View a #

Functor View Source # 
Instance details

Defined in Calamity.Interactions.View

Methods

fmap :: (a -> b) -> View a -> View b #

(<$) :: a -> View b -> View a #

Applicative View Source # 
Instance details

Defined in Calamity.Interactions.View

Methods

pure :: a -> View a #

(<*>) :: View (a -> b) -> View a -> View b #

liftA2 :: (a -> b -> c) -> View a -> View b -> View c #

(*>) :: View a -> View b -> View b #

(<*) :: View a -> View b -> View a #

row :: View a -> View a Source #

Convert a View such that it renders as a row.

Note: nested rows are not allowed by discord, along with further restrictions listed here: https://discord.com/developers/docs/interactions/message-components

runView Source #

Arguments

:: BotC r 
=> View inp

The initial view to render

-> ([Component] -> Sem r sendResp)

A function to send the rendered view (i.e. as a message or a modal)

-> (inp -> Sem (InteractionEff ': (ViewEff a inp sendResp ': r)) ())

Your callback effect.

local state semantics are preserved between calls here, you can keep state around

-> Sem r a 

Run a View, returning the value passed to endView

This function will not return until endView is used inside the view. If you want it to run in the background, consider using Polysemy.Async.

This is async exception safe, you can use libraries such as polysemy-conc to stop views after a timeout.

runViewInstance Source #

Arguments

:: BotC r 
=> sendResp

An initial value to act as the value of GetSendResponse

If you just sent a message, probably pass that

-> ViewInstance inp

The initial view to run

-> (inp -> Sem (InteractionEff ': (ViewEff a inp sendResp ': r)) ())

Your callback effect.

In here you get access to the InteractionEff and ViewEff effects.

local state semantics are preserved between calls here, you can keep state around

-> Sem r a 

Run a prerendered View, returning the value passed to endView

This function won't send the view, you should do that yourself

button :: ButtonStyle -> Text -> View Bool Source #

Construct a View containing a Button with the given style and label

Other fields of Button default to Nothing

button' :: (Button -> Button) -> View Bool Source #

Construct a View containing a Button, then modify the component with the passed mapping function

The Button passed to the mapping function will have a style of ButtonPrimary, other fields will be Nothing

select :: [Text] -> View (Maybe Text) Source #

Construct a View containing a Select with the given list of values

Each element of the passed options list is used as both the display label and value, use select' if you desire more control

select' :: [SelectOption] -> (Select -> Select) -> View (Maybe [Text]) Source #

Construct a View containing a Select with the given options, then modify the component with the passed mapping function

textInput Source #

Arguments

:: TextInputStyle 
-> Text

Label

-> View Text 

Construct a View containing a TextInput with the given style and label

All other fields of TextInput default to Nothing

This view ensures that a value was passed for an input

textInput' Source #

Arguments

:: TextInputStyle 
-> Text

Label

-> (TextInput -> TextInput) 
-> View (Maybe Text) 

Construct a View containing a TextInput with the given style and label, then modify the component with the passed mapping function

deleteInitialMsg :: (BotC r, Member (ViewEff a inp (Either e Message)) r) => Sem r () Source #

Delete the initial message containing components

instantiateView :: RandomGen g => g -> View a -> (ViewInstance a, g) Source #

Generate a ViewInstance of a View by filling in CustomIDs with random values