summaryrefslogtreecommitdiff
path: root/Hsbot/Irc/Types.hs
blob: eac58d7f0b4ebdec2eb158456915b6a0983c9f64 (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
module Hsbot.Irc.Types
    ( IrcBot
    , IrcBotState (..)
    , IrcServer
    , IrcServerState (..)
    ) where

import Control.Concurrent
import Control.Monad.State
import qualified Data.Map as M
import Data.Time
import System.IO

import Hsbot.Irc.Config
import Hsbot.Irc.Message
import Hsbot.Irc.PluginCommons
import Hsbot.Message

-- | The Ircbot monad
type IrcBot = StateT IrcBotState IO

-- | An Ircbot state
data IrcBotState = IrcBotState
    { ircBotStartTime            :: UTCTime                     -- the bot's uptime
    , ircBotPlugins              :: M.Map String IrcPluginState -- Loaded plugins
    , ircBotCommands             :: M.Map String [String]       -- Loaded plugins
    , ircBotChan                 :: Chan IrcBotMsg              -- The IrcBot's communication channel
    , ircBotMasterChan           :: Chan BotMsg                 -- The Hsbot communication channel
    , ircBotMyChan               :: Chan BotMsg                 -- The Hsbot communication channel
    , ircBotServerState          :: IrcServerState              -- The state of the IrcServer
    , ircBotHandle               :: Handle                      -- The server's socket/handle
    , ircBotConfig               :: IrcConfig                   -- The starting configuration
    , ircBotReaderThreadId       :: ThreadId
    , ircBotMasterReaderThreadId :: ThreadId
    }

-- | The IrcServer monad
type IrcServer = StateT IrcServerState IrcBot

-- | An IRC server
data IrcServerState = IrcServerState
    { ircServerId            :: String         -- the server's address
    , ircServerChannels      :: [String]       -- the Channels we are connected to
    , ircServerNickname      :: String         -- the hsbot's nickname
    , ircServerCommandPrefix :: Char           -- the prefix the ircbot will recognize as commands
    , ircServerChan          :: Chan IrcBotMsg -- the IrcBot channel
    }