From 09bc3834373cad1f8e44eeb05854f19b66e208f8 Mon Sep 17 00:00:00 2001 From: Laura Date: Mon, 16 Jan 2023 21:43:33 +0100 Subject: Fortune --- miaowe.hs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'miaowe.hs') diff --git a/miaowe.hs b/miaowe.hs index f7fb8e6..608ba44 100644 --- a/miaowe.hs +++ b/miaowe.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE CPP #-} + -- IRC art (spam)bot {- @@ -28,6 +30,10 @@ import System.Exit import System.IO import Text.Printf +#ifdef FORTUNE +import System.Process +#endif + type BitMap = [Word8] type MircString = String @@ -42,7 +48,12 @@ data Image = Image { } codeUrl = "https://gitlab.com/laleanor/miaowe" -helpString = "Commands available: List; Code; Help. Anything else is interpreted as a file name." + +#ifdef FORTUNE +helpString = "Commands available: Code; Fortune; Help; List. Anything else is interpreted as a file name." +#else +helpString = "Commands available: Code; Help; List. Anything else is interpreted as a file name." +#endif ctrlC = [toEnum 03] :: String ctrlO = [toEnum 15] :: String @@ -128,8 +139,8 @@ ppmToImage ppm = Image ircConnect :: String -> MircString ircConnect credentials = printf "NICK miaowe\r\n\ - \USER nya 0 * :mew mew\r\n\ - \PRIVMSG NickServ :IDENTIFY %s\r\n" credentials +USER nya 0 * :mew mew\r\n\ +PRIVMSG NickServ :IDENTIFY %s\r\n" credentials waitForMessage :: (String -> Bool) -> IO String waitForMessage p = getLine >>= \l -> if p l @@ -180,9 +191,14 @@ trySendFile channel path = (doesFileExist (path) then sendFile channel (path) else - sendToChannel channel "No such file." + sendToChannel channel "No such file or command." >> hFlush stdout)) +#ifdef FORTUNE +getFortune :: IO String +getFortune = readCreateProcess ((shell "fortune | cowsay -b")) "" +#endif + processCommand :: IrcChannel -> MircString -> IO () processCommand channel command | length (words command) < 5 = sendToChannel channel "You need to specify a command." @@ -192,6 +208,10 @@ processCommand channel command | length (words command) < 5 = sendToChannel chan intercalate "\n" | (words command)!!4 == "Code" = sendToChannel channel codeUrl | (words command)!!4 == "Help" = sendToChannel channel helpString +#ifdef FORTUNE + | (words command)!!4 == "Fortune" = getFortune + >>= sendToChannel channel +#endif | otherwise = (if isInfixOf "/" ((words command)!!4) then sendToChannel channel -- cgit v1.2.3