summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--miaowe.hs14
1 files changed, 10 insertions, 4 deletions
diff --git a/miaowe.hs b/miaowe.hs
index 99f4327..e2be098 100644
--- a/miaowe.hs
+++ b/miaowe.hs
@@ -251,16 +251,22 @@ doCommand channel command =
trySendFile channel
((words command)!!4))
-processCommand :: IrcChannel -> MircString -> NominalDiffTime -> IO ()
+subtractPresent :: NominalDiffTime -> IO UTCTime
+subtractPresent t = getCurrentTime >>= \c -> return $ addUTCTime (-t) c
+
+processCommand :: IrcChannel -> MircString -> NominalDiffTime -> IO UTCTime
processCommand channel command timeElapsed | timeElapsed < 30 =
sendToChannel channel
"Not so quick, partner"
+ >> subtractPresent timeElapsed
| length (words command) < 5 =
sendToChannel channel
"You need to specify \
a command."
+ >> subtractPresent timeElapsed
| otherwise =
doCommand channel command
+ >> getCurrentTime
commandChannel :: String -> String
commandChannel command = (words command)!!2
@@ -270,9 +276,9 @@ mainLoop channel time = waitForCommand
>>= \line ->
(if commandChannel line == channel
then getCurrentTime
- >>= \t -> processCommand channel line (diffUTCTime t time)
- else return ())
- >> getCurrentTime
+ >>= \t -> processCommand channel line
+ (diffUTCTime t time)
+ else return time)
>>= mainLoop channel