{-# LANGUAGE TemplateHaskell #-}

-- | Webhook endpoints
module Calamity.HTTP.Webhook (
  WebhookRequest (..),
  CreateWebhookData (..),
  ModifyWebhookData (..),
  ExecuteWebhookOptions (..),
) where

import Calamity.HTTP.Channel (AllowedMentions, CreateMessageAttachment (..))
import Calamity.HTTP.Internal.Request
import Calamity.HTTP.Internal.Route
import Calamity.Internal.Utils (CalamityToJSON (..), CalamityToJSON' (..), (.=), (.?=))
import Calamity.Types.Model.Channel
import Calamity.Types.Model.Guild
import Calamity.Types.Snowflake
import qualified Data.Aeson as Aeson
import Data.Default.Class
import Data.Text (Text)
import qualified Data.Text as T
import Network.HTTP.Client.MultipartFormData
import Network.HTTP.Req
import Network.Mime
import Optics
import PyF

data CreateWebhookData = CreateWebhookData
  { CreateWebhookData -> Maybe Text
username :: Maybe Text
  , -- | The avatar field should be in discord's image data format: https://discord.com/developers/docs/reference#image-data
    CreateWebhookData -> Maybe Text
avatar :: Maybe Text
  }
  deriving (Int -> CreateWebhookData -> ShowS
[CreateWebhookData] -> ShowS
CreateWebhookData -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateWebhookData] -> ShowS
$cshowList :: [CreateWebhookData] -> ShowS
show :: CreateWebhookData -> String
$cshow :: CreateWebhookData -> String
showsPrec :: Int -> CreateWebhookData -> ShowS
$cshowsPrec :: Int -> CreateWebhookData -> ShowS
Show)
  deriving ([CreateWebhookData] -> Encoding
[CreateWebhookData] -> Value
CreateWebhookData -> Encoding
CreateWebhookData -> Value
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [CreateWebhookData] -> Encoding
$ctoEncodingList :: [CreateWebhookData] -> Encoding
toJSONList :: [CreateWebhookData] -> Value
$ctoJSONList :: [CreateWebhookData] -> Value
toEncoding :: CreateWebhookData -> Encoding
$ctoEncoding :: CreateWebhookData -> Encoding
toJSON :: CreateWebhookData -> Value
$ctoJSON :: CreateWebhookData -> Value
Aeson.ToJSON) via CalamityToJSON CreateWebhookData

instance CalamityToJSON' CreateWebhookData where
  toPairs :: forall kv. KeyValue kv => CreateWebhookData -> [Maybe kv]
toPairs CreateWebhookData {Maybe Text
avatar :: Maybe Text
username :: Maybe Text
$sel:avatar:CreateWebhookData :: CreateWebhookData -> Maybe Text
$sel:username:CreateWebhookData :: CreateWebhookData -> Maybe Text
..} =
    [ Key
"username" forall v kv. (ToJSON v, KeyValue kv) => Key -> Maybe v -> Maybe kv
.?= Maybe Text
username
    , Key
"avatar" forall v kv. (ToJSON v, KeyValue kv) => Key -> Maybe v -> Maybe kv
.?= Maybe Text
avatar
    ]

instance Default CreateWebhookData where
  def :: CreateWebhookData
def = Maybe Text -> Maybe Text -> CreateWebhookData
CreateWebhookData forall a. Maybe a
Nothing forall a. Maybe a
Nothing

data ModifyWebhookData = ModifyWebhookData
  { ModifyWebhookData -> Maybe Text
username :: Maybe Text
  , -- | The avatar field should be in discord's image data format: https://discord.com/developers/docs/reference#image-data
    ModifyWebhookData -> Maybe Text
avatar :: Maybe Text
  , ModifyWebhookData -> Maybe (Snowflake Channel)
channelID :: Maybe (Snowflake Channel)
  }
  deriving (Int -> ModifyWebhookData -> ShowS
[ModifyWebhookData] -> ShowS
ModifyWebhookData -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ModifyWebhookData] -> ShowS
$cshowList :: [ModifyWebhookData] -> ShowS
show :: ModifyWebhookData -> String
$cshow :: ModifyWebhookData -> String
showsPrec :: Int -> ModifyWebhookData -> ShowS
$cshowsPrec :: Int -> ModifyWebhookData -> ShowS
Show)
  deriving ([ModifyWebhookData] -> Encoding
[ModifyWebhookData] -> Value
ModifyWebhookData -> Encoding
ModifyWebhookData -> Value
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [ModifyWebhookData] -> Encoding
$ctoEncodingList :: [ModifyWebhookData] -> Encoding
toJSONList :: [ModifyWebhookData] -> Value
$ctoJSONList :: [ModifyWebhookData] -> Value
toEncoding :: ModifyWebhookData -> Encoding
$ctoEncoding :: ModifyWebhookData -> Encoding
toJSON :: ModifyWebhookData -> Value
$ctoJSON :: ModifyWebhookData -> Value
Aeson.ToJSON) via CalamityToJSON ModifyWebhookData

