diff options
| -rw-r--r-- | HsBot/Base/Env.hs | 3 | ||||
| -rw-r--r-- | HsBot/Base/State.hs | 1 | ||||
| -rw-r--r-- | HsBot/IRC.hs | 6 | ||||
| -rw-r--r-- | HsBot/Logics/Dummy.hs | 9 | ||||
| -rw-r--r-- | hsbot.db | 2 |
5 files changed, 14 insertions, 7 deletions
diff --git a/HsBot/Base/Env.hs b/HsBot/Base/Env.hs index 36fafd5..e5a9133 100644 --- a/HsBot/Base/Env.hs +++ b/HsBot/Base/Env.hs @@ -18,3 +18,6 @@ envGet :: String -> Env -> String envGet key (Env _ conf) = getUnwrapped key conf envGet key env = envGet key (castEnv env) +envState :: Env -> State +envState (Env state _) = state +envState env = envState (castEnv env) diff --git a/HsBot/Base/State.hs b/HsBot/Base/State.hs index abcf479..6d4efdc 100644 --- a/HsBot/Base/State.hs +++ b/HsBot/Base/State.hs @@ -6,6 +6,7 @@ import List import HsBot.IRC.User data State = State { + isReady :: Bool, currentChannel :: String, line :: String, users :: [User] diff --git a/HsBot/IRC.hs b/HsBot/IRC.hs index cf1a1e8..da488ea 100644 --- a/HsBot/IRC.hs +++ b/HsBot/IRC.hs @@ -60,7 +60,7 @@ ircStart (DispatchEnv state conf dispatch) = do hSetBuffering h NoBuffering ircWrite h "NICK" ircNick ircWrite h "USER" $ ircNick ++ " 0 * :" ++ ircUser - ircEvalLoop h (DispatchEnv state { currentChannel = ircChannel } conf dispatch) + ircEvalLoop h (DispatchEnv state { isReady = False, currentChannel = ircChannel } conf dispatch) return () ircEvalLoop :: Handle -> Env -> IO () @@ -84,11 +84,11 @@ ircEvalLoop h env = do } ircEval :: Handle -> IrcMessage -> Env -> IO Env -ircEval h msg env@(DispatchEnv state _ dispatch) = ircEval' (clean msg) +ircEval h msg env@(DispatchEnv state conf dispatch) = ircEval' (clean msg) where ircEval' "+x" = do ircWrite h "JOIN" (currentChannel state) - return (env) + return (DispatchEnv state { isReady = True } conf dispatch) ircEval' cleanMsg = do (Env s c) <- dispatch cleanMsg sendReplyMsg (castEnv env) return (DispatchEnv s c dispatch) diff --git a/HsBot/Logics/Dummy.hs b/HsBot/Logics/Dummy.hs index a873f8a..be32a50 100644 --- a/HsBot/Logics/Dummy.hs +++ b/HsBot/Logics/Dummy.hs @@ -1,10 +1,13 @@ module HsBot.Logics.Dummy (dummyRun) where import HsBot.Base.Env +import HsBot.Base.State dummyRun :: String -> SendMessage -> Env -> IO Env -dummyRun str sendMessage env = do - --sendMessage "Hello World" - putStrLn str +dummyRun str sendMessage env@(Env state _) = do + if isReady state + --then sendMessage "Hello World" + then putStrLn $ "::::" ++ str + else putStrLn str return (env) @@ -1 +1 @@ -State {currentChannel = "#buetow.org", line = "!w\DELs", users = [User {userName = "thunder", userPts = 103},User {userName = "otto", userPts = 4},User {userName = "rantanplan", userPts = 102},User {userName = "rantanplan2", userPts = 6},User {userName = "icefox2", userPts = 14},User {userName = "icefox", userPts = 13},User {userName = "foobar", userPts = 8},User {userName = "foobar1", userPts = 8},User {userName = "foobar2", userPts = 8},User {userName = "foobar3", userPts = 8},User {userName = "foobar4", userPts = 8},User {userName = "foobar5", userPts = 8},User {userName = "foobar6", userPts = 8},User {userName = "openfire", userPts = 5}]}
\ No newline at end of file +State {isReady = True, currentChannel = "#buetow.org", line = "!w\DELs", users = [User {userName = "thunder", userPts = 103},User {userName = "otto", userPts = 4},User {userName = "rantanplan", userPts = 102},User {userName = "rantanplan2", userPts = 6},User {userName = "icefox2", userPts = 14},User {userName = "icefox", userPts = 13},User {userName = "foobar", userPts = 8},User {userName = "foobar1", userPts = 8},User {userName = "foobar2", userPts = 8},User {userName = "foobar3", userPts = 8},User {userName = "foobar4", userPts = 8},User {userName = "foobar5", userPts = 8},User {userName = "foobar6", userPts = 8},User {userName = "openfire", userPts = 5}]}
\ No newline at end of file |
