summaryrefslogtreecommitdiff
path: root/Main.hs
diff options
context:
space:
mode:
authorpb <pb@9f8f72e9-4bf4-416e-b76e-7d4203597157>2010-03-14 15:25:03 +0000
committerpb <pb@9f8f72e9-4bf4-416e-b76e-7d4203597157>2010-03-14 15:25:03 +0000
commitac0057a4e0f10b78d3db0bb34c72edd034e15987 (patch)
tree404daff8bcc3619079183dd82894ee3eb2807efe /Main.hs
parent00b43501612224cb32a6cde6c3c97d2e39b49d59 (diff)
git-svn-id: https://ssl.buetow.org/repos/hsbot/trunk@30 9f8f72e9-4bf4-416e-b76e-7d4203597157
Diffstat (limited to 'Main.hs')
-rw-r--r--Main.hs58
1 files changed, 28 insertions, 30 deletions
diff --git a/Main.hs b/Main.hs
index 60d522c..f550665 100644
--- a/Main.hs
+++ b/Main.hs
@@ -23,38 +23,36 @@ r = main
dispatch :: Dispatch
dispatch cmd sendMessage env@(Env state conf _) =
- getLambda ("!" ++ cmd) state
- where
- printHelp = sendMessage . concat . showL
- getLambda x = let (Cmd _ _ c) = getCmd x in c
- getDescr x = let (Cmd _ b _) = getCmd x in b
+ 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
+ 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 commands ),
-
- Cmd "!i" "Prints infos"
- (\_ -> sendMessage $ (envGet "name" env)
- ++ " " ++ (envGet "version" env)
- ++ " (try !h)" ),
-
- Cmd "!p" "Prints current state"
- (\s -> sendMessage $ show s ),
-
- Cmd "!s" "Stores current state to file"
- (\s -> do
- sendMessage "Storing current state"
- stateSave (envGet "databaseFile" env) s ),
-
- Cmd "!q" "quits"
- (\s -> do
- sendMessage "Good bye"
- stateSave (envGet "databaseFile" env) s
- exitWith ExitSuccess )
+ 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
+
+