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

Calamity.Interactions

Description

Calamity Interaction views

Synopsis

Documentation

Interactions and Views

This module contains functions and types related to handling discord interactions.

The data models for components can be found in Calamity.Types.Model.Channel.Component

Examples

Displaying a View


let view = row $ do
      a <- button ButtonPrimary "defer"
      b <- button ButtonPrimary "deferEph"
      c <- button ButtonPrimary "deferComp"
      d <- button ButtonPrimary "modal"
      pure (a, b, c, d)

    modalView = do
      a <- textInput TextInputShort "a"
      b <- textInput TextInputParagraph "b"
      pure (a, b)
in runView view (tell ctx) $ \(a, b, c, d) -> do
     when a $ do
       void defer
       embed $ threadDelay 1000000
       void $ followUp @Text "lol"

     when b $ do
       void deferEphemeral
       embed $ threadDelay 1000000
       void $ followUpEphemeral @Text "lol"

     when c $ do
       void deferComponent
       embed $ threadDelay 1000000
       void $ followUp @Text "lol"

     when d $ do
       void . async $ do
         runView modalView (void . pushModal "lol") $ (a, b) -> do
           embed $ print (a, b)
           void $ respond ("Thanks: " <> a <> " " <> b)
           endView ()

     pure ()