{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}

-- |
-- Module      : Network.IRC.Client.Internal.Types
-- Copyright   : (c) 2017 Michael Walker
-- License     : MIT
-- Maintainer  : Michael Walker <mike@barrucadu.co.uk>
-- Stability   : experimental
-- Portability : FlexibleInstances, GADTs, GeneralizedNewtypeDeriving, MultiParamTypeClasses
--
-- Internal types. Most of these are re-exported elsewhere as lenses.
--
-- This module is NOT considered to form part of the public interface
-- of this library.
module Network.IRC.Client.Internal.Types where

import           Control.Applicative            (Alternative)
import           Control.Concurrent             (ThreadId)
import           Control.Concurrent.STM         (TVar, atomically, readTVar,
                                                 readTVarIO, writeTVar)
import           Control.Concurrent.STM.TBMChan (TBMChan)
import           Control.Monad                  (MonadPlus)
import           Control.Monad.Catch            (Exception, MonadCatch,
                                                 MonadMask, MonadThrow,
                                                 SomeException)
import           Control.Monad.IO.Class         (MonadIO, liftIO)
import           Control.Monad.Reader           (MonadReader, ReaderT, asks)
import           Control.Monad.State            (MonadState(..))
import           Data.ByteString                (ByteString)
import           Data.Conduit                   (ConduitM)
import qualified Data.Set                       as S
import           Data.Text                      (Text)
import           Data.Time.Clock                (NominalDiffTime)
import           Data.Void                      (Void)
import           Network.IRC.Conduit            (Event(..), Message, Source)


-------------------------------------------------------------------------------
-- * The IRC monad

