From 80ff91aa5d6cda6adc1c97dc39b950dd7daed9d5 Mon Sep 17 00:00:00 2001 From: pb Date: Sun, 28 Mar 2010 11:09:30 +0000 Subject: git-svn-id: https://ssl.buetow.org/repos/hsbot/trunk@50 9f8f72e9-4bf4-416e-b76e-7d4203597157 --- HsBot/Base.hs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 HsBot/Base.hs (limited to 'HsBot/Base.hs') diff --git a/HsBot/Base.hs b/HsBot/Base.hs new file mode 100644 index 0000000..a349fad --- /dev/null +++ b/HsBot/Base.hs @@ -0,0 +1,51 @@ +module HsBot.Base (startBase) where + +import System + +import HsBot.Base.Cmd +import HsBot.Base.Conf +import HsBot.Base.Env +import HsBot.Base.State +import HsBot.General.Tools +import HsBot.IRC +import HsBot.Logics + +startBase :: IO () +startBase = do + let conf = makeConf + databaseFile <- get "databaseFile" conf + let state = stateLoad databaseFile + state' <- state -- Extract State from the IO Monad + ircStart (DispatchEnv state' conf dispatch) + +dispatch :: Dispatch +dispatch msg sendMessage env@(Env state conf) = dispatch' msg + where + dispatch' ('!':_) = + case cmdGet msg commands of + Just (Cmd _ _ cmdAction) -> do + cmdAction state + return (env) + Nothing -> return (env) + dispatch' _ = logicsRun msg env + commands = [ + Cmd "!h" "Prints help" printHelp, + Cmd "!i" "Prints infos" printInfos, + Cmd "!p" "Prints current state" printState, + Cmd "!s" "Stores current state to file" storeState, + Cmd "!q" "quits" quit + ] + printHelp _ = printHelp' commands + where printHelp' = sendMessage . concat . showL + printInfos _ = do + sendMessage $ (envGet "name" env) + ++ " " ++ (envGet "version" env) + ++ " (try !h)" + printState = sendMessage . show + storeState state = do + sendMessage "Storing current state" + stateSave (envGet "databaseFile" env) state + quit state = do + sendMessage "Good bye" + stateSave (envGet "databaseFile" env) state + exitWith ExitSuccess -- cgit v1.2.3