summaryrefslogtreecommitdiff
path: root/Main.hs
diff options
context:
space:
mode:
authorpb <pb@9f8f72e9-4bf4-416e-b76e-7d4203597157>2010-03-26 22:31:54 +0000
committerpb <pb@9f8f72e9-4bf4-416e-b76e-7d4203597157>2010-03-26 22:31:54 +0000
commitaf903e0031288f6e4f1c8a63db8ef9efc63f8b91 (patch)
tree7c80a2a52e3ed711573c63df837af04fd66606f9 /Main.hs
parent429c6c5657e207d55d99d49e82142a23755d9911 (diff)
git-svn-id: https://ssl.buetow.org/repos/hsbot/trunk@41 9f8f72e9-4bf4-416e-b76e-7d4203597157
Diffstat (limited to 'Main.hs')
-rw-r--r--Main.hs27
1 files changed, 15 insertions, 12 deletions
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 ()
-