instance CalamityToJSON' ModifyWebhookData where
  toPairs :: forall kv. KeyValue kv => ModifyWebhookData -> [Maybe kv]
toPairs ModifyWebhookData {Maybe Text
Maybe (Snowflake Channel)
channelID :: Maybe (Snowflake Channel)
avatar :: Maybe Text
username :: Maybe Text
$sel:channelID:ModifyWebhookData :: ModifyWebhookData -> Maybe (Snowflake Channel)
$sel:avatar:ModifyWebhookData :: ModifyWebhookData -> Maybe Text
$sel:username:ModifyWebhookData :: ModifyWebhookData -> Maybe Text
..} =
    [ Key
"username" forall v kv. (ToJSON v, KeyValue kv) => Key -> Maybe v -> Maybe kv
.?= Maybe Text
username
    , Key
"avatar" forall v kv. (ToJSON v, KeyValue kv) => Key -> Maybe v -> Maybe kv
.?= Maybe Text
avatar
    , Key
"channel_id" forall v kv. (ToJSON v, KeyValue kv) => Key -> Maybe v -> Maybe kv
.?= Maybe (Snowflake Channel)
channelID
    ]

instance Default ModifyWebhookData where
  def :: ModifyWebhookData
def = Maybe Text
-> Maybe Text -> Maybe (Snowflake Channel) -> ModifyWebhookData
ModifyWebhookData forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing

data ExecuteWebhookOptions = ExecuteWebhookOptions
  { ExecuteWebhookOptions -> Maybe Bool
wait :: Maybe Bool
  , ExecuteWebhookOptions -> Maybe Text
content :: Maybe Text
  , ExecuteWebhookOptions -> [CreateMessageAttachment]
attachments :: [CreateMessageAttachment]
  , ExecuteWebhookOptions -> Maybe [Embed]
embeds :: Maybe [Embed]
  , ExecuteWebhookOptions -> Maybe Text
username :: Maybe Text
  , ExecuteWebhookOptions -> Maybe Text
avatarUrl :: Maybe Text
  , ExecuteWebhookOptions -> Maybe AllowedMentions
allowedMentions :: Maybe AllowedMentions
  , ExecuteWebhookOptions -> Maybe Bool
tts :: Maybe Bool
  , ExecuteWebhookOptions -> [Component]
components :: [Component]
  }
  deriving (Int -> ExecuteWebhookOptions -> ShowS
[ExecuteWebhookOptions] -> ShowS
ExecuteWebhookOptions -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ExecuteWebhookOptions] -> ShowS
$cshowList :: [ExecuteWebhookOptions] -> ShowS
show :: ExecuteWebhookOptions -> String
$cshow :: ExecuteWebhookOptions -> String
showsPrec :: Int -> ExecuteWebhookOptions -> ShowS
$cshowsPrec :: Int -> ExecuteWebhookOptions -> ShowS
Show)

instance Default ExecuteWebhookOptions where
  def :: ExecuteWebhookOptions
def = Maybe Bool
-> Maybe Text
-> [CreateMessageAttachment]
-> Maybe [Embed]
-> Maybe Text
-> Maybe Text
-> Maybe AllowedMentions
-> Maybe Bool
-> [Component]
-> ExecuteWebhookOptions
ExecuteWebhookOptions forall a. Maybe a
Nothing forall a. Maybe a
Nothing [] forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing []

