summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Dessaux2011-05-16 01:27:27 +0200
committerJulien Dessaux2011-05-16 01:27:27 +0200
commitbc8299374e6245d0fa425dfbe505fa414c7e6168 (patch)
treed899f2619eae4b275c0ce9ead8418f0557597277
parentSome more stupid ducks' faces. (diff)
downloadhsbot-bc8299374e6245d0fa425dfbe505fa414c7e6168.tar.gz
hsbot-bc8299374e6245d0fa425dfbe505fa414c7e6168.tar.bz2
hsbot-bc8299374e6245d0fa425dfbe505fa414c7e6168.zip
Fixed inconsistencies in the duck module.
-rw-r--r--Hsbot/Plugin/Duck.hs11
1 files changed, 5 insertions, 6 deletions
diff --git a/Hsbot/Plugin/Duck.hs b/Hsbot/Plugin/Duck.hs
index 6a97abd..187c62d 100644
--- a/Hsbot/Plugin/Duck.hs
+++ b/Hsbot/Plugin/Duck.hs
@@ -61,7 +61,6 @@ scoreAction sender rounds shots kills = do
getDuckStats :: Query StatDB StatDB
getDuckStats = ask
--- This will define @ViewMessage@ and @AddMessage@ for us.
$(makeAcidic ''StatDB ['getDuckStats, 'scoreAction])
-- | The duck plugin identity
@@ -87,11 +86,11 @@ theDuck channel seconds = do
let kills = howManyDucksInThere . concat $ IRC.msg_params msg
when (kills /= "") $ answerMsg msg kills
-- Then we check if someone shot some duck
- let shots = howManyBulletFiredInThere . concat $ IRC.msg_params msg
- noDucksToShoot <- liftIO $ isEmptyMVar ducksMVar
when (getDestination msg == channel) $ do
+ let shots = howManyBulletFiredInThere . concat $ IRC.msg_params msg
when (shots > 0) $ do
_ <- update' statDB (ScoreAction (getSender msg) 0 shots 0)
+ noDucksToShoot <- liftIO $ isEmptyMVar ducksMVar
unless noDucksToShoot $ do
ducksWaitingForDeath <- liftIO $ modifyMVar ducksMVar (\x -> return (x - shots, x))
_ <- update' statDB (ScoreAction (getSender msg) 0 0 (min ducksWaitingForDeath shots))
@@ -115,7 +114,7 @@ theDuck channel seconds = do
| otherwise = return ()
eval _ _ _ _ = return ()
--- | Regularly spawns ducks on a channel, just waiting to be shot
+-- | Spawns ducks on a channel, just waiting to be shot
duckSpawner :: String -> Int -> MVar Int -> Plugin (Env IO) ()
duckSpawner channel secs ducksMVar = do
pEnv <- ask
@@ -131,11 +130,11 @@ duckSpawner channel secs ducksMVar = do
writeMsg . OutgoingMsg $ IRC.Message Nothing "PRIVMSG" [channel, concat thoseDucks]
liftIO myThreadId >>= lift . delThreadIdFromQuitMVar
--- | Shoot as many times are there are ducks in the initial string
+-- | Tels how many shots we can hear from this string
howManyBulletFiredInThere :: String -> Int
howManyBulletFiredInThere = sum . concatMap (\y -> map (\x -> if x `L.isInfixOf` y then 1 else 0) bangs) . words
--- | Shoot as many times are there are ducks in the initial string
+-- | Shoot as many times there are ducks in the provided string
howManyDucksInThere :: String -> String
howManyDucksInThere = concat . concatMap (\y -> map (\x -> if x `L.isInfixOf` y then "PAN! " else "") ducks) . words