-- | The IRC monad.
newtype IRC s a = IRC { forall s a. IRC s a -> ReaderT (IRCState s) IO a
runIRC :: ReaderT (IRCState s) IO a }
  deriving (forall a b. a -> IRC s b -> IRC s a
forall a b. (a -> b) -> IRC s a -> IRC s b
forall s a b. a -> IRC s b -> IRC s a
forall s a b. (a -> b) -> IRC s a -> IRC s b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> IRC s b -> IRC s a
$c<$ :: forall s a b. a -> IRC s b -> IRC s a
fmap :: forall a b. (a -> b) -> IRC s a -> IRC s b
$cfmap :: forall s a b. (a -> b) -> IRC s a -> IRC s b
Functor, forall s. Functor (IRC s)
forall a. a -> IRC s a
forall s a. a -> IRC s a
forall a b. IRC s a -> IRC s b -> IRC s a
forall a b. IRC s a -> IRC s b -> IRC s b
forall a b. IRC s (a -> b) -> IRC s a -> IRC s b
forall s a b. IRC s a -> IRC s b -> IRC s a
forall s a b. IRC s a -> IRC s b -> IRC s b
forall s a b. IRC s (a -> b) -> IRC s a -> IRC s b
forall a b c. (a -> b -> c) -> IRC s a -> IRC s b -> IRC s c
forall s a b c. (a -> b -> c) -> IRC s a -> IRC s b -> IRC s 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
<* :: forall a b. IRC s a -> IRC s b -> IRC s a
$c<* :: forall s a b. IRC s a -> IRC s b -> IRC s a
*> :: forall a b. IRC s a -> IRC s b -> IRC s b
$c*> :: forall s a b. IRC s a -> IRC s b -> IRC s b
liftA2 :: forall a b c. (a -> b -> c) -> IRC s a -> IRC s b -> IRC s c
$cliftA2 :: forall s a b c. (a -> b -> c) -> IRC s a -> IRC s b -> IRC s c
<*> :: forall a b. IRC s (a -> b) -> IRC s a -> IRC s b
$c<*> :: forall s a b. IRC s (a -> b) -> IRC s a -> IRC s b
pure :: forall a. a -> IRC s a
$cpure :: forall s a. a -> IRC s a
Applicative, forall s. Applicative (IRC s)
forall a. IRC s a
forall a. IRC s a -> IRC s [a]
forall a. IRC s a -> IRC s a -> IRC s a
forall s a. IRC s a
forall s a. IRC s a -> IRC s [a]
forall s a. IRC s a -> IRC s a -> IRC s a
forall (f :: * -> *).
Applicative f
-> (forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
many :: forall a. IRC s a -> IRC s [a]
$cmany :: forall s a. IRC s a -> IRC s [a]
some :: forall a. IRC s a -> IRC s [a]
$csome :: forall s a. IRC s a -> IRC s [a]
<|> :: forall a. IRC s a -> IRC s a -> IRC s a
$c<|> :: forall s a. IRC s a -> IRC s a -> IRC s a
empty :: forall a. IRC s a
$cempty :: forall s a. IRC s a
Alternative, forall s. Applicative (IRC s)
forall a. a -> IRC s a
forall s a. a -> IRC s a
forall a b. IRC s a -> IRC s b -> IRC s b
forall a b. IRC s a -> (a -> IRC s b) -> IRC s b
forall s a b. IRC s a -> IRC s b -> IRC s b
forall s a b. IRC s a -> (a -> IRC s b) -> IRC s 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 :: forall a. a -> IRC s a
$creturn :: forall s a. a -> IRC s a
>> :: forall a b. IRC s a -> IRC s b -> IRC s b
$c>> :: forall s a b. IRC s a -> IRC s b -> IRC s b
>>= :: forall a b. IRC s a -> (a -> IRC s b) -> IRC s b
$c>>= :: forall s a b. IRC s a -> (a -> IRC s b) -> IRC s b
Monad, forall s. Monad (IRC s)
forall s. Alternative (IRC s)
forall a. IRC s a
forall a. IRC s a -> IRC s a -> IRC s a
forall s a. IRC s a
forall s a. IRC s a -> IRC s a -> IRC s a
forall (m :: * -> *).
Alternative m
-> Monad m
-> (forall a. m a)
-> (forall a. m a -> m a -> m a)
-> MonadPlus m
mplus :: forall a. IRC s a -> IRC s a -> IRC s a
$cmplus :: forall s a. IRC s a -> IRC s a -> IRC s a
mzero :: forall a. IRC s a
$cmzero :: forall s a. IRC s a
MonadPlus, forall s. Monad (IRC s)
forall a. IO a -> IRC s a
forall s a. IO a -> IRC s a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
liftIO :: forall a. IO a -> IRC s a
$cliftIO :: forall s a. IO a -> IRC s a
MonadIO, MonadReader (IRCState s), forall s. Monad (IRC s)
forall e a. Exception e => e -> IRC s a
forall s e a. Exception e => e -> IRC s a
forall (m :: * -> *).
Monad m -> (forall e a. Exception e => e -> m a) -> MonadThrow m
throwM :: forall e a. Exception e => e -> IRC s a
$cthrowM :: forall s e a. Exception e => e -> IRC s a
MonadThrow, forall s. MonadThrow (IRC s)
forall e a. Exception e => IRC s a -> (e -> IRC s a) -> IRC s a
forall s e a. Exception e => IRC s a -> (e -> IRC s a) -> IRC s a
forall (m :: * -> *).
MonadThrow m
-> (forall e a. Exception e => m a -> (e -> m a) -> m a)
-> MonadCatch m
catch :: forall e a. Exception e => IRC s a -> (e -> IRC s a) -> IRC s a
$ccatch :: forall s e a. Exception e => IRC s a -> (e -> IRC s a) -> IRC s a
MonadCatch, forall s. MonadCatch (IRC s)
forall b. ((forall a. IRC s a -> IRC s a) -> IRC s b) -> IRC s b
forall s b. ((forall a. IRC s a -> IRC s a) -> IRC s b) -> IRC s b
forall a b c.
IRC s a
-> (a -> ExitCase b -> IRC s c) -> (a -> IRC s b) -> IRC s (b, c)
forall s a b c.
IRC s a
-> (a -> ExitCase b -> IRC s c) -> (a -> IRC s b) -> IRC s (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 :: forall a b c.
IRC s a
-> (a -> ExitCase b -> IRC s c) -> (a -> IRC s b) -> IRC s (b, c)
$cgeneralBracket :: forall s a b c.
IRC s a
-> (a -> ExitCase b -> IRC s c) -> (a -> IRC s b) -> IRC s (b, c)
uninterruptibleMask :: forall b. ((forall a. IRC s a -> IRC s a) -> IRC s b) -> IRC s b
$cuninterruptibleMask :: forall s b. ((forall a. IRC s a -> IRC s a) -> IRC s b) -> IRC s b
mask :: forall b. ((forall a. IRC s a -> IRC s a) -> IRC s b) -> IRC s b
$cmask :: forall s b. ((forall a. IRC s a -> IRC s a) -> IRC s b) -> IRC s b
MonadMask)

instance MonadState s (IRC s) where
  state :: forall a. (s -> (a, s)) -> IRC s a
state s -> (a, s)
f = do
    TVar s
tvar <- forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks forall s. IRCState s -> TVar s
_userState
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. STM a -> IO a
atomically forall a b. (a -> b) -> a -> b
$ do
      (a
a, s
s) <- s -> (a, s)
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. TVar a -> STM a
readTVar TVar s
tvar
      forall a. TVar a -> a -> STM ()
writeTVar TVar s
tvar s
s
      forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a
  get :: IRC s s
get = do
    TVar s
tvar <- forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks forall s. IRCState s -> TVar s
_userState
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall a. TVar a -> IO a
readTVarIO TVar s
tvar
  put :: s -> IRC s ()
put s
s = do
    TVar s
tvar <- forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks forall s. IRCState s -> TVar s
_userState
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall a. STM a -> IO a
atomically (forall a. TVar a -> a -> STM ()
writeTVar TVar s
tvar s
s)

-------------------------------------------------------------------------------
-- * State

-- | The state of an IRC session.
data IRCState s = IRCState
  { forall s. IRCState s -> ConnectionConfig s
_connectionConfig :: ConnectionConfig s
  -- ^ Read-only connection configuration
  , forall s. IRCState s -> TVar s
_userState        :: TVar s
  -- ^ Mutable user state
  , forall s. IRCState s -> TVar (InstanceConfig s)
_instanceConfig   :: TVar (InstanceConfig s)
  -- ^ Mutable instance configuration in STM
  , forall s. IRCState s -> TVar (TBMChan (Message ByteString))
_sendqueue        :: TVar (TBMChan (Message ByteString))
  -- ^ Message send queue.
  , forall s. IRCState s -> TVar ConnectionState
_connectionState  :: TVar ConnectionState
  -- ^ State of the connection.
  , forall s. IRCState s -> TVar (Set ThreadId)
_runningThreads   :: TVar (S.Set ThreadId)
  -- ^ Threads which will be killed when the client disconnects.
  }

-- | The static state of an IRC server connection.
data ConnectionConfig s = ConnectionConfig
  { forall s.
ConnectionConfig s
-> IO ()
-> ConduitM (Either ByteString (Event ByteString)) Void IO ()
-> ConduitM () (Message ByteString) IO ()
-> IO ()
_func       :: IO () -> ConduitM (Either ByteString (Event ByteString)) Void IO () -> ConduitM () (Message ByteString) IO () -> IO ()
  -- ^ Function to connect and start the conduits.
  , forall s. ConnectionConfig s -> ByteString
_server     :: ByteString
  -- ^ The server host.
  , forall s. ConnectionConfig s -> Int
_port       :: Int
  -- ^ The server port.
  , forall s. ConnectionConfig s -> Text
_username   :: Text
  -- ^ Client username; sent to the server during the initial set-up.
  , forall s. ConnectionConfig s -> Text
_realname   :: Text
  -- ^ Client realname; sent to the server during the initial set-up.
  , forall s. ConnectionConfig s -> Maybe Text
_password   :: Maybe Text
  -- ^ Client password; sent to the server during the initial set-up.
  , forall s. ConnectionConfig s -> NominalDiffTime
_flood      :: NominalDiffTime
  -- ^ The minimum time between two adjacent messages.
  , forall s. ConnectionConfig s -> NominalDiffTime
_timeout    :: NominalDiffTime
  -- ^ The maximum time (in seconds) between received messages from
  -- the server. If no messages arrive from the server for this
  -- period, the client is sent a 'Timeout' exception and disconnects.
  , forall s. ConnectionConfig s -> IRC s ()
_onconnect  :: IRC s ()
  -- ^ Action to run after sending the @PASS@ and @USER@ commands to the
  -- server. The default behaviour is to send the @NICK@ command.
  , forall s. ConnectionConfig s -> Maybe SomeException -> IRC s ()
_ondisconnect :: Maybe SomeException -> IRC s ()
  -- ^ Action to run after disconnecting from the server, both by
  -- local choice and by losing the connection. This is run after
  -- tearing down the connection. If the connection terminated due to
  -- an exception, it is given. The default behaviour is to reconnect
  -- if a timeout, otherwise rethrow any exception.
  , forall s. ConnectionConfig s -> Origin -> ByteString -> IO ()
_logfunc    :: Origin -> ByteString -> IO ()
  -- ^ Function to log messages sent to and received from the server.
  }

-- | The updateable state of an IRC connection.
data InstanceConfig s = InstanceConfig
  { forall s. InstanceConfig s -> Text
_nick     :: Text
  -- ^ Client nick
  , forall s. InstanceConfig s -> [Text]
_channels :: [Text]
  -- ^ Current channels: this list both determines the channels to join on
  -- connect, and is modified by the default event handlers when channels
  -- are joined or parted.
  , forall s. InstanceConfig s -> Text
_version  :: Text
  -- ^ The version is sent in response to the CTCP \"VERSION\" request by
  -- the default event handlers.
  , forall s. InstanceConfig s -> [EventHandler s]
_handlers :: [EventHandler s]
  -- ^ The registered event handlers. The order in this list is the
  -- order in which they are executed.
  , forall s. InstanceConfig s -> [(Text, Maybe Text)]
_ignore   :: [(Text, Maybe Text)]
  -- ^ List of nicks (optionally restricted to channels) to ignore
  -- messages from. 'Nothing' ignores globally.
  }

-- | The state of the connection.
data ConnectionState = Connected | Disconnecting | Disconnected
  deriving (ConnectionState
forall a. a -> a -> Bounded a
maxBound :: ConnectionState
$cmaxBound :: ConnectionState
minBound :: ConnectionState
$cminBound :: ConnectionState
Bounded, Int -> ConnectionState
ConnectionState -> Int
ConnectionState -> [ConnectionState]
ConnectionState -> ConnectionState
ConnectionState -> ConnectionState -> [ConnectionState]
ConnectionState
-> ConnectionState -> ConnectionState -> [ConnectionState]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: ConnectionState
-> ConnectionState -> ConnectionState -> [ConnectionState]
$cenumFromThenTo :: ConnectionState
-> ConnectionState -> ConnectionState -> [ConnectionState]
enumFromTo :: ConnectionState -> ConnectionState -> [ConnectionState]
$cenumFromTo :: ConnectionState -> ConnectionState -> [ConnectionState]
enumFromThen :: ConnectionState -> ConnectionState -> [ConnectionState]
$cenumFromThen :: ConnectionState -> ConnectionState -> [ConnectionState]
enumFrom :: ConnectionState -> [ConnectionState]
$cenumFrom :: ConnectionState -> [ConnectionState]
fromEnum :: ConnectionState -> Int
$cfromEnum :: ConnectionState -> Int
toEnum :: Int -> ConnectionState
$ctoEnum :: Int -> ConnectionState
pred :: ConnectionState -> ConnectionState
$cpred :: ConnectionState -> ConnectionState
succ :: ConnectionState -> ConnectionState
$csucc :: ConnectionState -> ConnectionState
Enum, ConnectionState -> ConnectionState -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConnectionState -> ConnectionState -> Bool
$c/= :: ConnectionState -> ConnectionState -> Bool
== :: ConnectionState -> ConnectionState -> Bool
$c== :: ConnectionState -> ConnectionState -> Bool
Eq, Eq ConnectionState
ConnectionState -> ConnectionState -> Bool
ConnectionState -> ConnectionState -> Ordering
ConnectionState -> ConnectionState -> ConnectionState
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ConnectionState -> ConnectionState -> ConnectionState
$cmin :: ConnectionState -> ConnectionState -> ConnectionState
max :: ConnectionState -> ConnectionState -> ConnectionState
$cmax :: ConnectionState -> ConnectionState -> ConnectionState
>= :: ConnectionState -> ConnectionState -> Bool
$c>= :: ConnectionState -> ConnectionState -> Bool
> :: ConnectionState -> ConnectionState -> Bool
$c> :: ConnectionState -> ConnectionState -> Bool
<= :: ConnectionState -> ConnectionState -> Bool
$c<= :: ConnectionState -> ConnectionState -> Bool
< :: ConnectionState -> ConnectionState -> Bool
$c< :: ConnectionState -> ConnectionState -> Bool
compare :: ConnectionState -> ConnectionState -> Ordering
$ccompare :: ConnectionState -> ConnectionState -> Ordering
Ord, ReadPrec [ConnectionState]
ReadPrec ConnectionState
Int -> ReadS ConnectionState
ReadS [ConnectionState]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ConnectionState]
$creadListPrec :: ReadPrec [ConnectionState]
readPrec :: ReadPrec ConnectionState
$creadPrec :: ReadPrec ConnectionState
readList :: ReadS [ConnectionState]
$creadList :: ReadS [ConnectionState]
readsPrec :: Int -> ReadS ConnectionState
$creadsPrec :: Int -> ReadS ConnectionState
Read, Int -> ConnectionState -> ShowS
[ConnectionState] -> ShowS
ConnectionState -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConnectionState] -> ShowS
$cshowList :: [ConnectionState] -> ShowS
show :: ConnectionState -> String
$cshow :: ConnectionState -> String
showsPrec :: Int -> ConnectionState -> ShowS
$cshowsPrec :: Int -> ConnectionState -> ShowS
Show)