data CreateMessageAttachmentJson = CreateMessageAttachmentJson
  { CreateMessageAttachmentJson -> Int
id :: Int
  , CreateMessageAttachmentJson -> Text
filename :: Text
  , CreateMessageAttachmentJson -> Maybe Text
description :: Maybe Text
  }
  deriving (Int -> CreateMessageAttachmentJson -> ShowS
[CreateMessageAttachmentJson] -> ShowS
CreateMessageAttachmentJson -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateMessageAttachmentJson] -> ShowS
$cshowList :: [CreateMessageAttachmentJson] -> ShowS
show :: CreateMessageAttachmentJson -> String
$cshow :: CreateMessageAttachmentJson -> String
showsPrec :: Int -> CreateMessageAttachmentJson -> ShowS
$cshowsPrec :: Int -> CreateMessageAttachmentJson -> ShowS
Show)
  deriving ([CreateMessageAttachmentJson] -> Encoding
[CreateMessageAttachmentJson] -> Value
CreateMessageAttachmentJson -> Encoding
CreateMessageAttachmentJson -> Value
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [CreateMessageAttachmentJson] -> Encoding
$ctoEncodingList :: [CreateMessageAttachmentJson] -> Encoding
toJSONList :: [CreateMessageAttachmentJson] -> Value
$ctoJSONList :: [CreateMessageAttachmentJson] -> Value
toEncoding :: CreateMessageAttachmentJson -> Encoding
$ctoEncoding :: CreateMessageAttachmentJson -> Encoding
toJSON :: CreateMessageAttachmentJson -> Value
$ctoJSON :: CreateMessageAttachmentJson -> Value
Aeson.ToJSON) via CalamityToJSON CreateMessageAttachmentJson

instance CalamityToJSON' CreateMessageAttachmentJson where
  toPairs :: forall kv. KeyValue kv => CreateMessageAttachmentJson -> [Maybe kv]
toPairs CreateMessageAttachmentJson {Int
Maybe Text
Text
description :: Maybe Text
filename :: Text
id :: Int
$sel:description:CreateMessageAttachmentJson :: CreateMessageAttachmentJson -> Maybe Text
$sel:filename:CreateMessageAttachmentJson :: CreateMessageAttachmentJson -> Text
$sel:id:CreateMessageAttachmentJson :: CreateMessageAttachmentJson -> Int
..} =
    [ Key
"id" forall v kv. (ToJSON v, KeyValue kv) => Key -> v -> Maybe kv
.= Int
id
    , Key
"filename" forall v kv. (ToJSON v, KeyValue kv) => Key -> v -> Maybe kv
.= Text
filename
    , Key
"description" forall v kv. (ToJSON v, KeyValue kv) => Key -> Maybe v -> Maybe kv
.?= Maybe Text
description
    ]

data ExecuteWebhookJson = ExecuteWebhookJson
  { ExecuteWebhookJson -> Maybe Text
content :: Maybe Text
  , ExecuteWebhookJson -> Maybe [Embed]
embeds :: Maybe [Embed]
  , ExecuteWebhookJson -> Maybe Text
username :: Maybe Text
  , ExecuteWebhookJson -> Maybe Text
avatarUrl :: Maybe Text
  , ExecuteWebhookJson -> Maybe Bool
tts :: Maybe Bool
  , ExecuteWebhookJson -> [CreateMessageAttachmentJson]
attachments :: [CreateMessageAttachmentJson]
  , ExecuteWebhookJson -> Maybe AllowedMentions
allowedMentions :: Maybe AllowedMentions
  , ExecuteWebhookJson -> [Component]
components :: [Component]
  }
  deriving (Int -> ExecuteWebhookJson -> ShowS
[ExecuteWebhookJson] -> ShowS
ExecuteWebhookJson -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ExecuteWebhookJson] -> ShowS
$cshowList :: [ExecuteWebhookJson] -> ShowS
show :: ExecuteWebhookJson -> String
$cshow :: ExecuteWebhookJson -> String
showsPrec :: Int -> ExecuteWebhookJson -> ShowS
$cshowsPrec :: Int -> ExecuteWebhookJson -> ShowS
Show)
  deriving ([ExecuteWebhookJson] -> Encoding
[ExecuteWebhookJson] -> Value
ExecuteWebhookJson -> Encoding
ExecuteWebhookJson -> Value
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [ExecuteWebhookJson] -> Encoding
$ctoEncodingList :: [ExecuteWebhookJson] -> Encoding
toJSONList :: [ExecuteWebhookJson] -> Value
$ctoJSONList :: [ExecuteWebhookJson] -> Value
toEncoding :: ExecuteWebhookJson -> Encoding
$ctoEncoding :: ExecuteWebhookJson -> Encoding
toJSON :: ExecuteWebhookJson -> Value
$ctoJSON :: ExecuteWebhookJson -> Value
Aeson.ToJSON) via CalamityToJSON ExecuteWebhookJson

