From 9d31763ebda82ee78652575f47c4fac0eb668daa Mon Sep 17 00:00:00 2001 From: Laura Date: Thu, 26 Jan 2023 23:23:06 +0100 Subject: Don't reset timer when command is rejected. --- miaowe.hs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'miaowe.hs') 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 -- cgit v1.2.3