-- | The origin of a message.
data Origin = FromServer | FromClient
  deriving (Origin
forall a. a -> a -> Bounded a
maxBound :: Origin
$cmaxBound :: Origin
minBound :: Origin
$cminBound :: Origin
Bounded, Int -> Origin
Origin -> Int
Origin -> [Origin]
Origin -> Origin
Origin -> Origin -> [Origin]
Origin -> Origin -> Origin -> [Origin]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Origin -> Origin -> Origin -> [Origin]
$cenumFromThenTo :: Origin -> Origin -> Origin -> [Origin]
enumFromTo :: Origin -> Origin -> [Origin]
$cenumFromTo :: Origin -> Origin -> [Origin]
enumFromThen :: Origin -> Origin -> [Origin]
$cenumFromThen :: Origin -> Origin -> [Origin]
enumFrom :: Origin -> [Origin]
$cenumFrom :: Origin -> [Origin]
fromEnum :: Origin -> Int
$cfromEnum :: Origin -> Int
toEnum :: Int -> Origin
$ctoEnum :: Int -> Origin
pred :: Origin -> Origin
$cpred :: Origin -> Origin
succ :: Origin -> Origin
$csucc :: Origin -> Origin
Enum, Origin -> Origin -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Origin -> Origin -> Bool
$c/= :: Origin -> Origin -> Bool
== :: Origin -> Origin -> Bool
$c== :: Origin -> Origin -> Bool
Eq, Eq Origin
Origin -> Origin -> Bool
Origin -> Origin -> Ordering
Origin -> Origin -> Origin
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Origin -> Origin -> Origin
$cmin :: Origin -> Origin -> Origin
max :: Origin -> Origin -> Origin
$cmax :: Origin -> Origin -> Origin
>= :: Origin -> Origin -> Bool
$c>= :: Origin -> Origin -> Bool
> :: Origin -> Origin -> Bool
$c> :: Origin -> Origin -> Bool
<= :: Origin -> Origin -> Bool
$c<= :: Origin -> Origin -> Bool
< :: Origin -> Origin -> Bool
$c< :: Origin -> Origin -> Bool
compare :: Origin -> Origin -> Ordering
$ccompare :: Origin -> Origin -> Ordering
Ord, ReadPrec [Origin]
ReadPrec Origin
Int -> ReadS Origin
ReadS [Origin]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Origin]
$creadListPrec :: ReadPrec [Origin]
readPrec :: ReadPrec Origin
$creadPrec :: ReadPrec Origin
readList :: ReadS [Origin]
$creadList :: ReadS [Origin]
readsPrec :: Int -> ReadS Origin
$creadsPrec :: Int -> ReadS Origin
Read, Int -> Origin -> ShowS
[Origin] -> ShowS
Origin -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Origin] -> ShowS
$cshowList :: [Origin] -> ShowS
show :: Origin -> String
$cshow :: Origin -> String
showsPrec :: Int -> Origin -> ShowS
$cshowsPrec :: Int -> Origin -> ShowS
Show)


