From 2e4f14d2848d91aae83d60082dd6085431a663a8 Mon Sep 17 00:00:00 2001 From: Laura Date: Tue, 17 Jan 2023 23:19:46 +0100 Subject: Case-insensitive commands --- miaowe.hs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/miaowe.hs b/miaowe.hs index 608ba44..82ad8aa 100644 --- a/miaowe.hs +++ b/miaowe.hs @@ -202,23 +202,24 @@ getFortune = readCreateProcess ((shell "fortune | cowsay -b")) "" processCommand :: IrcChannel -> MircString -> IO () processCommand channel command | length (words command) < 5 = sendToChannel channel "You need to specify a command." - | (words command)!!4 == "Quit" = exitSuccess - | (words command)!!4 == "List" = listDirectory "." - >>= sendToChannel channel . - intercalate "\n" - | (words command)!!4 == "Code" = sendToChannel channel codeUrl - | (words command)!!4 == "Help" = sendToChannel channel helpString + | otherwise = case (words command)!!4 of + "quit" -> exitSuccess + "list" -> listDirectory "." + >>= sendToChannel channel . + intercalate "\n" + "code" -> sendToChannel channel codeUrl + "help" -> sendToChannel channel helpString #ifdef FORTUNE - | (words command)!!4 == "Fortune" = getFortune - >>= sendToChannel channel + "fortune" -> getFortune + >>= sendToChannel channel #endif - | otherwise = (if isInfixOf "/" ((words command)!!4) - then - sendToChannel channel - "Only PWD please." - else - trySendFile channel - ((words command)!!4)) + _ -> (if isInfixOf "/" ((words command)!!4) + then + sendToChannel channel + "Only PWD please." + else + trySendFile channel + ((words command)!!4)) mainLoop :: IrcChannel -> IO () mainLoop channel = waitForCommand -- cgit v1.2.3