From af903e0031288f6e4f1c8a63db8ef9efc63f8b91 Mon Sep 17 00:00:00 2001 From: pb Date: Fri, 26 Mar 2010 22:31:54 +0000 Subject: git-svn-id: https://ssl.buetow.org/repos/hsbot/trunk@41 9f8f72e9-4bf4-416e-b76e-7d4203597157 --- Main.hs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'Main.hs') diff --git a/Main.hs b/Main.hs index 1d668d3..df2c41b 100644 --- a/Main.hs +++ b/Main.hs @@ -22,30 +22,33 @@ r :: IO () r = main dispatch :: Dispatch -dispatch cmd sendMessage env@(Env state conf) = - let commands = [ +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' _ = return (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 + printHelp _ = printHelp' commands where printHelp' = sendMessage . concat . showL - printInfos _ = do + printInfos _ = do sendMessage $ (envGet "name" env) ++ " " ++ (envGet "version" env) ++ " (try !h)" - printState = sendMessage . show - storeState state = do + printState = sendMessage . show + storeState state = do sendMessage "Storing current state" stateSave (envGet "databaseFile" env) state - quit state = do + quit state = do sendMessage "Good bye" stateSave (envGet "databaseFile" env) state exitWith ExitSuccess - - in case cmdGet ("!" ++ cmd) commands of - Just (Cmd _ _ cmdAction) -> cmdAction state - Nothing -> return () - -- cgit v1.2.3