diff options
| author | pb <pb@9f8f72e9-4bf4-416e-b76e-7d4203597157> | 2010-03-14 15:32:50 +0000 |
|---|---|---|
| committer | pb <pb@9f8f72e9-4bf4-416e-b76e-7d4203597157> | 2010-03-14 15:32:50 +0000 |
| commit | 29e84fb4a5fc81ebadfc4266b0b753eef44fa558 (patch) | |
| tree | 1d983de15dd34f646dbf5b4581d0afcd5301d74f /Main.hs | |
| parent | ac0057a4e0f10b78d3db0bb34c72edd034e15987 (diff) | |
git-svn-id: https://ssl.buetow.org/repos/hsbot/trunk@31 9f8f72e9-4bf4-416e-b76e-7d4203597157
Diffstat (limited to 'Main.hs')
| -rw-r--r-- | Main.hs | 57 |
1 files changed, 25 insertions, 32 deletions
@@ -23,36 +23,29 @@ r = main dispatch :: Dispatch dispatch cmd sendMessage env@(Env state conf _) = - let (Cmd _ _ dispatchFunction) = getCmd ("!" ++ cmd) - in dispatchFunction state - where - getCmd x = - let command = [ (Cmd a b c) | (Cmd a b c) <- commands, a == x ] - in if length command == 0 - then getCmd "!i" - else head command - - 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 - + let 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 + + in case cmdGet ("!" ++ cmd) commands of + Just (Cmd _ _ dispatchFunction) -> dispatchFunction state + Nothing -> dispatch "i" sendMessage env |