instance CalamityToJSON' ExecuteWebhookJson where
  toPairs :: forall kv. KeyValue kv => ExecuteWebhookJson -> [Maybe kv]
toPairs ExecuteWebhookJson {[Component]
[CreateMessageAttachmentJson]
Maybe Bool
Maybe [Embed]
Maybe Text
Maybe AllowedMentions
components :: [Component]
allowedMentions :: Maybe AllowedMentions
attachments :: [CreateMessageAttachmentJson]
tts :: Maybe Bool
avatarUrl :: Maybe Text
username :: Maybe Text
embeds :: Maybe [Embed]
content :: Maybe Text
$sel:components:ExecuteWebhookJson :: ExecuteWebhookJson -> [Component]
$sel:allowedMentions:ExecuteWebhookJson :: ExecuteWebhookJson -> Maybe AllowedMentions
$sel:attachments:ExecuteWebhookJson :: ExecuteWebhookJson -> [CreateMessageAttachmentJson]
$sel:tts:ExecuteWebhookJson :: ExecuteWebhookJson -> Maybe Bool
$sel:avatarUrl:ExecuteWebhookJson :: ExecuteWebhookJson -> Maybe Text
$sel:username:ExecuteWebhookJson :: ExecuteWebhookJson -> Maybe Text
$sel:embeds:ExecuteWebhookJson :: ExecuteWebhookJson -> Maybe [Embed]
$sel:content:ExecuteWebhookJson :: ExecuteWebhookJson -> Maybe Text
..} =
    [ Key
"content" forall v kv. (ToJSON v, KeyValue kv) => Key -> Maybe v -> Maybe kv
.?= Maybe Text
content
    , Key
"embeds" forall v kv. (ToJSON v, KeyValue kv) => Key -> Maybe v -> Maybe kv
.?= Maybe [Embed]
embeds
    , Key
"avatar_url" forall v kv. (ToJSON v, KeyValue kv) => Key -> Maybe v -> Maybe kv
.?= Maybe Text
avatarUrl
    , Key
"tts" forall v kv. (ToJSON v, KeyValue kv) => Key -> Maybe v -> Maybe kv
.?= Maybe Bool
tts
    , Key
"attachments" forall v kv. (ToJSON v, KeyValue kv) => Key -> v -> Maybe kv
.= [CreateMessageAttachmentJson]
attachments
    , Key
"allowed_mentions" forall v kv. (ToJSON v, KeyValue kv) => Key -> Maybe v -> Maybe kv
.?= Maybe AllowedMentions
allowedMentions
    , Key
"components" forall v kv. (ToJSON v, KeyValue kv) => Key -> v -> Maybe kv
.= [Component]
components
    ]

$(makeFieldLabelsNoPrefix ''CreateWebhookData)
$(makeFieldLabelsNoPrefix ''ModifyWebhookData)
$(makeFieldLabelsNoPrefix ''ExecuteWebhookOptions)

data WebhookRequest a where
  CreateWebhook :: HasID Channel c => c -> CreateWebhookData -> WebhookRequest Webhook
  GetChannelWebhooks :: HasID Channel c => c -> WebhookRequest [Webhook]
  GetGuildWebhooks :: HasID Guild c => c -> WebhookRequest [Webhook]
  GetWebhook :: HasID Webhook w => w -> WebhookRequest Webhook
  GetWebhookToken :: HasID Webhook w => w -> Text -> WebhookRequest Webhook
  ModifyWebhook :: HasID Webhook w => w -> ModifyWebhookData -> WebhookRequest Webhook
  ModifyWebhookToken :: HasID Webhook w => w -> Text -> ModifyWebhookData -> WebhookRequest Webhook
  DeleteWebhook :: HasID Webhook w => w -> WebhookRequest ()
  DeleteWebhookToken :: HasID Webhook w => w -> Text -> WebhookRequest ()
  ExecuteWebhook :: HasID Webhook w => w -> Text -> ExecuteWebhookOptions -> WebhookRequest ()

