summaryrefslogtreecommitdiff
path: root/Hsbot/Main.hs
blob: 592fefa7878b42ccb8196f55c053d2397606c434 (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
module Hsbot.Main
    ( imain
    ) where

import Control.Exception
import Control.Monad.State
import Prelude hiding (catch)
import System.IO

import Config
import Hsbot.Core
import Hsbot.IRC
import Hsbot.Plugin
import Hsbot.Types

-- | Bot's main entry point
imain :: IO ()
imain = do
    bot <- connectServer $ ircServer config
    (execStateT run bot) `catch` (\(ex :: IOException) -> return bot)
    evalStateT disconnectServer bot

-- | The Bot monad main function
run :: IrcBot ()
run = do
    initServer
    mapM_ loadPlugin defaultPlugins
    runServer