diff options
author | Laura <the-ceo-of-antifa@protonmail.com> | 2023-01-16 21:43:33 +0100 |
---|---|---|
committer | Laura <the-ceo-of-antifa@protonmail.com> | 2023-01-16 21:43:33 +0100 |
commit | 09bc3834373cad1f8e44eeb05854f19b66e208f8 (patch) | |
tree | 8ee9574fcd878db8228e01d9df1d1bbbedaa266f | |
parent | dbf609a7e83e69abef13e5db57575ce101d5c9c5 (diff) | |
download | miaowe-09bc3834373cad1f8e44eeb05854f19b66e208f8.tar.gz miaowe-09bc3834373cad1f8e44eeb05854f19b66e208f8.zip |
Fortune
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | miaowe.hs | 28 |
3 files changed, 27 insertions, 5 deletions
@@ -2,4 +2,4 @@ SRCS := miaowe.hs TARGET := miaowe $(TARGET): $(SRCS) - ghc -g -o $(TARGET) $(SRCS) + ghc -g $(GHCFLAGS) -o $(TARGET) $(SRCS) @@ -18,6 +18,8 @@ Available commands: * Help -- helps * Quit -- quits +Miaowe can optionally include a fortune cookie command. To enable this, compile with: `make GHCFLAGS=-DFORTUNE`. The command will be called "Fortune". + To run: ./miaowe <channel> @@ -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 |