Archived
1
0
Fork 0

Fixed Duck module's behaviour when talked from other channels.

This commit is contained in:
Julien Dessaux 2011-05-15 14:15:55 +02:00
parent 1e348a0ad2
commit 5a0ba99774

View file

@ -89,29 +89,29 @@ theDuck channel seconds = do
-- Then we check if someone shot some duck -- Then we check if someone shot some duck
let shots = howManyBulletFiredInThere . concat $ IRC.msg_params msg let shots = howManyBulletFiredInThere . concat $ IRC.msg_params msg
noDucksToShoot <- liftIO $ isEmptyMVar ducksMVar noDucksToShoot <- liftIO $ isEmptyMVar ducksMVar
when (shots > 0) $ do when (getDestination msg == channel) $ do
_ <- update' statDB (ScoreAction (getSender msg) 0 shots 0) when (shots > 0) $ do
when (and [getDestination msg == channel, not noDucksToShoot]) $ do _ <- update' statDB (ScoreAction (getSender msg) 0 shots 0)
ducksWaitingForDeath <- liftIO $ modifyMVar ducksMVar (\x -> return (x - shots, x)) unless noDucksToShoot $ do
_ <- update' statDB (ScoreAction (getSender msg) 0 0 (min ducksWaitingForDeath shots)) ducksWaitingForDeath <- liftIO $ modifyMVar ducksMVar (\x -> return (x - shots, x))
when (shots >= ducksWaitingForDeath) $ do _ <- update' statDB (ScoreAction (getSender msg) 0 0 (min ducksWaitingForDeath shots))
_ <- liftIO $ takeMVar ducksMVar when (shots >= ducksWaitingForDeath) $ do
time <- liftIO $ readMVar timeMVar _ <- liftIO $ takeMVar ducksMVar
duckSpawner channel time ducksMVar time <- liftIO $ readMVar timeMVar
_ <- update' statDB (ScoreAction (getSender msg) 1 0 0) duckSpawner channel time ducksMVar
return () _ <- update' statDB (ScoreAction (getSender msg) 1 0 0)
-- Finally we check if we received some command return ()
cmdArgs <- lift $ getCommand msg -- Finally we check if we received some command
case cmdArgs of cmdArgs <- lift $ getCommand msg
"duck":"freq":time:_ -> do case cmdArgs of
case reads time :: [(Int, String)] of "duck":"freq":time:_ -> case reads time :: [(Int, String)] of
(secs,_):_ -> liftIO $ modifyMVar_ timeMVar (\_ -> return secs) (secs,_):_ -> liftIO $ modifyMVar_ timeMVar (\_ -> return secs)
_ -> answerMsg msg "Invalid time value." _ -> answerMsg msg "Invalid time value."
"duck":"freq":_ -> answerMsg msg $ "You must provide an amount of seconds the bot should wait before spawning " "duck":"freq":_ -> answerMsg msg $ "You must provide an amount of seconds the bot should wait before spawning "
++ "new ducks after the end of a round." ++ "new ducks after the end of a round."
"duck":"stat":_ -> query' statDB GetDuckStats >>= printDuckStats channel "duck":"stat":_ -> query' statDB GetDuckStats >>= printDuckStats channel
"duck":_ -> answerMsg msg "Invalid duck command." "duck":_ -> answerMsg msg "Invalid duck command."
_ -> return () _ -> return ()
| otherwise = return () | otherwise = return ()
eval _ _ _ _ = return () eval _ _ _ _ = return ()