baseRoute :: Snowflake Webhook -> RouteBuilder _
baseRoute :: Snowflake Webhook
-> RouteBuilder
     '[ '( 'IDRequirement Webhook, 'Satisfied),
        '( 'IDRequirement Webhook,
           AddRequiredInner (Lookup ('IDRequirement Webhook) '[]))]
baseRoute Snowflake Webhook
id = RouteBuilder '[]
mkRouteBuilder forall a (reqs :: [(RequirementType, RouteRequirement)]).
RouteFragmentable a reqs =>
RouteBuilder reqs -> a -> ConsRes a reqs
// Text -> S
S Text
"webhooks" forall a (reqs :: [(RequirementType, RouteRequirement)]).
RouteFragmentable a reqs =>
RouteBuilder reqs -> a -> ConsRes a reqs
// forall {k} (a :: k). ID a
ID @Webhook forall a b. a -> (a -> b) -> b
& forall t (reqs :: [(RequirementType, RouteRequirement)]).
Typeable t =>
Snowflake t
-> RouteBuilder reqs
-> RouteBuilder ('( 'IDRequirement t, 'Satisfied) : reqs)
giveID Snowflake Webhook
id

instance Request (WebhookRequest a) where
  type Result (WebhookRequest a) = a

  route :: WebhookRequest a -> Route
route (CreateWebhook (forall b a. HasID b a => a -> Snowflake b
getID @Channel -> Snowflake Channel
cid) CreateWebhookData
_) =
    RouteBuilder '[]
mkRouteBuilder forall a (reqs :: [(RequirementType, RouteRequirement)]).
RouteFragmentable a reqs =>
RouteBuilder reqs -> a -> ConsRes a reqs
// Text -> S
S Text
"channels" forall a (reqs :: [(RequirementType, RouteRequirement)]).
RouteFragmentable a reqs =>
RouteBuilder reqs -> a -> ConsRes a reqs
// forall {k} (a :: k). ID a
ID @Channel forall a (reqs :: [(RequirementType, RouteRequirement)]).
RouteFragmentable a reqs =>
RouteBuilder reqs -> a -> ConsRes a reqs
// Text -> S
S Text
"webhooks"
      forall a b. a -> (a -> b) -> b
& forall t (reqs :: [(RequirementType, RouteRequirement)]).
Typeable t =>
Snowflake t
-> RouteBuilder reqs
-> RouteBuilder ('( 'IDRequirement t, 'Satisfied) : reqs)
giveID Snowflake Channel
cid
      forall a b. a -> (a -> b) -> b
& forall (reqs :: [(RequirementType, RouteRequirement)]).
EnsureFulfilled reqs =>
RouteBuilder reqs -> Route
buildRoute
  route (GetChannelWebhooks (forall b a. HasID b a => a -> Snowflake b
getID @Channel -> Snowflake Channel
cid)) =
    RouteBuilder '[]
mkRouteBuilder forall a (reqs :: [(RequirementType, RouteRequirement)]).
RouteFragmentable a reqs =>
RouteBuilder reqs -> a -> ConsRes a reqs
// Text -> S
S Text
"channels" forall a (reqs :: [(RequirementType, RouteRequirement)]).
RouteFragmentable a reqs =>
RouteBuilder reqs -> a -> ConsRes a reqs
// forall {k} (a :: k). ID a
ID @Channel forall a (reqs :: [(RequirementType, RouteRequirement)]).
RouteFragmentable a reqs =>
RouteBuilder reqs -> a -> ConsRes a reqs
// Text -> S
S Text
"webhooks"
      forall a b. a -> (a -> b) -> b
& forall t (reqs :: [(RequirementType, RouteRequirement)]).
Typeable t =>
Snowflake t
-> RouteBuilder reqs
-> RouteBuilder ('( 'IDRequirement t, 'Satisfied) : reqs)
giveID Snowflake Channel
cid
      forall a b. a -> (a -> b) -> b
& forall (reqs :: [(RequirementType, RouteRequirement)]).
EnsureFulfilled reqs =>
RouteBuilder reqs -> Route
buildRoute
  route (GetGuildWebhooks (forall b a. HasID b a => a -> Snowflake b
getID @Guild -> Snowflake Guild
gid)) =
    RouteBuilder '[]
mkRouteBuilder forall a (reqs :: [(RequirementType, RouteRequirement)]).
RouteFragmentable a reqs =>
RouteBuilder reqs -> a -> ConsRes a reqs
// Text -> S
S Text
"guilds" forall a (reqs :: [(RequirementType, RouteRequirement)]).
RouteFragmentable a reqs =>
RouteBuilder reqs -> a -> ConsRes a reqs
// forall {k} (a :: k). ID a
ID @Guild forall a (reqs :: [(RequirementType, RouteRequirement)]).
RouteFragmentable a reqs =>
RouteBuilder reqs -> a -> ConsRes a reqs
// Text -> S
S Text
"webhooks"
      forall a b. a -> (a -> b) -> b
& forall t (reqs :: [(RequirementType, RouteRequirement)]).
Typeable t =>
Snowflake t
-> RouteBuilder reqs
-> RouteBuilder ('( 'IDRequirement t, 'Satisfied) : reqs)
giveID Snowflake Guild
gid
      forall a b. a -> (a -> b) -> b
& forall (reqs :: [(RequirementType, RouteRequirement)]).
EnsureFulfilled reqs =>
RouteBuilder reqs -> Route
buildRoute
  route (GetWebhook (forall b a. HasID b a => a -> Snowflake b
getID @Webhook -> Snowflake Webhook
wid)) =
    Snowflake Webhook
-> RouteBuilder
     '[ '( 'IDRequirement Webhook, 'Satisfied),
        '( 'IDRequirement Webhook, 'Required)]
baseRoute Snowflake Webhook
wid
      forall a b. a -> (a -> b) -> b
& forall (reqs :: [(RequirementType, RouteRequirement)]).
EnsureFulfilled reqs =>
RouteBuilder reqs -> Route
buildRoute
  route (GetWebhookToken (forall b a. HasID b a => a -> Snowflake b
getID @Webhook -> Snowflake Webhook
wid) Text
t) =
    Snowflake Webhook
-> RouteBuilder
     '[ '( 'IDRequirement Webhook, 'Satisfied),
        '( 'IDRequirement Webhook, 'Required)]
baseRoute Snowflake Webhook
wid forall a (reqs :: [(RequirementType, RouteRequirement)]).
RouteFragmentable a reqs =>
RouteBuilder reqs -> a -> ConsRes a reqs
// Text -> S
S Text
t
      forall a b. a -> (a -> b) -> b
& forall (reqs :: [(RequirementType, RouteRequirement)]).
EnsureFulfilled reqs =>
RouteBuilder reqs -> Route
buildRoute
  route (ModifyWebhook (forall b a. HasID b a => a -> Snowflake b
getID @Webhook -> Snowflake Webhook
wid) ModifyWebhookData
_) =
    Snowflake Webhook
-> RouteBuilder
     '[ '( 'IDRequirement Webhook, 'Satisfied),
        '( 'IDRequirement Webhook, 'Required)]
baseRoute Snowflake Webhook
wid
      forall a b. a -> (a -> b) -> b
& forall (reqs :: [(RequirementType, RouteRequirement)]).
EnsureFulfilled reqs =>
RouteBuilder reqs -> Route
buildRoute
  route (ModifyWebhookToken (forall b a. HasID b a => a -> Snowflake b
getID @Webhook -> Snowflake Webhook
wid) Text
t ModifyWebhookData
_) =
    Snowflake Webhook
-> RouteBuilder
     '[ '( 'IDRequirement Webhook, 'Satisfied),
        '( 'IDRequirement Webhook, 'Required)]
baseRoute Snowflake Webhook
wid forall a (reqs :: [(RequirementType, RouteRequirement)]).
RouteFragmentable a reqs =>
RouteBuilder reqs -> a -> ConsRes a reqs
// Text -> S
S Text
t
      forall a b. a -> (a -> b) -> b
& forall (reqs :: [(RequirementType, RouteRequirement)]).
EnsureFulfilled reqs =>
RouteBuilder reqs -> Route
buildRoute
  route (DeleteWebhook (forall b a. HasID b a => a -> Snowflake b
getID @Webhook -> Snowflake Webhook
wid)) =
    Snowflake Webhook
-> RouteBuilder
     '[ '( 'IDRequirement Webhook, 'Satisfied),
        '( 'IDRequirement Webhook, 'Required)]
baseRoute Snowflake Webhook
wid
      forall a b. a -> (a -> b) -> b
& forall (reqs :: [(RequirementType, RouteRequirement)]).
EnsureFulfilled reqs =>
RouteBuilder reqs -> Route
buildRoute
  route (DeleteWebhookToken (forall b a. HasID b a => a -> Snowflake b
getID @Webhook -> Snowflake Webhook
wid) Text
t) =
    Snowflake Webhook
-> RouteBuilder
     '[ '( 'IDRequirement Webhook, 'Satisfied),
        '( 'IDRequirement Webhook, 'Required)]
baseRoute Snowflake Webhook
wid forall a (reqs :: [(RequirementType, RouteRequirement)]).
RouteFragmentable a reqs =>
RouteBuilder reqs -> a -> ConsRes a reqs
// Text -> S
S Text
t
      forall a b. a -> (a -> b) -> b
& forall (reqs :: [(RequirementType, RouteRequirement)]).
EnsureFulfilled reqs =>
RouteBuilder reqs -> Route
buildRoute
  route (ExecuteWebhook (forall b a. HasID b a => a -> Snowflake b
getID @Webhook -> Snowflake Webhook
wid) Text
t ExecuteWebhookOptions
_) =
    Snowflake Webhook
-> RouteBuilder
     '[ '( 'IDRequirement Webhook, 'Satisfied),
        '( 'IDRequirement Webhook, 'Required)]
baseRoute Snowflake Webhook
wid forall a (reqs :: [(RequirementType, RouteRequirement)]).
RouteFragmentable a reqs =>
RouteBuilder reqs -> a -> ConsRes a reqs
// Text -> S
S Text
t
      forall a b. a -> (a -> b) -> b
& forall (reqs :: [(RequirementType, RouteRequirement)]).
EnsureFulfilled reqs =>
RouteBuilder reqs -> Route
buildRoute

  action :: WebhookRequest a -> Url 'Https -> Option 'Https -> Req LbsResponse
action (CreateWebhook c
_ CreateWebhookData
o) = forall a.
HttpBody a =>
a -> Url 'Https -> Option 'Https -> Req LbsResponse
postWith' forall a b. (a -> b) -> a -> b
$ forall a. a -> ReqBodyJson a
ReqBodyJson CreateWebhookData
o
  action (GetChannelWebhooks c
_) = Url 'Https -> Option 'Https -> Req LbsResponse
getWith
  action (GetGuildWebhooks c
_) = Url 'Https -> Option 'Https -> Req LbsResponse
getWith
  action (GetWebhook w
_) = Url 'Https -> Option 'Https -> Req LbsResponse
getWith
  action (GetWebhookToken w
_ Text
_) = Url 'Https -> Option 'Https -> Req LbsResponse
getWith
  action (ModifyWebhook w
_ ModifyWebhookData
o) = forall a.
HttpBody a =>
a -> Url 'Https -> Option 'Https -> Req LbsResponse
patchWith' forall a b. (a -> b) -> a -> b
$ forall a. a -> ReqBodyJson a
ReqBodyJson ModifyWebhookData
o
  action (ModifyWebhookToken w
_ Text
_ ModifyWebhookData
o) = forall a.
HttpBody a =>
a -> Url 'Https -> Option 'Https -> Req LbsResponse
patchWith' forall a b. (a -> b) -> a -> b
$ forall a. a -> ReqBodyJson a
ReqBodyJson ModifyWebhookData
o
  action (DeleteWebhook w
_) = Url 'Https -> Option 'Https -> Req LbsResponse
deleteWith
  action (DeleteWebhookToken w
_ Text
_) = Url 'Https -> Option 'Https -> Req LbsResponse
deleteWith
  action (ExecuteWebhook w
_ Text
_ ExecuteWebhookOptions
wh) = \Url 'Https
u Option 'Https
o -> do
    let filePart :: CreateMessageAttachment -> a -> PartM IO
filePart CreateMessageAttachment {Text
$sel:filename:CreateMessageAttachment :: CreateMessageAttachment -> Text
filename :: Text
filename, ByteString
$sel:content:CreateMessageAttachment :: CreateMessageAttachment -> ByteString
content :: ByteString
content} a
n =
          (forall (m :: * -> *).
Applicative m =>
Text -> ByteString -> PartM m
partLBS @IO (String -> Text
T.pack forall a b. (a -> b) -> a -> b
$ String
"files[" forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show a
n forall a. Semigroup a => a -> a -> a
<> String
"]") ByteString
content)
            { partFilename :: Maybe String
partFilename = forall a. a -> Maybe a
Just (Text -> String
T.unpack Text
filename)
            , partContentType :: Maybe MimeType
partContentType = forall a. a -> Maybe a
Just (Text -> MimeType
defaultMimeLookup Text
filename)
            }
        attachmentPart :: CreateMessageAttachment -> Int -> CreateMessageAttachmentJson
attachmentPart CreateMessageAttachment {Text
filename :: Text
$sel:filename:CreateMessageAttachment :: CreateMessageAttachment -> Text
filename, Maybe Text
$sel:description:CreateMessageAttachment :: CreateMessageAttachment -> Maybe Text
description :: Maybe Text
description} Int
n =
          Int -> Text -> Maybe Text -> CreateMessageAttachmentJson
CreateMessageAttachmentJson Int
n Text
filename Maybe Text
description
        files :: [PartM IO]
files = forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith forall {a}. Show a => CreateMessageAttachment -> a -> PartM IO
filePart (ExecuteWebhookOptions
wh forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "attachments" a => a
#attachments) [(Int
0 :: Int) ..]
        attachments :: [CreateMessageAttachmentJson]
attachments = forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith CreateMessageAttachment -> Int -> CreateMessageAttachmentJson
attachmentPart (ExecuteWebhookOptions
wh forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "attachments" a => a
#attachments) [Int
0 ..]
        jsonBody :: ExecuteWebhookJson
jsonBody =
          ExecuteWebhookJson
            { $sel:content:ExecuteWebhookJson :: Maybe Text
content = ExecuteWebhookOptions
wh 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:username:ExecuteWebhookJson :: Maybe Text
username = ExecuteWebhookOptions
wh forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "username" a => a
#username
            , $sel:avatarUrl:ExecuteWebhookJson :: Maybe Text
avatarUrl = ExecuteWebhookOptions
wh forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "avatarUrl" a => a
#avatarUrl
            , $sel:tts:ExecuteWebhookJson :: Maybe Bool
tts = ExecuteWebhookOptions
wh 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:embeds:ExecuteWebhookJson :: Maybe [Embed]
embeds = ExecuteWebhookOptions
wh 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:ExecuteWebhookJson :: Maybe AllowedMentions
allowedMentions = ExecuteWebhookOptions
wh 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:components:ExecuteWebhookJson :: [Component]
components = ExecuteWebhookOptions
wh 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:ExecuteWebhookJson :: [CreateMessageAttachmentJson]
attachments = [CreateMessageAttachmentJson]
attachments
            }
    ReqBodyMultipart
body <- forall (m :: * -> *). MonadIO m => [PartM IO] -> m ReqBodyMultipart
reqBodyMultipart (forall (m :: * -> *).
Applicative m =>
Text -> ByteString -> PartM m
partLBS Text
"payload_json" (forall a. ToJSON a => a -> ByteString
Aeson.encode ExecuteWebhookJson
jsonBody) forall a. a -> [a] -> [a]
: [PartM IO]
files)
    forall a.
HttpBody a =>
a
-> Option 'Https -> Url 'Https -> Option 'Https -> Req LbsResponse
postWithP' ReqBodyMultipart
body (Text
"wait" forall a. ToHttpApiData a => Text -> Maybe a -> Option 'Https
=:? (ExecuteWebhookOptions
wh forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "wait" a => a
#wait)) Url 'Https
u Option 'Https
o