module Network.IRC.Client.Lens where
import Control.Concurrent.STM (TVar)
import Control.Monad.Catch (SomeException)
import Data.ByteString (ByteString)
import Data.Profunctor (Choice (right'),
Profunctor (dimap))
import Data.Text (Text)
import Data.Time (NominalDiffTime)
import Network.IRC.Client.Internal.Lens
import Network.IRC.Client.Internal.Types
connectionConfig :: Getter (IRCState s) (ConnectionConfig s)
connectionConfig = \ afb s -> (\ b -> s {_connectionConfig = b}) <$> afb (_connectionConfig s)
userState :: Lens' (IRCState s) (TVar s)
userState = \ afb s -> (\ b -> s {_userState = b}) <$> afb (_userState s)
instanceConfig :: Lens' (IRCState s) (TVar (InstanceConfig s))
instanceConfig = \ afb s -> (\ b -> s {_instanceConfig = b}) <$> afb (_instanceConfig s)
connectionState :: Lens' (IRCState s) (TVar ConnectionState)
connectionState = \ afb s -> (\ b -> s {_connectionState = b}) <$> afb (_connectionState s)
server :: Getter (ConnectionConfig s) ByteString
server = \ afb s -> (\ b -> s {_server = b}) <$> afb (_server s)
port :: Getter (ConnectionConfig s) Int
port = \ afb s -> (\ b -> s {_port = b}) <$> afb (_port s)
username :: Lens' (ConnectionConfig s) Text
username = \ afb s -> (\ b -> s {_username = b}) <$> afb (_username s)
realname :: Lens' (ConnectionConfig s) Text
realname = \ afb s -> (\ b -> s {_realname = b}) <$> afb (_realname s)
password :: Lens' (ConnectionConfig s) (Maybe Text)
password = \ afb s -> (\ b -> s {_password = b}) <$> afb (_password s)
flood :: Lens' (ConnectionConfig s) NominalDiffTime
flood = \ afb s -> (\ b -> s {_flood = b}) <$> afb (_flood s)
timeout :: Lens' (ConnectionConfig s) NominalDiffTime
timeout = \ afb s -> (\ b -> s {_timeout = b}) <$> afb (_timeout s)
onconnect :: Lens' (ConnectionConfig s) (IRC s ())
onconnect = \ afb s -> (\ b -> s {_onconnect = b}) <$> afb (_onconnect s)
ondisconnect :: Lens' (ConnectionConfig s) (Maybe SomeException -> IRC s ())
ondisconnect = \ afb s -> (\ b -> s {_ondisconnect = b}) <$> afb (_ondisconnect s)
logfunc :: Lens' (ConnectionConfig s) (Origin -> ByteString -> IO ())
logfunc = \ afb s -> (\ b -> s {_logfunc = b}) <$> afb (_logfunc s)
nick :: Lens' (InstanceConfig s) Text
nick = \ afb s -> (\ b -> s {_nick = b}) <$> afb (_nick s)
channels :: Lens' (InstanceConfig s) [Text]
channels = \ afb s -> (\ b -> s {_channels = b}) <$> afb (_channels s)
version :: Lens' (InstanceConfig s) Text
version = \ afb s -> (\ b -> s {_version = b}) <$> afb (_version s)
handlers :: Lens' (InstanceConfig s) [EventHandler s]
handlers = \ afb s -> (\ b -> s {_handlers = b}) <$> afb (_handlers s)
ignore :: Lens' (InstanceConfig s) [(Text, Maybe Text)]
ignore = \ afb s -> (\ b -> s {_ignore = b}) <$> afb (_ignore s)
_Connected :: Prism' ConnectionState ()
_Connected = dimap (\ s -> case s of Connected -> Right (); _ -> Left s)
(either pure $ fmap (\ () -> Connected)) . right'
_Disconnecting :: Prism' ConnectionState ()
_Disconnecting = dimap (\ s -> case s of Disconnecting -> Right (); _ -> Left s)
(either pure $ fmap (\ () -> Disconnecting)) . right'
_Disconnected :: Prism' ConnectionState ()
_Disconnected = dimap (\ s -> case s of Disconnected -> Right (); _ -> Left s)
(either pure $ fmap (\ () -> Disconnected)) . right'
_FromServer :: Prism' Origin ()
_FromServer = dimap (\ s -> case s of FromServer -> Right (); _ -> Left s)
(either pure $ fmap (\ () -> FromServer)) . right'
_FromClient :: Prism' Origin ()
_FromClient = dimap (\ s -> case s of FromClient -> Right (); _ -> Left s)
(either pure $ fmap (\ () -> FromClient)) . right'