summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaura <the-ceo-of-antifa@protonmail.com>2023-01-26 19:52:01 +0100
committerLaura <the-ceo-of-antifa@protonmail.com>2023-01-26 19:52:01 +0100
commitae5a054c4fc3697ab0026955225db7ceeeb36ead (patch)
tree7c388792f603403a16d76097e416212b6d68bb73
parentf210592c5881747c2baacde5dd8ab0e09c61dc95 (diff)
downloadmiaowe-ae5a054c4fc3697ab0026955225db7ceeeb36ead.tar.gz
miaowe-ae5a054c4fc3697ab0026955225db7ceeeb36ead.zip
Throttle so we don't get klined for flooding
-rw-r--r--miaowe.hs33
1 files changed, 21 insertions, 12 deletions
diff --git a/miaowe.hs b/miaowe.hs
index aa26987..99f4327 100644
--- a/miaowe.hs
+++ b/miaowe.hs
@@ -24,6 +24,7 @@ import qualified Data.ByteString.Char8 as S.Char8
import qualified Data.ByteString.Internal as S.Internal
import Data.Char
import Data.List
+import Data.Time
import Data.Word
import System.Directory
import System.Environment
@@ -250,22 +251,29 @@ doCommand channel command =
trySendFile channel
((words command)!!4))
-processCommand :: IrcChannel -> MircString -> IO ()
-processCommand channel command | length (words command) < 5 = sendToChannel channel
- "You need to specify \
+processCommand :: IrcChannel -> MircString -> NominalDiffTime -> IO ()
+processCommand channel command timeElapsed | timeElapsed < 30 =
+ sendToChannel channel
+ "Not so quick, partner"
+ | length (words command) < 5 =
+ sendToChannel channel
+ "You need to specify \
a command."
- | otherwise = doCommand channel command
+ | otherwise =
+ doCommand channel command
commandChannel :: String -> String
commandChannel command = (words command)!!2
-mainLoop :: IrcChannel -> IO ()
-mainLoop channel = waitForCommand
- >>= \line ->
- (if commandChannel line == channel
- then processCommand channel line
- else return ())
- >> mainLoop channel
+mainLoop :: IrcChannel -> UTCTime -> IO ()
+mainLoop channel time = waitForCommand
+ >>= \line ->
+ (if commandChannel line == channel
+ then getCurrentTime
+ >>= \t -> processCommand channel line (diffUTCTime t time)
+ else return ())
+ >> getCurrentTime
+ >>= mainLoop channel
main :: IO ()
@@ -282,4 +290,5 @@ main =
>>= \args ->
joinChannel (args!!0)
>> hFlush stdout
- >> mainLoop (args!!0)
+ >> getCurrentTime
+ >>= mainLoop (args!!0)