Archived
1
0
Fork 0

Began a big refactoring/rewriting (again)

This commit is contained in:
Julien Dessaux 2011-04-13 20:15:55 +02:00
parent d05aea2def
commit ff07633fb8
41 changed files with 423 additions and 5107 deletions

39
Hsbot.hs Normal file
View file

@ -0,0 +1,39 @@
module Hsbot
( hsbot
) where
import qualified Config.Dyre as Dyre
import Config.Dyre.Relaunch
import Control.Monad.Reader
import System.Log.Logger
import Hsbot.Config
import Hsbot.Core
import Hsbot.Types
startHsbot :: Config -> IO ()
startHsbot config = do
-- checking for configuration file compilation error
case configErrors config of
Nothing -> return ()
Just em -> putStrLn $ "Error: " ++ em
-- initialization
infoM "Hsbot" "Bot initializations"
hsbotEnv <- initHsbot config
-- main stuff
infoM "Hsbot" "Bot core starting"
status <- runReaderT runHsbot hsbotEnv
infoM "Hsbot" $ "Bot core exited with status " ++ (show status)
-- Handling exit signal
case status of
BotContinue -> startHsbot config -- TODO do something not so dumb about starting over
BotExit -> runReaderT terminateHsbot hsbotEnv
BotReload -> relaunchMaster Nothing -- TODO relaunchWithTextState (state { stateConfig = config }) Nothing, add a flag that prevent spawning the sockets again
BotRestart -> relaunchMaster Nothing -- TODO relaunch and kill sockets
hsbot :: Config -> IO ()
hsbot = Dyre.wrapMain $ Dyre.defaultParams
{ Dyre.projectName = "hsbot"
, Dyre.realMain = startHsbot
, Dyre.showError = (\config err -> config { configErrors = Just err }) }