diff options
| author | pb <pb@9f8f72e9-4bf4-416e-b76e-7d4203597157> | 2010-03-14 14:59:11 +0000 |
|---|---|---|
| committer | pb <pb@9f8f72e9-4bf4-416e-b76e-7d4203597157> | 2010-03-14 14:59:11 +0000 |
| commit | 505b9940f6739dafd5a71fec8d7fdba4724d90ba (patch) | |
| tree | 25f6ada26275a667761f70e308098e5ea6665a5f /Main.hs | |
| parent | 17c092a07ad03bbb77bcf629463f78b5a49dc4cb (diff) | |
git-svn-id: https://ssl.buetow.org/repos/hsbot/trunk@28 9f8f72e9-4bf4-416e-b76e-7d4203597157
Diffstat (limited to 'Main.hs')
| -rw-r--r-- | Main.hs | 45 |
1 files changed, 43 insertions, 2 deletions
@@ -1,9 +1,13 @@ module Main where +import System + +import Cmd import Conf +import Env import IRC import State -import Env +import Tools main :: IO () main = do @@ -11,9 +15,46 @@ main = do databaseFile <- get "databaseFile" conf let state = stateLoad databaseFile state' <- state -- Extract State from the IO Monad - ircConnect (Env state' conf) + ircConnect (Env state' conf dispatch) -- Shortcut r :: IO () 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 + 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 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 ) + ] + |