-------------------------------------------------------------------------------
-- * Events

-- | A function which handles an event.
data EventHandler s where
  EventHandler
    :: (Event Text -> Maybe b)
    -> (Source Text -> b -> IRC s ())
    -> EventHandler s


-------------------------------------------------------------------------------
-- * Exceptions

-- | Exception thrown to kill the client if the timeout elapses with
-- nothing received from the server.
data Timeout = Timeout
  deriving (Timeout
forall a. a -> a -> Bounded a
maxBound :: Timeout
$cmaxBound :: Timeout
minBound :: Timeout
$cminBound :: Timeout
Bounded, Int -> Timeout
Timeout -> Int
Timeout -> [Timeout]
Timeout -> Timeout
Timeout -> Timeout -> [Timeout]
Timeout -> Timeout -> Timeout -> [Timeout]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Timeout -> Timeout -> Timeout -> [Timeout]
$cenumFromThenTo :: Timeout -> Timeout -> Timeout -> [Timeout]
enumFromTo :: Timeout -> Timeout -> [Timeout]
$cenumFromTo :: Timeout -> Timeout -> [Timeout]
enumFromThen :: Timeout -> Timeout -> [Timeout]
$cenumFromThen :: Timeout -> Timeout -> [Timeout]
enumFrom :: Timeout -> [Timeout]
$cenumFrom :: Timeout -> [Timeout]
fromEnum :: Timeout -> Int
$cfromEnum :: Timeout -> Int
toEnum :: Int -> Timeout
$ctoEnum :: Int -> Timeout
pred :: Timeout -> Timeout
$cpred :: Timeout -> Timeout
succ :: Timeout -> Timeout
$csucc :: Timeout -> Timeout
Enum, Timeout -> Timeout -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Timeout -> Timeout -> Bool
$c/= :: Timeout -> Timeout -> Bool
== :: Timeout -> Timeout -> Bool
$c== :: Timeout -> Timeout -> Bool
Eq, Eq Timeout
Timeout -> Timeout -> Bool
Timeout -> Timeout -> Ordering
Timeout -> Timeout -> Timeout
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Timeout -> Timeout -> Timeout
$cmin :: Timeout -> Timeout -> Timeout
max :: Timeout -> Timeout -> Timeout
$cmax :: Timeout -> Timeout -> Timeout
>= :: Timeout -> Timeout -> Bool
$c>= :: Timeout -> Timeout -> Bool
> :: Timeout -> Timeout -> Bool
$c> :: Timeout -> Timeout -> Bool
<= :: Timeout -> Timeout -> Bool
$c<= :: Timeout -> Timeout -> Bool
< :: Timeout -> Timeout -> Bool
$c< :: Timeout -> Timeout -> Bool
compare :: Timeout -> Timeout -> Ordering
$ccompare :: Timeout -> Timeout -> Ordering
Ord, ReadPrec [Timeout]
ReadPrec Timeout
Int -> ReadS Timeout
ReadS [Timeout]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Timeout]
$creadListPrec :: ReadPrec [Timeout]
readPrec :: ReadPrec Timeout
$creadPrec :: ReadPrec Timeout
readList :: ReadS [Timeout]
$creadList :: ReadS [Timeout]
readsPrec :: Int -> ReadS Timeout
$creadsPrec :: Int -> ReadS Timeout
Read, Int -> Timeout -> ShowS
[Timeout] -> ShowS
Timeout -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Timeout] -> ShowS
$cshowList :: [Timeout] -> ShowS
show :: Timeout -> String
$cshow :: Timeout -> String
showsPrec :: Int -> Timeout -> ShowS
$cshowsPrec :: Int -> Timeout -> ShowS
Show)

