{-# LANGUAGE GADTs #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE OverloadedStrings #-}
module Discord.Internal.Rest.Channel
( ChannelRequest(..)
, MessageDetailedOpts(..)
, AllowedMentions(..)
, ReactionTiming(..)
, MessageTiming(..)
, ChannelInviteOpts(..)
, ModifyChannelOpts(..)
, ChannelPermissionsOpts(..)
, GroupDMAddRecipientOpts(..)
, ChannelPermissionsOptsType(..)
) where
import Data.Aeson
import Data.Default (Default, def)
import Data.Emoji (unicodeByName)
import qualified Data.Text as T
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
import Network.HTTP.Client (RequestBody (RequestBodyBS))
import Network.HTTP.Client.MultipartFormData (partFileRequestBody, partBS, PartM)
import Network.HTTP.Req ((/:))
import qualified Network.HTTP.Req as R
import Discord.Internal.Rest.Prelude
import Discord.Internal.Types
instance Request (ChannelRequest a) where
majorRoute :: ChannelRequest a -> String
majorRoute = ChannelRequest a -> String
forall a. ChannelRequest a -> String
channelMajorRoute
jsonRequest :: ChannelRequest a -> JsonRequest
jsonRequest = ChannelRequest a -> JsonRequest
forall a. ChannelRequest a -> JsonRequest
channelJsonRequest
data ChannelRequest a where
GetChannel :: ChannelId -> ChannelRequest Channel
ModifyChannel :: ChannelId -> ModifyChannelOpts -> ChannelRequest Channel
DeleteChannel :: ChannelId -> ChannelRequest Channel
GetChannelMessages :: ChannelId -> (Int, MessageTiming) -> ChannelRequest [Message]
GetChannelMessage :: (ChannelId, MessageId) -> ChannelRequest Message
CreateMessage :: ChannelId -> T.Text -> ChannelRequest Message
CreateMessageEmbed :: ChannelId -> T.Text -> CreateEmbed -> ChannelRequest Message
CreateMessageUploadFile :: ChannelId -> T.Text -> B.ByteString -> ChannelRequest Message
CreateMessageDetailed :: ChannelId -> MessageDetailedOpts -> ChannelRequest Message
CreateReaction :: (ChannelId, MessageId) -> T.Text -> ChannelRequest ()
DeleteOwnReaction :: (ChannelId, MessageId) -> T.Text -> ChannelRequest ()
DeleteUserReaction :: (ChannelId, MessageId) -> UserId -> T.Text -> ChannelRequest ()
DeleteSingleReaction :: (ChannelId, MessageId) -> T.Text -> ChannelRequest ()
GetReactions :: (ChannelId, MessageId) -> T.Text -> (Int, ReactionTiming) -> ChannelRequest [User]
DeleteAllReactions :: (ChannelId, MessageId) -> ChannelRequest ()
EditMessage :: (ChannelId, MessageId) -> T.Text -> Maybe CreateEmbed
-> ChannelRequest Message
DeleteMessage :: (ChannelId, MessageId) -> ChannelRequest ()
BulkDeleteMessage :: (ChannelId, [MessageId]) -> ChannelRequest ()
EditChannelPermissions :: ChannelId -> OverwriteId -> ChannelPermissionsOpts -> ChannelRequest ()
GetChannelInvites :: ChannelId -> ChannelRequest Object
CreateChannelInvite :: ChannelId -> ChannelInviteOpts -> ChannelRequest Invite
DeleteChannelPermission :: ChannelId -> OverwriteId -> ChannelRequest ()
TriggerTypingIndicator :: ChannelId -> ChannelRequest ()
GetPinnedMessages :: ChannelId -> ChannelRequest [Message]
AddPinnedMessage :: (ChannelId, MessageId) -> ChannelRequest ()
DeletePinnedMessage :: (ChannelId, MessageId) -> ChannelRequest ()
GroupDMAddRecipient :: ChannelId -> GroupDMAddRecipientOpts -> ChannelRequest ()
GroupDMRemoveRecipient :: ChannelId -> UserId -> ChannelRequest ()
data MessageDetailedOpts = MessageDetailedOpts
{ MessageDetailedOpts -> Text
messageDetailedContent :: T.Text
, MessageDetailedOpts -> Bool
messageDetailedTTS :: Bool
, MessageDetailedOpts -> Maybe CreateEmbed
messageDetailedEmbed :: Maybe CreateEmbed
, MessageDetailedOpts -> Maybe (Text, ByteString)
messageDetailedFile :: Maybe (T.Text, B.ByteString)
, MessageDetailedOpts -> Maybe AllowedMentions
messageDetailedAllowedMentions :: Maybe AllowedMentions
, MessageDetailedOpts -> Maybe MessageReference
messageDetailedReference :: Maybe MessageReference
}
instance Default MessageDetailedOpts where
def :: MessageDetailedOpts
def = MessageDetailedOpts :: Text
-> Bool
-> Maybe CreateEmbed
-> Maybe (Text, ByteString)
-> Maybe AllowedMentions
-> Maybe MessageReference
-> MessageDetailedOpts
MessageDetailedOpts { messageDetailedContent :: Text
messageDetailedContent = Text
""
, messageDetailedTTS :: Bool
messageDetailedTTS = Bool
False
, messageDetailedEmbed :: Maybe CreateEmbed
messageDetailedEmbed = Maybe CreateEmbed
forall a. Maybe a
Nothing
, messageDetailedFile :: Maybe (Text, ByteString)
messageDetailedFile = Maybe (Text, ByteString)
forall a. Maybe a
Nothing
, messageDetailedAllowedMentions :: Maybe AllowedMentions
messageDetailedAllowedMentions = Maybe AllowedMentions
forall a. Maybe a
Nothing
, messageDetailedReference :: Maybe MessageReference
messageDetailedReference = Maybe MessageReference
forall a. Maybe a
Nothing
}
data AllowedMentions = AllowedMentions
{ AllowedMentions -> Bool
mentionEveryone :: Bool
, AllowedMentions -> Bool
mentionUsers :: Bool
, AllowedMentions -> Bool
mentionRoles :: Bool
, AllowedMentions -> [UserId]
mentionUserIds :: [UserId]
, AllowedMentions -> [UserId]
mentionRoleIds :: [RoleId]
, AllowedMentions -> Bool
mentionRepliedUser :: Bool
}
instance Default AllowedMentions where
def :: AllowedMentions
def = AllowedMentions :: Bool
-> Bool -> Bool -> [UserId] -> [UserId] -> Bool -> AllowedMentions
AllowedMentions { mentionEveryone :: Bool
mentionEveryone = Bool
False
, mentionUsers :: Bool
mentionUsers = Bool
True
, mentionRoles :: Bool
mentionRoles = Bool
True
, mentionUserIds :: [UserId]
mentionUserIds = []
, mentionRoleIds :: [UserId]
mentionRoleIds = []
, mentionRepliedUser :: Bool
mentionRepliedUser = Bool
True
}
instance ToJSON AllowedMentions where
toJSON :: AllowedMentions -> Value
toJSON AllowedMentions{Bool
[UserId]
mentionRepliedUser :: Bool
mentionRoleIds :: [UserId]
mentionUserIds :: [UserId]
mentionRoles :: Bool
mentionUsers :: Bool
mentionEveryone :: Bool
mentionRepliedUser :: AllowedMentions -> Bool
mentionRoleIds :: AllowedMentions -> [UserId]
mentionUserIds :: AllowedMentions -> [UserId]
mentionRoles :: AllowedMentions -> Bool
mentionUsers :: AllowedMentions -> Bool
mentionEveryone :: AllowedMentions -> Bool
..} = [Pair] -> Value
object [
(Text
"parse" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= [Text
name :: T.Text | (Text
name, Bool
True) <-
[ (Text
"everyone", Bool
mentionEveryone),
(Text
"users", Bool
mentionUsers),
(Text
"roles", Bool
mentionRoles) ] ]),
(Text
"roles" Text -> [UserId] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= [UserId]
mentionRoleIds),
(Text
"users" Text -> [UserId] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= [UserId]
mentionUserIds),
(Text
"replied_user" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= Bool
mentionRepliedUser) ]
data ReactionTiming = BeforeReaction MessageId
| AfterReaction MessageId
| LatestReaction
reactionTimingToQuery :: ReactionTiming -> R.Option 'R.Https
reactionTimingToQuery :: ReactionTiming -> Option 'Https
reactionTimingToQuery ReactionTiming
t = case ReactionTiming
t of
(BeforeReaction UserId
snow) -> Text
"before" Text -> String -> Option 'Https
forall param a.
(QueryParam param, ToHttpApiData a) =>
Text -> a -> param
R.=: UserId -> String
forall a. Show a => a -> String
show UserId
snow
(AfterReaction UserId
snow) -> Text
"after" Text -> String -> Option 'Https
forall param a.
(QueryParam param, ToHttpApiData a) =>
Text -> a -> param
R.=: UserId -> String
forall a. Show a => a -> String
show UserId
snow
(ReactionTiming
LatestReaction) -> Option 'Https
forall a. Monoid a => a
mempty
data MessageTiming = AroundMessage MessageId
| BeforeMessage MessageId
| AfterMessage MessageId
| LatestMessages
messageTimingToQuery :: MessageTiming -> R.Option 'R.Https
messageTimingToQuery :: MessageTiming -> Option 'Https
messageTimingToQuery MessageTiming
t = case MessageTiming
t of
(AroundMessage UserId
snow) -> Text
"around" Text -> String -> Option 'Https
forall param a.
(QueryParam param, ToHttpApiData a) =>
Text -> a -> param
R.=: UserId -> String
forall a. Show a => a -> String
show UserId
snow
(BeforeMessage UserId
snow) -> Text
"before" Text -> String -> Option 'Https
forall param a.
(QueryParam param, ToHttpApiData a) =>
Text -> a -> param
R.=: UserId -> String
forall a. Show a => a -> String
show UserId
snow
(AfterMessage UserId
snow) -> Text
"after" Text -> String -> Option 'Https
forall param a.
(QueryParam param, ToHttpApiData a) =>
Text -> a -> param
R.=: UserId -> String
forall a. Show a => a -> String
show UserId
snow
(MessageTiming
LatestMessages) -> Option 'Https
forall a. Monoid a => a
mempty
data ChannelInviteOpts = ChannelInviteOpts
{ ChannelInviteOpts -> Maybe Integer
channelInviteOptsMaxAgeSeconds :: Maybe Integer
, ChannelInviteOpts -> Maybe Integer
channelInviteOptsMaxUsages :: Maybe Integer
, ChannelInviteOpts -> Maybe Bool
channelInviteOptsIsTemporary :: Maybe Bool
, ChannelInviteOpts -> Maybe Bool
channelInviteOptsDontReuseSimilarInvite :: Maybe Bool
}
instance ToJSON ChannelInviteOpts where
toJSON :: ChannelInviteOpts -> Value
toJSON ChannelInviteOpts{Maybe Bool
Maybe Integer
channelInviteOptsDontReuseSimilarInvite :: Maybe Bool
channelInviteOptsIsTemporary :: Maybe Bool
channelInviteOptsMaxUsages :: Maybe Integer
channelInviteOptsMaxAgeSeconds :: Maybe Integer
channelInviteOptsDontReuseSimilarInvite :: ChannelInviteOpts -> Maybe Bool
channelInviteOptsIsTemporary :: ChannelInviteOpts -> Maybe Bool
channelInviteOptsMaxUsages :: ChannelInviteOpts -> Maybe Integer
channelInviteOptsMaxAgeSeconds :: ChannelInviteOpts -> Maybe Integer
..} = [Pair] -> Value
object [(Text
name, Value
val) | (Text
name, Just Value
val) <-
[(Text
"max_age", Integer -> Value
forall a. ToJSON a => a -> Value
toJSON (Integer -> Value) -> Maybe Integer -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Integer
channelInviteOptsMaxAgeSeconds),
(Text
"max_uses", Integer -> Value
forall a. ToJSON a => a -> Value
toJSON (Integer -> Value) -> Maybe Integer -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Integer
channelInviteOptsMaxUsages),
(Text
"temporary", Bool -> Value
forall a. ToJSON a => a -> Value
toJSON (Bool -> Value) -> Maybe Bool -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Bool
channelInviteOptsIsTemporary),
(Text
"unique", Bool -> Value
forall a. ToJSON a => a -> Value
toJSON (Bool -> Value) -> Maybe Bool -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Bool
channelInviteOptsDontReuseSimilarInvite) ] ]
data ModifyChannelOpts = ModifyChannelOpts
{ ModifyChannelOpts -> Maybe Text
modifyChannelName :: Maybe T.Text
, ModifyChannelOpts -> Maybe Integer
modifyChannelPosition :: Maybe Integer
, ModifyChannelOpts -> Maybe Text
modifyChannelTopic :: Maybe T.Text
, ModifyChannelOpts -> Maybe Bool
modifyChannelNSFW :: Maybe Bool
, ModifyChannelOpts -> Maybe Integer
modifyChannelBitrate :: Maybe Integer
, ModifyChannelOpts -> Maybe Integer
modifyChannelUserRateLimit :: Maybe Integer
, ModifyChannelOpts -> Maybe [Overwrite]
modifyChannelPermissionOverwrites :: Maybe [Overwrite]
, ModifyChannelOpts -> Maybe UserId
modifyChannelParentId :: Maybe ChannelId
}
instance ToJSON ModifyChannelOpts where
toJSON :: ModifyChannelOpts -> Value
toJSON ModifyChannelOpts{Maybe Bool
Maybe Integer
Maybe [Overwrite]
Maybe Text
Maybe UserId
modifyChannelParentId :: Maybe UserId
modifyChannelPermissionOverwrites :: Maybe [Overwrite]
modifyChannelUserRateLimit :: Maybe Integer
modifyChannelBitrate :: Maybe Integer
modifyChannelNSFW :: Maybe Bool
modifyChannelTopic :: Maybe Text
modifyChannelPosition :: Maybe Integer
modifyChannelName :: Maybe Text
modifyChannelParentId :: ModifyChannelOpts -> Maybe UserId
modifyChannelPermissionOverwrites :: ModifyChannelOpts -> Maybe [Overwrite]
modifyChannelUserRateLimit :: ModifyChannelOpts -> Maybe Integer
modifyChannelBitrate :: ModifyChannelOpts -> Maybe Integer
modifyChannelNSFW :: ModifyChannelOpts -> Maybe Bool
modifyChannelTopic :: ModifyChannelOpts -> Maybe Text
modifyChannelPosition :: ModifyChannelOpts -> Maybe Integer
modifyChannelName :: ModifyChannelOpts -> Maybe Text
..} = [Pair] -> Value
object [(Text
name, Value
val) | (Text
name, Just Value
val) <-
[(Text
"name", Text -> Value
forall a. ToJSON a => a -> Value
toJSON (Text -> Value) -> Maybe Text -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Text
modifyChannelName),
(Text
"position", Integer -> Value
forall a. ToJSON a => a -> Value
toJSON (Integer -> Value) -> Maybe Integer -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Integer
modifyChannelPosition),
(Text
"topic", Text -> Value
forall a. ToJSON a => a -> Value
toJSON (Text -> Value) -> Maybe Text -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Text
modifyChannelTopic),
(Text
"nsfw", Bool -> Value
forall a. ToJSON a => a -> Value
toJSON (Bool -> Value) -> Maybe Bool -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Bool
modifyChannelNSFW),
(Text
"bitrate", Integer -> Value
forall a. ToJSON a => a -> Value
toJSON (Integer -> Value) -> Maybe Integer -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Integer
modifyChannelBitrate),
(Text
"user_limit", Integer -> Value
forall a. ToJSON a => a -> Value
toJSON (Integer -> Value) -> Maybe Integer -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Integer
modifyChannelUserRateLimit),
(Text
"permission_overwrites", [Overwrite] -> Value
forall a. ToJSON a => a -> Value
toJSON ([Overwrite] -> Value) -> Maybe [Overwrite] -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe [Overwrite]
modifyChannelPermissionOverwrites),
(Text
"parent_id", UserId -> Value
forall a. ToJSON a => a -> Value
toJSON (UserId -> Value) -> Maybe UserId -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe UserId
modifyChannelParentId) ] ]
data ChannelPermissionsOpts = ChannelPermissionsOpts
{ ChannelPermissionsOpts -> Integer
channelPermissionsOptsAllow :: Integer
, ChannelPermissionsOpts -> Integer
channelPermissionsOptsDeny :: Integer
, ChannelPermissionsOpts -> ChannelPermissionsOptsType
channelPermissionsOptsType :: ChannelPermissionsOptsType}
data ChannelPermissionsOptsType = ChannelPermissionsOptsUser
| ChannelPermissionsOptsRole
instance ToJSON ChannelPermissionsOptsType where
toJSON :: ChannelPermissionsOptsType -> Value
toJSON ChannelPermissionsOptsType
t = case ChannelPermissionsOptsType
t of ChannelPermissionsOptsType
ChannelPermissionsOptsUser -> Text -> Value
String Text
"member"
ChannelPermissionsOptsType
ChannelPermissionsOptsRole -> Text -> Value
String Text
"role"
instance ToJSON ChannelPermissionsOpts where
toJSON :: ChannelPermissionsOpts -> Value
toJSON (ChannelPermissionsOpts Integer
a Integer
d ChannelPermissionsOptsType
t) = [Pair] -> Value
object [ (Text
"allow", Integer -> Value
forall a. ToJSON a => a -> Value
toJSON Integer
a )
, (Text
"deny", Integer -> Value
forall a. ToJSON a => a -> Value
toJSON Integer
d)
, (Text
"type", ChannelPermissionsOptsType -> Value
forall a. ToJSON a => a -> Value
toJSON ChannelPermissionsOptsType
t)]
data GroupDMAddRecipientOpts = GroupDMAddRecipientOpts
{ GroupDMAddRecipientOpts -> UserId
groupDMAddRecipientUserToAdd :: UserId
, GroupDMAddRecipientOpts -> Text
groupDMAddRecipientUserToAddNickName :: T.Text
, GroupDMAddRecipientOpts -> Text
groupDMAddRecipientGDMJoinAccessToken :: T.Text
}
channelMajorRoute :: ChannelRequest a -> String
channelMajorRoute :: ChannelRequest a -> String
channelMajorRoute ChannelRequest a
c = case ChannelRequest a
c of
(GetChannel UserId
chan) -> String
"get_chan " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(ModifyChannel UserId
chan ModifyChannelOpts
_) -> String
"mod_chan " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(DeleteChannel UserId
chan) -> String
"mod_chan " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(GetChannelMessages UserId
chan (Int, MessageTiming)
_) -> String
"msg " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(GetChannelMessage (UserId
chan, UserId
_)) -> String
"get_msg " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(CreateMessage UserId
chan Text
_) -> String
"msg " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(CreateMessageEmbed UserId
chan Text
_ CreateEmbed
_) -> String
"msg " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(CreateMessageUploadFile UserId
chan Text
_ ByteString
_) -> String
"msg " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(CreateMessageDetailed UserId
chan MessageDetailedOpts
_) -> String
"msg " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(CreateReaction (UserId
chan, UserId
_) Text
_) -> String
"add_react " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(DeleteOwnReaction (UserId
chan, UserId
_) Text
_) -> String
"react " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(DeleteUserReaction (UserId
chan, UserId
_) UserId
_ Text
_) -> String
"react " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(DeleteSingleReaction (UserId
chan, UserId
_) Text
_) -> String
"react " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(GetReactions (UserId
chan, UserId
_) Text
_ (Int, ReactionTiming)
_) -> String
"react " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(DeleteAllReactions (UserId
chan, UserId
_)) -> String
"react " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(EditMessage (UserId
chan, UserId
_) Text
_ Maybe CreateEmbed
_) -> String
"get_msg " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(DeleteMessage (UserId
chan, UserId
_)) -> String
"get_msg " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(BulkDeleteMessage (UserId
chan, [UserId]
_)) -> String
"del_msgs " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(EditChannelPermissions UserId
chan UserId
_ ChannelPermissionsOpts
_) -> String
"perms " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(GetChannelInvites UserId
chan) -> String
"invites " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(CreateChannelInvite UserId
chan ChannelInviteOpts
_) -> String
"invites " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(DeleteChannelPermission UserId
chan UserId
_) -> String
"perms " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(TriggerTypingIndicator UserId
chan) -> String
"tti " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(GetPinnedMessages UserId
chan) -> String
"pins " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(AddPinnedMessage (UserId
chan, UserId
_)) -> String
"pin " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(DeletePinnedMessage (UserId
chan, UserId
_)) -> String
"pin " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(GroupDMAddRecipient UserId
chan GroupDMAddRecipientOpts
_) -> String
"groupdm " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
(GroupDMRemoveRecipient UserId
chan UserId
_) -> String
"groupdm " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserId -> String
forall a. Show a => a -> String
show UserId
chan
cleanupEmoji :: T.Text -> T.Text
cleanupEmoji :: Text -> Text
cleanupEmoji Text
emoji =
let noAngles :: Text
noAngles = Text -> Text -> Text -> Text
T.replace Text
"<" Text
"" (Text -> Text -> Text -> Text
T.replace Text
">" Text
"" Text
emoji)
byName :: Maybe Text
byName = String -> Text
T.pack (String -> Text) -> Maybe String -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Maybe String
unicodeByName (Text -> String
T.unpack (Text -> Text -> Text -> Text
T.replace Text
":" Text
"" Text
emoji))
in case (Maybe Text
byName, Text -> Text -> Maybe Text
T.stripPrefix Text
":" Text
noAngles) of
(Just Text
e, Maybe Text
_) -> Text
e
(Maybe Text
_, Just Text
a) -> Text
"custom:" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
a
(Maybe Text
_, Maybe Text
Nothing) -> Text
noAngles
maybeEmbed :: Maybe CreateEmbed -> [PartM IO]
maybeEmbed :: Maybe CreateEmbed -> [PartM IO]
maybeEmbed =
let mkPart :: (Text, ByteString) -> PartM m
mkPart (Text
name,ByteString
content) = Text -> String -> RequestBody -> PartM m
forall (m :: * -> *).
Applicative m =>
Text -> String -> RequestBody -> PartM m
partFileRequestBody Text
name (Text -> String
T.unpack Text
name) (ByteString -> RequestBody
RequestBodyBS ByteString
content)
uploads :: CreateEmbed -> [(a, ByteString)]
uploads CreateEmbed{[EmbedField]
Maybe CreateEmbedImage
Text
createEmbedFooterIcon :: CreateEmbed -> Maybe CreateEmbedImage
createEmbedFooterText :: CreateEmbed -> Text
createEmbedImage :: CreateEmbed -> Maybe CreateEmbedImage
createEmbedFields :: CreateEmbed -> [EmbedField]
createEmbedDescription :: CreateEmbed -> Text
createEmbedThumbnail :: CreateEmbed -> Maybe CreateEmbedImage
createEmbedUrl :: CreateEmbed -> Text
createEmbedTitle :: CreateEmbed -> Text
createEmbedAuthorIcon :: CreateEmbed -> Maybe CreateEmbedImage
createEmbedAuthorUrl :: CreateEmbed -> Text
createEmbedAuthorName :: CreateEmbed -> Text
createEmbedFooterIcon :: Maybe CreateEmbedImage
createEmbedFooterText :: Text
createEmbedImage :: Maybe CreateEmbedImage
createEmbedFields :: [EmbedField]
createEmbedDescription :: Text
createEmbedThumbnail :: Maybe CreateEmbedImage
createEmbedUrl :: Text
createEmbedTitle :: Text
createEmbedAuthorIcon :: Maybe CreateEmbedImage
createEmbedAuthorUrl :: Text
createEmbedAuthorName :: Text
..} = [(a
n,ByteString
c) | (a
n, Just (CreateEmbedImageUpload ByteString
c)) <-
[ (a
"author.png", Maybe CreateEmbedImage
createEmbedAuthorIcon)
, (a
"thumbnail.png", Maybe CreateEmbedImage
createEmbedThumbnail)
, (a
"image.png", Maybe CreateEmbedImage
createEmbedImage)
, (a
"footer.png", Maybe CreateEmbedImage
createEmbedFooterIcon) ]]
in [PartM IO]
-> (CreateEmbed -> [PartM IO]) -> Maybe CreateEmbed -> [PartM IO]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (((Text, ByteString) -> PartM IO)
-> [(Text, ByteString)] -> [PartM IO]
forall a b. (a -> b) -> [a] -> [b]
map (Text, ByteString) -> PartM IO
forall (m :: * -> *).
Applicative m =>
(Text, ByteString) -> PartM m
mkPart ([(Text, ByteString)] -> [PartM IO])
-> (CreateEmbed -> [(Text, ByteString)])
-> CreateEmbed
-> [PartM IO]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CreateEmbed -> [(Text, ByteString)]
forall a. IsString a => CreateEmbed -> [(a, ByteString)]
uploads)
channels :: R.Url 'R.Https
channels :: Url 'Https
channels = Url 'Https
baseUrl Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"channels"
channelJsonRequest :: ChannelRequest r -> JsonRequest
channelJsonRequest :: ChannelRequest r -> JsonRequest
channelJsonRequest ChannelRequest r
c = case ChannelRequest r
c of
(GetChannel UserId
chan) ->
Url 'Https -> Option 'Https -> JsonRequest
Get (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan) Option 'Https
forall a. Monoid a => a
mempty
(ModifyChannel UserId
chan ModifyChannelOpts
patch) ->
Url 'Https
-> RestIO (ReqBodyJson ModifyChannelOpts)
-> Option 'Https
-> JsonRequest
forall a.
HttpBody a =>
Url 'Https -> RestIO a -> Option 'Https -> JsonRequest
Patch (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan) (ReqBodyJson ModifyChannelOpts
-> RestIO (ReqBodyJson ModifyChannelOpts)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ModifyChannelOpts -> ReqBodyJson ModifyChannelOpts
forall a. a -> ReqBodyJson a
R.ReqBodyJson ModifyChannelOpts
patch)) Option 'Https
forall a. Monoid a => a
mempty
(DeleteChannel UserId
chan) ->
Url 'Https -> Option 'Https -> JsonRequest
Delete (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan) Option 'Https
forall a. Monoid a => a
mempty
(GetChannelMessages UserId
chan (Int
n,MessageTiming
timing)) ->
let n' :: Int
n' = if Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
1 then Int
1 else (if Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
100 then Int
100 else Int
n)
options :: Option 'Https
options = Text
"limit" Text -> Int -> Option 'Https
forall param a.
(QueryParam param, ToHttpApiData a) =>
Text -> a -> param
R.=: Int
n' Option 'Https -> Option 'Https -> Option 'Https
forall a. Semigroup a => a -> a -> a
<> MessageTiming -> Option 'Https
messageTimingToQuery MessageTiming
timing
in Url 'Https -> Option 'Https -> JsonRequest
Get (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"messages") Option 'Https
options
(GetChannelMessage (UserId
chan, UserId
msg)) ->
Url 'Https -> Option 'Https -> JsonRequest
Get (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"messages" Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
msg) Option 'Https
forall a. Monoid a => a
mempty
(CreateMessage UserId
chan Text
msg) ->
let content :: [Pair]
content = [Text
"content" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= Text
msg]
body :: RestIO (ReqBodyJson Value)
body = ReqBodyJson Value -> RestIO (ReqBodyJson Value)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ReqBodyJson Value -> RestIO (ReqBodyJson Value))
-> ReqBodyJson Value -> RestIO (ReqBodyJson Value)
forall a b. (a -> b) -> a -> b
$ Value -> ReqBodyJson Value
forall a. a -> ReqBodyJson a
R.ReqBodyJson (Value -> ReqBodyJson Value) -> Value -> ReqBodyJson Value
forall a b. (a -> b) -> a -> b
$ [Pair] -> Value
object [Pair]
content
in Url 'Https
-> RestIO (ReqBodyJson Value) -> Option 'Https -> JsonRequest
forall a.
HttpBody a =>
Url 'Https -> RestIO a -> Option 'Https -> JsonRequest
Post (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"messages") RestIO (ReqBodyJson Value)
body Option 'Https
forall a. Monoid a => a
mempty
(CreateMessageEmbed UserId
chan Text
msg CreateEmbed
embed) ->
let partJson :: PartM IO
partJson = Text -> ByteString -> PartM IO
forall (m :: * -> *).
Applicative m =>
Text -> ByteString -> PartM m
partBS Text
"payload_json" (ByteString -> PartM IO) -> ByteString -> PartM IO
forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString
BL.toStrict (ByteString -> ByteString) -> ByteString -> ByteString
forall a b. (a -> b) -> a -> b
$ Value -> ByteString
forall a. ToJSON a => a -> ByteString
encode (Value -> ByteString) -> Value -> ByteString
forall a b. (a -> b) -> a -> b
$ Value -> Value
forall a. ToJSON a => a -> Value
toJSON (Value -> Value) -> Value -> Value
forall a b. (a -> b) -> a -> b
$ [Pair] -> Value
object [Text
"content" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= Text
msg, Text
"embed" Text -> Embed -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= CreateEmbed -> Embed
createEmbed CreateEmbed
embed]
body :: RestIO ReqBodyMultipart
body = [PartM IO] -> RestIO ReqBodyMultipart
forall (m :: * -> *). MonadIO m => [PartM IO] -> m ReqBodyMultipart
R.reqBodyMultipart (PartM IO
partJson PartM IO -> [PartM IO] -> [PartM IO]
forall a. a -> [a] -> [a]
: Maybe CreateEmbed -> [PartM IO]
maybeEmbed (CreateEmbed -> Maybe CreateEmbed
forall a. a -> Maybe a
Just CreateEmbed
embed))
in Url 'Https
-> RestIO ReqBodyMultipart -> Option 'Https -> JsonRequest
forall a.
HttpBody a =>
Url 'Https -> RestIO a -> Option 'Https -> JsonRequest
Post (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"messages") RestIO ReqBodyMultipart
body Option 'Https
forall a. Monoid a => a
mempty
(CreateMessageUploadFile UserId
chan Text
fileName ByteString
file) ->
let part :: PartM IO
part = Text -> String -> RequestBody -> PartM IO
forall (m :: * -> *).
Applicative m =>
Text -> String -> RequestBody -> PartM m
partFileRequestBody Text
"file" (Text -> String
T.unpack Text
fileName) (RequestBody -> PartM IO) -> RequestBody -> PartM IO
forall a b. (a -> b) -> a -> b
$ ByteString -> RequestBody
RequestBodyBS ByteString
file
body :: RestIO ReqBodyMultipart
body = [PartM IO] -> RestIO ReqBodyMultipart
forall (m :: * -> *). MonadIO m => [PartM IO] -> m ReqBodyMultipart
R.reqBodyMultipart [PartM IO
part]
in Url 'Https
-> RestIO ReqBodyMultipart -> Option 'Https -> JsonRequest
forall a.
HttpBody a =>
Url 'Https -> RestIO a -> Option 'Https -> JsonRequest
Post (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"messages") RestIO ReqBodyMultipart
body Option 'Https
forall a. Monoid a => a
mempty
(CreateMessageDetailed UserId
chan MessageDetailedOpts
msgOpts) ->
let fileUpload :: Maybe (Text, ByteString)
fileUpload = MessageDetailedOpts -> Maybe (Text, ByteString)
messageDetailedFile MessageDetailedOpts
msgOpts
filePart :: [PartM IO]
filePart = case Maybe (Text, ByteString)
fileUpload of
Maybe (Text, ByteString)
Nothing -> []
Just (Text, ByteString)
f -> [Text -> String -> RequestBody -> PartM IO
forall (m :: * -> *).
Applicative m =>
Text -> String -> RequestBody -> PartM m
partFileRequestBody Text
"file" (Text -> String
T.unpack (Text -> String) -> Text -> String
forall a b. (a -> b) -> a -> b
$ (Text, ByteString) -> Text
forall a b. (a, b) -> a
fst (Text, ByteString)
f)
(RequestBody -> PartM IO) -> RequestBody -> PartM IO
forall a b. (a -> b) -> a -> b
$ ByteString -> RequestBody
RequestBodyBS (ByteString -> RequestBody) -> ByteString -> RequestBody
forall a b. (a -> b) -> a -> b
$ (Text, ByteString) -> ByteString
forall a b. (a, b) -> b
snd (Text, ByteString)
f]
payloadData :: Value
payloadData = [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$ [ Text
"content" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= MessageDetailedOpts -> Text
messageDetailedContent MessageDetailedOpts
msgOpts
, Text
"tts" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= MessageDetailedOpts -> Bool
messageDetailedTTS MessageDetailedOpts
msgOpts ] [Pair] -> [Pair] -> [Pair]
forall a. [a] -> [a] -> [a]
++
[ Text
name Text -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= Value
value | (Text
name, Just Value
value) <-
[ (Text
"embed", Embed -> Value
forall a. ToJSON a => a -> Value
toJSON (Embed -> Value) -> (CreateEmbed -> Embed) -> CreateEmbed -> Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CreateEmbed -> Embed
createEmbed (CreateEmbed -> Value) -> Maybe CreateEmbed -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MessageDetailedOpts -> Maybe CreateEmbed
messageDetailedEmbed MessageDetailedOpts
msgOpts)
, (Text
"allowed_mentions", AllowedMentions -> Value
forall a. ToJSON a => a -> Value
toJSON (AllowedMentions -> Value) -> Maybe AllowedMentions -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MessageDetailedOpts -> Maybe AllowedMentions
messageDetailedAllowedMentions MessageDetailedOpts
msgOpts)
, (Text
"message_reference", MessageReference -> Value
forall a. ToJSON a => a -> Value
toJSON (MessageReference -> Value)
-> Maybe MessageReference -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MessageDetailedOpts -> Maybe MessageReference
messageDetailedReference MessageDetailedOpts
msgOpts)
] ]
payloadPart :: PartM IO
payloadPart = Text -> ByteString -> PartM IO
forall (m :: * -> *).
Applicative m =>
Text -> ByteString -> PartM m
partBS Text
"payload_json" (ByteString -> PartM IO) -> ByteString -> PartM IO
forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString
BL.toStrict (ByteString -> ByteString) -> ByteString -> ByteString
forall a b. (a -> b) -> a -> b
$ Value -> ByteString
forall a. ToJSON a => a -> ByteString
encode (Value -> ByteString) -> Value -> ByteString
forall a b. (a -> b) -> a -> b
$ Value -> Value
forall a. ToJSON a => a -> Value
toJSON Value
payloadData
body :: RestIO ReqBodyMultipart
body = [PartM IO] -> RestIO ReqBodyMultipart
forall (m :: * -> *). MonadIO m => [PartM IO] -> m ReqBodyMultipart
R.reqBodyMultipart (PartM IO
payloadPart PartM IO -> [PartM IO] -> [PartM IO]
forall a. a -> [a] -> [a]
: [PartM IO]
filePart)
in Url 'Https
-> RestIO ReqBodyMultipart -> Option 'Https -> JsonRequest
forall a.
HttpBody a =>
Url 'Https -> RestIO a -> Option 'Https -> JsonRequest
Post (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"messages") RestIO ReqBodyMultipart
body Option 'Https
forall a. Monoid a => a
mempty
(CreateReaction (UserId
chan, UserId
msgid) Text
emoji) ->
let e :: Text
e = Text -> Text
cleanupEmoji Text
emoji
in Url 'Https -> NoReqBody -> Option 'Https -> JsonRequest
forall a.
HttpBody a =>
Url 'Https -> a -> Option 'Https -> JsonRequest
Put (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"messages" Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
msgid Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"reactions" Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
e Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"@me" )
NoReqBody
R.NoReqBody Option 'Https
forall a. Monoid a => a
mempty
(DeleteOwnReaction (UserId
chan, UserId
msgid) Text
emoji) ->
let e :: Text
e = Text -> Text
cleanupEmoji Text
emoji
in Url 'Https -> Option 'Https -> JsonRequest
Delete (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"messages" Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
msgid Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"reactions" Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
e Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"@me" ) Option 'Https
forall a. Monoid a => a
mempty
(DeleteUserReaction (UserId
chan, UserId
msgid) UserId
uID Text
emoji) ->
let e :: Text
e = Text -> Text
cleanupEmoji Text
emoji
in Url 'Https -> Option 'Https -> JsonRequest
Delete (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"messages" Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
msgid Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"reactions" Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
e Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
uID ) Option 'Https
forall a. Monoid a => a
mempty
(DeleteSingleReaction (UserId
chan, UserId
msgid) Text
emoji) ->
let e :: Text
e = Text -> Text
cleanupEmoji Text
emoji
in Url 'Https -> Option 'Https -> JsonRequest
Delete (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"messages" Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
msgid Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"reactions" Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
e) Option 'Https
forall a. Monoid a => a
mempty
(GetReactions (UserId
chan, UserId
msgid) Text
emoji (Int
n, ReactionTiming
timing)) ->
let e :: Text
e = Text -> Text
cleanupEmoji Text
emoji
n' :: Int
n' = if Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
1 then Int
1 else (if Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
100 then Int
100 else Int
n)
options :: Option 'Https
options = Text
"limit" Text -> Int -> Option 'Https
forall param a.
(QueryParam param, ToHttpApiData a) =>
Text -> a -> param
R.=: Int
n' Option 'Https -> Option 'Https -> Option 'Https
forall a. Semigroup a => a -> a -> a
<> ReactionTiming -> Option 'Https
reactionTimingToQuery ReactionTiming
timing
in Url 'Https -> Option 'Https -> JsonRequest
Get (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"messages" Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
msgid Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"reactions" Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
e) Option 'Https
options
(DeleteAllReactions (UserId
chan, UserId
msgid)) ->
Url 'Https -> Option 'Https -> JsonRequest
Delete (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"messages" Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
msgid Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"reactions" ) Option 'Https
forall a. Monoid a => a
mempty
(EditMessage (UserId
chan, UserId
msg) Text
new Maybe CreateEmbed
embed) ->
let partJson :: Value
partJson = Value -> Value
forall a. ToJSON a => a -> Value
toJSON (Value -> Value) -> Value -> Value
forall a b. (a -> b) -> a -> b
$ [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$ [Text
"content" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= Text
new] [Pair] -> [Pair] -> [Pair]
forall a. [a] -> [a] -> [a]
++ case Maybe CreateEmbed
embed of
Just CreateEmbed
e -> [Text
"embed" Text -> Embed -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= CreateEmbed -> Embed
createEmbed CreateEmbed
e]
Maybe CreateEmbed
Nothing -> []
body :: RestIO (ReqBodyJson Value)
body = ReqBodyJson Value -> RestIO (ReqBodyJson Value)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Value -> ReqBodyJson Value
forall a. a -> ReqBodyJson a
R.ReqBodyJson Value
partJson)
in Url 'Https
-> RestIO (ReqBodyJson Value) -> Option 'Https -> JsonRequest
forall a.
HttpBody a =>
Url 'Https -> RestIO a -> Option 'Https -> JsonRequest
Patch (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"messages" Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
msg) RestIO (ReqBodyJson Value)
body Option 'Https
forall a. Monoid a => a
mempty
(DeleteMessage (UserId
chan, UserId
msg)) ->
Url 'Https -> Option 'Https -> JsonRequest
Delete (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"messages" Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
msg) Option 'Https
forall a. Monoid a => a
mempty
(BulkDeleteMessage (UserId
chan, [UserId]
msgs)) ->
let body :: RestIO (ReqBodyJson Value)
body = ReqBodyJson Value -> RestIO (ReqBodyJson Value)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ReqBodyJson Value -> RestIO (ReqBodyJson Value))
-> (Value -> ReqBodyJson Value)
-> Value
-> RestIO (ReqBodyJson Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value -> ReqBodyJson Value
forall a. a -> ReqBodyJson a
R.ReqBodyJson (Value -> RestIO (ReqBodyJson Value))
-> Value -> RestIO (ReqBodyJson Value)
forall a b. (a -> b) -> a -> b
$ [Pair] -> Value
object [Text
"messages" Text -> [UserId] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= [UserId]
msgs]
in Url 'Https
-> RestIO (ReqBodyJson Value) -> Option 'Https -> JsonRequest
forall a.
HttpBody a =>
Url 'Https -> RestIO a -> Option 'Https -> JsonRequest
Post (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"messages" Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"bulk-delete") RestIO (ReqBodyJson Value)
body Option 'Https
forall a. Monoid a => a
mempty
(EditChannelPermissions UserId
chan UserId
perm ChannelPermissionsOpts
patch) ->
Url 'Https
-> ReqBodyJson ChannelPermissionsOpts
-> Option 'Https
-> JsonRequest
forall a.
HttpBody a =>
Url 'Https -> a -> Option 'Https -> JsonRequest
Put (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"permissions" Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
perm) (ChannelPermissionsOpts -> ReqBodyJson ChannelPermissionsOpts
forall a. a -> ReqBodyJson a
R.ReqBodyJson ChannelPermissionsOpts
patch) Option 'Https
forall a. Monoid a => a
mempty
(GetChannelInvites UserId
chan) ->
Url 'Https -> Option 'Https -> JsonRequest
Get (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"invites") Option 'Https
forall a. Monoid a => a
mempty
(CreateChannelInvite UserId
chan ChannelInviteOpts
patch) ->
Url 'Https
-> RestIO (ReqBodyJson ChannelInviteOpts)
-> Option 'Https
-> JsonRequest
forall a.
HttpBody a =>
Url 'Https -> RestIO a -> Option 'Https -> JsonRequest
Post (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"invites") (ReqBodyJson ChannelInviteOpts
-> RestIO (ReqBodyJson ChannelInviteOpts)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChannelInviteOpts -> ReqBodyJson ChannelInviteOpts
forall a. a -> ReqBodyJson a
R.ReqBodyJson ChannelInviteOpts
patch)) Option 'Https
forall a. Monoid a => a
mempty
(DeleteChannelPermission UserId
chan UserId
perm) ->
Url 'Https -> Option 'Https -> JsonRequest
Delete (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"permissions" Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
perm) Option 'Https
forall a. Monoid a => a
mempty
(TriggerTypingIndicator UserId
chan) ->
Url 'Https -> RestIO NoReqBody -> Option 'Https -> JsonRequest
forall a.
HttpBody a =>
Url 'Https -> RestIO a -> Option 'Https -> JsonRequest
Post (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"typing") (NoReqBody -> RestIO NoReqBody
forall (f :: * -> *) a. Applicative f => a -> f a
pure NoReqBody
R.NoReqBody) Option 'Https
forall a. Monoid a => a
mempty
(GetPinnedMessages UserId
chan) ->
Url 'Https -> Option 'Https -> JsonRequest
Get (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"pins") Option 'Https
forall a. Monoid a => a
mempty
(AddPinnedMessage (UserId
chan, UserId
msg)) ->
Url 'Https -> NoReqBody -> Option 'Https -> JsonRequest
forall a.
HttpBody a =>
Url 'Https -> a -> Option 'Https -> JsonRequest
Put (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"pins" Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
msg) NoReqBody
R.NoReqBody Option 'Https
forall a. Monoid a => a
mempty
(DeletePinnedMessage (UserId
chan, UserId
msg)) ->
Url 'Https -> Option 'Https -> JsonRequest
Delete (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"pins" Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
msg) Option 'Https
forall a. Monoid a => a
mempty
(GroupDMAddRecipient UserId
chan (GroupDMAddRecipientOpts UserId
uid Text
nick Text
tok)) ->
Url 'Https -> ReqBodyJson Value -> Option 'Https -> JsonRequest
forall a.
HttpBody a =>
Url 'Https -> a -> Option 'Https -> JsonRequest
Put (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"recipients" Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
uid)
(Value -> ReqBodyJson Value
forall a. a -> ReqBodyJson a
R.ReqBodyJson ([Pair] -> Value
object [ (Text
"access_token", Text -> Value
forall a. ToJSON a => a -> Value
toJSON Text
tok)
, (Text
"nick", Text -> Value
forall a. ToJSON a => a -> Value
toJSON Text
nick)]))
Option 'Https
forall a. Monoid a => a
mempty
(GroupDMRemoveRecipient UserId
chan UserId
userid) ->
Url 'Https -> Option 'Https -> JsonRequest
Delete (Url 'Https
channels Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
chan Url 'Https -> Text -> Url 'Https
forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
/: Text
"recipients" Url 'Https -> UserId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// UserId
userid) Option 'Https
forall a. Monoid a => a
mempty