summaryrefslogtreecommitdiff
path: root/miaowe.hs
diff options
context:
space:
mode:
authorLaura <the-ceo-of-antifa@protonmail.com>2023-01-26 23:23:06 +0100
committerLaura <the-ceo-of-antifa@protonmail.com>2023-01-26 23:23:06 +0100
commit9d31763ebda82ee78652575f47c4fac0eb668daa (patch)
tree791e4c983e49b3191025126989205f75cb148f3f /miaowe.hs
parentae5a054c4fc3697ab0026955225db7ceeeb36ead (diff)
downloadmiaowe-9d31763ebda82ee78652575f47c4fac0eb668daa.tar.gz
miaowe-9d31763ebda82ee78652575f47c4fac0eb668daa.zip
Don't reset timer when command is rejected.
Diffstat (limited to 'miaowe.hs')
-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