instance Exception Timeout

-- | Exception thrown to all managed threads when the client
-- disconnects.
data Disconnect = Disconnect
  deriving (Disconnect
forall a. a -> a -> Bounded a
maxBound :: Disconnect
$cmaxBound :: Disconnect
minBound :: Disconnect
$cminBound :: Disconnect
Bounded, Int -> Disconnect
Disconnect -> Int
Disconnect -> [Disconnect]
Disconnect -> Disconnect
Disconnect -> Disconnect -> [Disconnect]
Disconnect -> Disconnect -> Disconnect -> [Disconnect]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Disconnect -> Disconnect -> Disconnect -> [Disconnect]
$cenumFromThenTo :: Disconnect -> Disconnect -> Disconnect -> [Disconnect]
enumFromTo :: Disconnect -> Disconnect -> [Disconnect]
$cenumFromTo :: Disconnect -> Disconnect -> [Disconnect]
enumFromThen :: Disconnect -> Disconnect -> [Disconnect]
$cenumFromThen :: Disconnect -> Disconnect -> [Disconnect]
enumFrom :: Disconnect -> [Disconnect]
$cenumFrom :: Disconnect -> [Disconnect]
fromEnum :: Disconnect -> Int
$cfromEnum :: Disconnect -> Int
toEnum :: Int -> Disconnect
$ctoEnum :: Int -> Disconnect
pred :: Disconnect -> Disconnect
$cpred :: Disconnect -> Disconnect
succ :: Disconnect -> Disconnect
$csucc :: Disconnect -> Disconnect
Enum, Disconnect -> Disconnect -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Disconnect -> Disconnect -> Bool
$c/= :: Disconnect -> Disconnect -> Bool
== :: Disconnect -> Disconnect -> Bool
$c== :: Disconnect -> Disconnect -> Bool
Eq, Eq Disconnect
Disconnect -> Disconnect -> Bool
Disconnect -> Disconnect -> Ordering
Disconnect -> Disconnect -> Disconnect
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Disconnect -> Disconnect -> Disconnect
$cmin :: Disconnect -> Disconnect -> Disconnect
max :: Disconnect -> Disconnect -> Disconnect
$cmax :: Disconnect -> Disconnect -> Disconnect
>= :: Disconnect -> Disconnect -> Bool
$c>= :: Disconnect -> Disconnect -> Bool
> :: Disconnect -> Disconnect -> Bool
$c> :: Disconnect -> Disconnect -> Bool
<= :: Disconnect -> Disconnect -> Bool
$c<= :: Disconnect -> Disconnect -> Bool
< :: Disconnect -> Disconnect -> Bool
$c< :: Disconnect -> Disconnect -> Bool
compare :: Disconnect -> Disconnect -> Ordering
$ccompare :: Disconnect -> Disconnect -> Ordering
Ord, ReadPrec [Disconnect]
ReadPrec Disconnect
Int -> ReadS Disconnect
ReadS [Disconnect]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Disconnect]
$creadListPrec :: ReadPrec [Disconnect]
readPrec :: ReadPrec Disconnect
$creadPrec :: ReadPrec Disconnect
readList :: ReadS [Disconnect]
$creadList :: ReadS [Disconnect]
readsPrec :: Int -> ReadS Disconnect
$creadsPrec :: Int -> ReadS Disconnect
Read, Int -> Disconnect -> ShowS
[Disconnect] -> ShowS
Disconnect -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Disconnect] -> ShowS
$cshowList :: [Disconnect] -> ShowS
show :: Disconnect -> String
$cshow :: Disconnect -> String
showsPrec :: Int -> Disconnect -> ShowS
$cshowsPrec :: Int -> Disconnect -> ShowS
Show)

instance Exception Disconnect