{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
module Discord.Internal.Types.VoiceCommon where
import Control.Concurrent ( Chan, MVar, ThreadId )
import Control.Concurrent.BoundedChan qualified as Bounded
import Control.Exception.Safe ( Exception, MonadMask, MonadCatch, MonadThrow )
import Lens.Micro.TH ( makeFields )
import Control.Monad.Except
import Control.Monad.Reader
import Data.ByteString qualified as B
import Data.Text qualified as T
import Data.Word ( Word8 )
import GHC.Weak ( Weak )
import Network.Socket
import Network.WebSockets ( ConnectionException, Connection )
import Discord
import Discord.Types
import Discord.Internal.Gateway.EventLoop ( GatewayException(..) )
import Discord.Internal.Types.VoiceUDP
import Discord.Internal.Types.VoiceWebsocket
newtype Voice a = Voice
{ Voice a
-> ReaderT
DiscordBroadcastHandle (ExceptT VoiceError DiscordHandler) a
unVoice :: ReaderT DiscordBroadcastHandle (ExceptT VoiceError DiscordHandler) a
} deriving
( a -> Voice b -> Voice a
(a -> b) -> Voice a -> Voice b
(forall a b. (a -> b) -> Voice a -> Voice b)
-> (forall a b. a -> Voice b -> Voice a) -> Functor Voice
forall a b. a -> Voice b -> Voice a
forall a b. (a -> b) -> Voice a -> Voice b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Voice b -> Voice a
$c<$ :: forall a b. a -> Voice b -> Voice a
fmap :: (a -> b) -> Voice a -> Voice b
$cfmap :: forall a b. (a -> b) -> Voice a -> Voice b
Functor
, Functor Voice
a -> Voice a
Functor Voice
-> (forall a. a -> Voice a)
-> (forall a b. Voice (a -> b) -> Voice a -> Voice b)
-> (forall a b c. (a -> b -> c) -> Voice a -> Voice b -> Voice c)
-> (forall a b. Voice a -> Voice b -> Voice b)
-> (forall a b. Voice a -> Voice b -> Voice a)
-> Applicative Voice
Voice a -> Voice b -> Voice b
Voice a -> Voice b -> Voice a
Voice (a -> b) -> Voice a -> Voice b
(a -> b -> c) -> Voice a -> Voice b -> Voice c
forall a. a -> Voice a
forall a b. Voice a -> Voice b -> Voice a
forall a b. Voice a -> Voice b -> Voice b
forall a b. Voice (a -> b) -> Voice a -> Voice b
forall a b c. (a -> b -> c) -> Voice a -> Voice b -> Voice c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: Voice a -> Voice b -> Voice a
$c<* :: forall a b. Voice a -> Voice b -> Voice a
*> :: Voice a -> Voice b -> Voice b
$c*> :: forall a b. Voice a -> Voice b -> Voice b
liftA2 :: (a -> b -> c) -> Voice a -> Voice b -> Voice c
$cliftA2 :: forall a b c. (a -> b -> c) -> Voice a -> Voice b -> Voice c
<*> :: Voice (a -> b) -> Voice a -> Voice b
$c<*> :: forall a b. Voice (a -> b) -> Voice a -> Voice b
pure :: a -> Voice a
$cpure :: forall a. a -> Voice a
$cp1Applicative :: Functor Voice
Applicative
, Applicative Voice
a -> Voice a
Applicative Voice
-> (forall a b. Voice a -> (a -> Voice b) -> Voice b)
-> (forall a b. Voice a -> Voice b -> Voice b)
-> (forall a. a -> Voice a)
-> Monad Voice
Voice a -> (a -> Voice b) -> Voice b
Voice a -> Voice b -> Voice b
forall a. a -> Voice a
forall a b. Voice a -> Voice b -> Voice b
forall a b. Voice a -> (a -> Voice b) -> Voice b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: a -> Voice a
$creturn :: forall a. a -> Voice a
>> :: Voice a -> Voice b -> Voice b
$c>> :: forall a b. Voice a -> Voice b -> Voice b
>>= :: Voice a -> (a -> Voice b) -> Voice b
$c>>= :: forall a b. Voice a -> (a -> Voice b) -> Voice b
$cp1Monad :: Applicative Voice
Monad
, MonadIO
, MonadReader DiscordBroadcastHandle
, MonadError VoiceError
, MonadFail
, MonadThrow
, MonadThrow Voice
MonadThrow Voice
-> (forall e a.
Exception e =>
Voice a -> (e -> Voice a) -> Voice a)
-> MonadCatch Voice
Voice a -> (e -> Voice a) -> Voice a
forall e a. Exception e => Voice a -> (e -> Voice a) -> Voice a
forall (m :: * -> *).
MonadThrow m
-> (forall e a. Exception e => m a -> (e -> m a) -> m a)
-> MonadCatch m
catch :: Voice a -> (e -> Voice a) -> Voice a
$ccatch :: forall e a. Exception e => Voice a -> (e -> Voice a) -> Voice a
$cp1MonadCatch :: MonadThrow Voice
MonadCatch
, MonadCatch Voice
MonadCatch Voice
-> (forall b.
((forall a. Voice a -> Voice a) -> Voice b) -> Voice b)
-> (forall b.
((forall a. Voice a -> Voice a) -> Voice b) -> Voice b)
-> (forall a b c.
Voice a
-> (a -> ExitCase b -> Voice c) -> (a -> Voice b) -> Voice (b, c))
-> MonadMask Voice
Voice a
-> (a -> ExitCase b -> Voice c) -> (a -> Voice b) -> Voice (b, c)
((forall a. Voice a -> Voice a) -> Voice b) -> Voice b
((forall a. Voice a -> Voice a) -> Voice b) -> Voice b
forall b. ((forall a. Voice a -> Voice a) -> Voice b) -> Voice b
forall a b c.
Voice a
-> (a -> ExitCase b -> Voice c) -> (a -> Voice b) -> Voice (b, c)
forall (m :: * -> *).
MonadCatch m
-> (forall b. ((forall a. m a -> m a) -> m b) -> m b)
-> (forall b. ((forall a. m a -> m a) -> m b) -> m b)
-> (forall a b c.
m a -> (a -> ExitCase b -> m c) -> (a -> m b) -> m (b, c))
-> MonadMask m
generalBracket :: Voice a
-> (a -> ExitCase b -> Voice c) -> (a -> Voice b) -> Voice (b, c)
$cgeneralBracket :: forall a b c.
Voice a
-> (a -> ExitCase b -> Voice c) -> (a -> Voice b) -> Voice (b, c)
uninterruptibleMask :: ((forall a. Voice a -> Voice a) -> Voice b) -> Voice b
$cuninterruptibleMask :: forall b. ((forall a. Voice a -> Voice a) -> Voice b) -> Voice b
mask :: ((forall a. Voice a -> Voice a) -> Voice b) -> Voice b
$cmask :: forall b. ((forall a. Voice a -> Voice a) -> Voice b) -> Voice b
$cp1MonadMask :: MonadCatch Voice
MonadMask
)
data VoiceError
= VoiceNotAvailable
| NoServerAvailable
| InvalidPayloadOrder
deriving (Int -> VoiceError -> ShowS
[VoiceError] -> ShowS
VoiceError -> String
(Int -> VoiceError -> ShowS)
-> (VoiceError -> String)
-> ([VoiceError] -> ShowS)
-> Show VoiceError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VoiceError] -> ShowS
$cshowList :: [VoiceError] -> ShowS
show :: VoiceError -> String
$cshow :: VoiceError -> String
showsPrec :: Int -> VoiceError -> ShowS
$cshowsPrec :: Int -> VoiceError -> ShowS
Show, VoiceError -> VoiceError -> Bool
(VoiceError -> VoiceError -> Bool)
-> (VoiceError -> VoiceError -> Bool) -> Eq VoiceError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VoiceError -> VoiceError -> Bool
$c/= :: VoiceError -> VoiceError -> Bool
== :: VoiceError -> VoiceError -> Bool
$c== :: VoiceError -> VoiceError -> Bool
Eq)
data SubprocessException = SubprocessException String deriving (SubprocessException -> SubprocessException -> Bool
(SubprocessException -> SubprocessException -> Bool)
-> (SubprocessException -> SubprocessException -> Bool)
-> Eq SubprocessException
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SubprocessException -> SubprocessException -> Bool
$c/= :: SubprocessException -> SubprocessException -> Bool
== :: SubprocessException -> SubprocessException -> Bool
$c== :: SubprocessException -> SubprocessException -> Bool
Eq, Int -> SubprocessException -> ShowS
[SubprocessException] -> ShowS
SubprocessException -> String
(Int -> SubprocessException -> ShowS)
-> (SubprocessException -> String)
-> ([SubprocessException] -> ShowS)
-> Show SubprocessException
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SubprocessException] -> ShowS
$cshowList :: [SubprocessException] -> ShowS
show :: SubprocessException -> String
$cshow :: SubprocessException -> String
showsPrec :: Int -> SubprocessException -> ShowS
$cshowsPrec :: Int -> SubprocessException -> ShowS
Show)
instance Exception SubprocessException
data DiscordVoiceHandle = DiscordVoiceHandle
{ DiscordVoiceHandle -> GuildId
discordVoiceHandleGuildId :: GuildId
, DiscordVoiceHandle -> ChannelId
discordVoiceHandleChannelId :: ChannelId
, DiscordVoiceHandle
-> (Weak ThreadId,
(VoiceWebsocketReceiveChan, VoiceWebsocketSendChan))
discordVoiceHandleWebsocket :: (Weak ThreadId, (VoiceWebsocketReceiveChan, VoiceWebsocketSendChan))
, DiscordVoiceHandle
-> (Weak ThreadId, (VoiceUDPReceiveChan, VoiceUDPSendChan))
discordVoiceHandleUdp :: (Weak ThreadId, (VoiceUDPReceiveChan, VoiceUDPSendChan))
, DiscordVoiceHandle -> Integer
discordVoiceHandleSsrc :: Integer
}
data DiscordBroadcastHandle = DiscordBroadcastHandle
{ DiscordBroadcastHandle -> MVar [DiscordVoiceHandle]
discordBroadcastHandleVoiceHandles :: MVar [DiscordVoiceHandle]
, DiscordBroadcastHandle -> MVar ()
discordBroadcastHandleMutEx :: MVar ()
}
data VoiceWebsocketException
= VoiceWebsocketCouldNotConnect T.Text
| VoiceWebsocketEventParseError T.Text
| VoiceWebsocketUnexpected VoiceWebsocketReceivable T.Text
| VoiceWebsocketConnection ConnectionException T.Text
deriving (Int -> VoiceWebsocketException -> ShowS
[VoiceWebsocketException] -> ShowS
VoiceWebsocketException -> String
(Int -> VoiceWebsocketException -> ShowS)
-> (VoiceWebsocketException -> String)
-> ([VoiceWebsocketException] -> ShowS)
-> Show VoiceWebsocketException
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VoiceWebsocketException] -> ShowS
$cshowList :: [VoiceWebsocketException] -> ShowS
show :: VoiceWebsocketException -> String
$cshow :: VoiceWebsocketException -> String
showsPrec :: Int -> VoiceWebsocketException -> ShowS
$cshowsPrec :: Int -> VoiceWebsocketException -> ShowS
Show)
type VoiceWebsocketReceiveChan =
Chan (Either VoiceWebsocketException VoiceWebsocketReceivable)
type VoiceWebsocketSendChan = Chan VoiceWebsocketSendable
type VoiceUDPReceiveChan = Chan VoiceUDPPacket
type VoiceUDPSendChan = Bounded.BoundedChan B.ByteString
data WebsocketLaunchOpts = WebsocketLaunchOpts
{ WebsocketLaunchOpts -> UserId
websocketLaunchOptsBotUserId :: UserId
, WebsocketLaunchOpts -> Text
websocketLaunchOptsSessionId :: T.Text
, WebsocketLaunchOpts -> Text
websocketLaunchOptsToken :: T.Text
, WebsocketLaunchOpts -> GuildId
websocketLaunchOptsGuildId :: GuildId
, WebsocketLaunchOpts -> Text
websocketLaunchOptsEndpoint :: T.Text
, WebsocketLaunchOpts
-> (VoiceWebsocketReceiveChan, VoiceWebsocketSendChan)
websocketLaunchOptsWsHandle :: (VoiceWebsocketReceiveChan, VoiceWebsocketSendChan)
, WebsocketLaunchOpts -> MVar (Weak ThreadId)
websocketLaunchOptsUdpTid :: MVar (Weak ThreadId)
, WebsocketLaunchOpts -> (VoiceUDPReceiveChan, VoiceUDPSendChan)
websocketLaunchOptsUdpHandle :: (VoiceUDPReceiveChan, VoiceUDPSendChan)
, WebsocketLaunchOpts -> MVar Integer
websocketLaunchOptsSsrc :: MVar Integer
}
data WebsocketConn = WebsocketConn
{ WebsocketConn -> Connection
websocketConnConnection :: Connection
, WebsocketConn -> WebsocketLaunchOpts
websocketConnLaunchOpts :: WebsocketLaunchOpts
}
data UDPLaunchOpts = UDPLaunchOpts
{ UDPLaunchOpts -> Integer
uDPLaunchOptsSsrc :: Integer
, UDPLaunchOpts -> Text
uDPLaunchOptsIp :: T.Text
, UDPLaunchOpts -> Integer
uDPLaunchOptsPort :: Integer
, UDPLaunchOpts -> Text
uDPLaunchOptsMode :: T.Text
, UDPLaunchOpts -> (VoiceUDPReceiveChan, VoiceUDPSendChan)
uDPLaunchOptsUdpHandle :: (VoiceUDPReceiveChan, VoiceUDPSendChan)
, UDPLaunchOpts -> MVar [Word8]
uDPLaunchOptsSecretKey :: MVar [Word8]
}
data UDPConn = UDPConn
{ UDPConn -> UDPLaunchOpts
uDPConnLaunchOpts :: UDPLaunchOpts
, UDPConn -> Socket
uDPConnSocket :: Socket
}
$(makeFields ''DiscordVoiceHandle)
$(makeFields ''DiscordBroadcastHandle)
$(makeFields ''WebsocketLaunchOpts)
$(makeFields ''WebsocketConn)
$(makeFields ''UDPLaunchOpts)
$(makeFields ''UDPConn)