summaryrefslogtreecommitdiff
path: root/Hsbot.hs
diff options
context:
space:
mode:
authorJulien Dessaux2011-04-13 20:15:55 +0200
committerJulien Dessaux2011-04-13 20:15:55 +0200
commitff07633fb8f81577ffec409cbf0a3c7361990f6c (patch)
tree5021a2e13f878c6b29ad3ec835f694d0726b7e9c /Hsbot.hs
parentRegressed from parsec3 to parsec2 to solve a cabal install weird dependency p... (diff)
downloadhsbot-ff07633fb8f81577ffec409cbf0a3c7361990f6c.tar.gz
hsbot-ff07633fb8f81577ffec409cbf0a3c7361990f6c.tar.bz2
hsbot-ff07633fb8f81577ffec409cbf0a3c7361990f6c.zip
Began a big refactoring/rewriting (again)
Diffstat (limited to 'Hsbot.hs')
-rw-r--r--Hsbot.hs39
1 files changed, 39 insertions, 0 deletions
diff --git a/Hsbot.hs b/Hsbot.hs
new file mode 100644
index 0000000..bf87df7
--- /dev/null
+++ b/Hsbot.hs
@@ -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 }) }
+