summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Dessaux2011-05-15 14:15:55 +0200
committerJulien Dessaux2011-05-15 14:15:55 +0200
commit5a0ba99774a5687af0aac2af710ab72152f2156c (patch)
tree49eb7e3e576855d3f64ea7aff1f45c827cc77674
parentRemoved the most ugly ducks. (diff)
downloadhsbot-5a0ba99774a5687af0aac2af710ab72152f2156c.tar.gz
hsbot-5a0ba99774a5687af0aac2af710ab72152f2156c.tar.bz2
hsbot-5a0ba99774a5687af0aac2af710ab72152f2156c.zip
Fixed Duck module's behaviour when talked from other channels.
-rw-r--r--Hsbot/Plugin/Duck.hs46
1 files changed, 23 insertions, 23 deletions
diff --git a/Hsbot/Plugin/Duck.hs b/Hsbot/Plugin/Duck.hs
index 7001465..89d9a36 100644
--- a/Hsbot/Plugin/Duck.hs
+++ b/Hsbot/Plugin/Duck.hs
@@ -89,29 +89,29 @@ theDuck channel seconds = do
-- Then we check if someone shot some duck
let shots = howManyBulletFiredInThere . concat $ IRC.msg_params msg
noDucksToShoot <- liftIO $ isEmptyMVar ducksMVar
- when (shots > 0) $ do
- _ <- update' statDB (ScoreAction (getSender msg) 0 shots 0)
- when (and [getDestination msg == channel, not noDucksToShoot]) $ do
- ducksWaitingForDeath <- liftIO $ modifyMVar ducksMVar (\x -> return (x - shots, x))
- _ <- update' statDB (ScoreAction (getSender msg) 0 0 (min ducksWaitingForDeath shots))
- when (shots >= ducksWaitingForDeath) $ do
- _ <- liftIO $ takeMVar ducksMVar
- time <- liftIO $ readMVar timeMVar
- duckSpawner channel time ducksMVar
- _ <- update' statDB (ScoreAction (getSender msg) 1 0 0)
- return ()
- -- Finally we check if we received some command
- cmdArgs <- lift $ getCommand msg
- case cmdArgs of
- "duck":"freq":time:_ -> do
- case reads time :: [(Int, String)] of
- (secs,_):_ -> liftIO $ modifyMVar_ timeMVar (\_ -> return secs)
- _ -> answerMsg msg "Invalid time value."
- "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."
- "duck":"stat":_ -> query' statDB GetDuckStats >>= printDuckStats channel
- "duck":_ -> answerMsg msg "Invalid duck command."
- _ -> return ()
+ when (getDestination msg == channel) $ do
+ when (shots > 0) $ do
+ _ <- update' statDB (ScoreAction (getSender msg) 0 shots 0)
+ unless noDucksToShoot $ do
+ ducksWaitingForDeath <- liftIO $ modifyMVar ducksMVar (\x -> return (x - shots, x))
+ _ <- update' statDB (ScoreAction (getSender msg) 0 0 (min ducksWaitingForDeath shots))
+ when (shots >= ducksWaitingForDeath) $ do
+ _ <- liftIO $ takeMVar ducksMVar
+ time <- liftIO $ readMVar timeMVar
+ duckSpawner channel time ducksMVar
+ _ <- update' statDB (ScoreAction (getSender msg) 1 0 0)
+ return ()
+ -- Finally we check if we received some command
+ cmdArgs <- lift $ getCommand msg
+ case cmdArgs of
+ "duck":"freq":time:_ -> case reads time :: [(Int, String)] of
+ (secs,_):_ -> liftIO $ modifyMVar_ timeMVar (\_ -> return secs)
+ _ -> answerMsg msg "Invalid time value."
+ "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."
+ "duck":"stat":_ -> query' statDB GetDuckStats >>= printDuckStats channel
+ "duck":_ -> answerMsg msg "Invalid duck command."
+ _ -> return ()
| otherwise = return ()
eval _ _ _ _ = return ()