summaryrefslogtreecommitdiff
path: root/Hsbot/Types.hs
blob: c7331d3d965c4f0bb7920b4630b67f303b7afd2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
module Hsbot.Types
    ( Bot
    , BotState (..)
    , BotStatus (..)
    , BotEnv (..)
    , Config (..)
    , Env
    , Message (..)
    , Plugin
    , PluginEnv (..)
    , PluginId (..)
    , TLSConfig (..)
    ) where

import Control.Concurrent
import qualified Data.Map as M
import Control.Monad.Reader
import Control.Monad.State
import Network
import qualified Network.IRC as IRC
import Network.TLS
import System.IO

-- The bot environment
type Env = ReaderT BotEnv

data BotEnv = BotEnv
    { envBotState    :: MVar BotState
    , envHandle      :: Handle
    , envChan        :: Chan Message
    , envQuitMv      :: MVar BotStatus
    , envThreadIdsMv :: MVar [ThreadId]
    , envConfig      :: Config
    , envTLS         :: Maybe TLSParams
    , envTLSCtx      :: Maybe TLSCtx
    }

-- The bot monad
type Bot = StateT BotState

data BotState = BotState
    { botPlugins  :: M.Map String (PluginEnv, ThreadId)
    , botHooks    :: [Chan Message]
    , botChannels :: [String]
    , botNickname :: String
    }

-- The Plugin monad
type Plugin = ReaderT PluginEnv

data PluginEnv = PluginEnv
    { pluginId     :: PluginId
    , pluginChan   :: Chan Message
    , pluginMaster :: Chan Message
    }

data PluginId = PluginId
    { pluginName :: String
    , pluginEp   :: Plugin (Env IO) ()
    }

-- Messaging
data Message = IncomingMsg IRC.Message
             | OutgoingMsg IRC.Message

data BotStatus = BotContinue | BotExit | BotReload | BotRestart deriving (Show)

-- Config
data Config = Config
    { configErrors    :: Maybe String
    , configTLS       :: TLSConfig
    , configAddress   :: String
    , configPort      :: PortID
    , configChannels  :: [String]
    , configNicknames :: [String]
    , configRealname  :: String
    , configPlugins   :: [PluginId]
    }

data TLSConfig = TLSConfig
    { sslOn       :: Bool
    , sslCert     :: String
    , sslKey      :: String
    , sslVersions :: [Network.TLS.Version]
    , sslCiphers  :: [Network.TLS.Cipher]
    , sslVerify   :: Bool
    } deriving (Show)