summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaura <the-ceo-of-antifa@protonmail.com>2023-01-16 21:43:33 +0100
committerLaura <the-ceo-of-antifa@protonmail.com>2023-01-16 21:43:33 +0100
commit09bc3834373cad1f8e44eeb05854f19b66e208f8 (patch)
tree8ee9574fcd878db8228e01d9df1d1bbbedaa266f
parentdbf609a7e83e69abef13e5db57575ce101d5c9c5 (diff)
downloadmiaowe-09bc3834373cad1f8e44eeb05854f19b66e208f8.tar.gz
miaowe-09bc3834373cad1f8e44eeb05854f19b66e208f8.zip
Fortune
-rw-r--r--Makefile2
-rw-r--r--README.md2
-rw-r--r--miaowe.hs28
3 files changed, 27 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index 0ea3d7b..0f4a25f 100644
--- a/Makefile
+++ b/Makefile
@@ -2,4 +2,4 @@ SRCS := miaowe.hs
TARGET := miaowe
$(TARGET): $(SRCS)
- ghc -g -o $(TARGET) $(SRCS)
+ ghc -g $(GHCFLAGS) -o $(TARGET) $(SRCS)
diff --git a/README.md b/README.md
index 09b6ff5..2abc586 100644
--- a/README.md
+++ b/README.md
@@ -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>
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