From df5f62ab71f56722bdeca8e77c78ab1d7aeeeb24 Mon Sep 17 00:00:00 2001 From: pb Date: Tue, 16 Mar 2010 20:56:57 +0000 Subject: git-svn-id: https://ssl.buetow.org/repos/hsbot/trunk@34 9f8f72e9-4bf4-416e-b76e-7d4203597157 --- Env.hs | 6 +++--- IRC.hs | 10 +++++----- Main.hs | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Env.hs b/Env.hs index 30c005d..a914dab 100644 --- a/Env.hs +++ b/Env.hs @@ -4,11 +4,11 @@ import Conf import State type Dispatch = String -> (String -> IO ()) -> Env -> IO () -data Env = Env State Conf Dispatch | EnvWoDispatch State Conf +data Env = DispatchEnv State Conf Dispatch | Env State Conf envGetInt :: String -> Env -> Int -envGetInt key (Env _ conf _) = getUnwrappedInt key conf +envGetInt key (DispatchEnv _ conf _) = getUnwrappedInt key conf envGet :: String -> Env -> String -envGet key (Env _ conf _) = getUnwrapped key conf +envGet key (DispatchEnv _ conf _) = getUnwrapped key conf diff --git a/IRC.hs b/IRC.hs index fc32d9b..68d71f6 100644 --- a/IRC.hs +++ b/IRC.hs @@ -26,7 +26,7 @@ ircWrite h s t = do hPrintf h "%s %s\r\n" s t ircPrivMsg :: Handle -> IrcMessage -> Env -> String -> IO () -ircPrivMsg h msg (EnvWoDispatch state conf) s = do +ircPrivMsg h msg (Env state conf) s = do if isMultiline s then ircPrivMsg' (lines s) else ircPrivMsg' [s] @@ -52,7 +52,7 @@ ircPrivMsg h msg (EnvWoDispatch state conf) s = do ircPrivMsg' xs ircConnect :: Env -> IO () -ircConnect (Env state conf dispatch) = do +ircConnect (DispatchEnv state conf dispatch) = do ircChannel <- get "ircChannel" conf ircNick <- get "ircNick" conf ircPort <- get "ircPort" conf @@ -62,7 +62,7 @@ ircConnect (Env state conf dispatch) = do hSetBuffering h NoBuffering ircWrite h "NICK" ircNick ircWrite h "USER" $ ircNick ++ " 0 * :" ++ ircUser - ircEvalLoop h (Env state { currentChannel = ircChannel } conf dispatch) + ircEvalLoop h (DispatchEnv state { currentChannel = ircChannel } conf dispatch) ircEvalLoop :: Handle -> Env -> IO () ircEvalLoop h env = forever $ do @@ -85,12 +85,12 @@ ircEvalLoop h env = forever $ do pong x = ircWrite h "PONG" (':' : drop 6 x) ircEval :: Handle -> IrcMessage -> Env -> IO () -ircEval h msg env@(Env state conf dispatch) = +ircEval h msg env@(DispatchEnv state conf dispatch) = case isCommand (clean msg) of Just cmd -> dispatch cmd sendReplyMsg envWoDispatch Nothing -> evalServerMessage (clean msg) where - envWoDispatch = (EnvWoDispatch state conf) + envWoDispatch = (Env state conf) isCommand ('!':xs) = Just xs isCommand _ = Nothing evalServerMessage "+x" = ircWrite h "JOIN" (currentChannel state) diff --git a/Main.hs b/Main.hs index 58a7ca4..7726f70 100644 --- a/Main.hs +++ b/Main.hs @@ -15,14 +15,14 @@ main = do databaseFile <- get "databaseFile" conf let state = stateLoad databaseFile state' <- state -- Extract State from the IO Monad - ircConnect (Env state' conf dispatch) + ircConnect (DispatchEnv state' conf dispatch) -- Shortcut r :: IO () r = main dispatch :: Dispatch -dispatch cmd sendMessage env@(EnvWoDispatch state conf) = +dispatch cmd sendMessage env@(Env state conf) = let commands = [ Cmd "!h" "Prints help" printHelp, Cmd "!i" "Prints infos" printInfos, -- cgit v1.2.3