{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE NoDeriveAnyClass #-}
module Calamity.Types.Model.Guild.Permissions (
Permissions (..),
createInstantInvite,
kickMembers,
banMembers,
administrator,
manageChannels,
manageGuild,
addReactions,
viewAuditLog,
prioritySpeaker,
stream,
viewChannel,
sendMessages,
sendTtsMessages,
manageMessages,
embedLinks,
attachFiles,
readMessageHistory,
mentionEveryone,
useExternalEmojis,
viewGuildInsights,
connect,
speak,
muteMembers,
deafenMembers,
moveMembers,
useVad,
changeNickname,
manageNicknames,
manageRoles,
manageWebhooks,
manageEmojis,
) where
import Control.DeepSeq (NFData)
import Data.Aeson (FromJSON (..), ToJSON (..))
import Data.Aeson.Types (parseFail)
import Data.Bits (Bits (shiftL))
import Data.Flags ()
import Data.Flags.TH
import Data.Text.Read (decimal)
import Data.Word
import TextShow
$( bitmaskWrapper
"Permissions"
''Word64
[]
[ ("createInstantInvite", 1 `shiftL` 0)
, ("kickMembers", 1 `shiftL` 1)
, ("banMembers", 1 `shiftL` 2)
, ("administrator", 1 `shiftL` 3)
, ("manageChannels", 1 `shiftL` 4)
, ("manageGuild", 1 `shiftL` 5)
, ("addReactions", 1 `shiftL` 6)
, ("viewAuditLog", 1 `shiftL` 7)
, ("prioritySpeaker", 1 `shiftL` 8)
, ("stream", 1 `shiftL` 9)
, ("viewChannel", 1 `shiftL` 10)
, ("sendMessages", 1 `shiftL` 11)
, ("sendTtsMessages", 1 `shiftL` 12)
, ("manageMessages", 1 `shiftL` 13)
, ("embedLinks", 1 `shiftL` 14)
, ("attachFiles", 1 `shiftL` 15)
, ("readMessageHistory", 1 `shiftL` 16)
, ("mentionEveryone", 1 `shiftL` 17)
, ("useExternalEmojis", 1 `shiftL` 18)
, ("viewGuildInsights", 1 `shiftL` 19)
, ("connect", 1 `shiftL` 20)
, ("speak", 1 `shiftL` 21)
, ("muteMembers", 1 `shiftL` 22)
, ("deafenMembers", 1 `shiftL` 23)
, ("moveMembers", 1 `shiftL` 24)
, ("useVad", 1 `shiftL` 25)
, ("changeNickname", 1 `shiftL` 26)
, ("manageNicknames", 1 `shiftL` 27)
, ("manageRoles", 1 `shiftL` 28)
, ("manageWebhooks", 1 `shiftL` 29)
, ("manageEmojis", 1 `shiftL` 30)
, ("useApplicationCommands", 1 `shiftL` 31)
, ("requestToSPeak", 1 `shiftL` 32)
, ("manageEvents", 1 `shiftL` 33)
, ("manageThreads", 1 `shiftL` 34)
, ("createPublicThreads", 1 `shiftL` 35)
, ("createPrivateThreads", 1 `shiftL` 36)
, ("useExternalStickers", 1 `shiftL` 37)
, ("sendMessagesInThreads", 1 `shiftL` 38)
, ("useEmbeddedActivities", 1 `shiftL` 39)
, ("moderateMembers", 1 `shiftL` 40)
]
)
instance ToJSON Permissions where
toJSON :: Permissions -> Value
toJSON = Text -> Value
forall a. ToJSON a => a -> Value
toJSON (Text -> Value) -> (Permissions -> Text) -> Permissions -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Permissions -> Text
forall a. TextShow a => a -> Text
showt
toEncoding :: Permissions -> Encoding
toEncoding = Text -> Encoding
forall a. ToJSON a => a -> Encoding
toEncoding (Text -> Encoding)
-> (Permissions -> Text) -> Permissions -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Permissions -> Text
forall a. TextShow a => a -> Text
showt
instance FromJSON Permissions where
parseJSON :: Value -> Parser Permissions
parseJSON Value
a = do
Text
asText <- Value -> Parser Text
forall a. FromJSON a => Value -> Parser a
parseJSON Value
a
case Reader Word64
forall a. Integral a => Reader a
decimal Text
asText of
Right (Word64
n, Text
_) -> Permissions -> Parser Permissions
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Permissions -> Parser Permissions)
-> Permissions -> Parser Permissions
forall a b. (a -> b) -> a -> b
$ Word64 -> Permissions
Permissions Word64
n
Left String
e -> String -> Parser Permissions
forall a. String -> Parser a
parseFail String
e
deriving via FromStringShow Permissions instance TextShow Permissions
deriving via Word64 instance NFData Permissions