Created
April 5, 2013 16:51
-
-
Save Ephemeralis/5320818 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Network | |
import System.IO | |
import Text.Printf | |
import Data.List | |
import System.Exit | |
server = "irc.ppy.sh" | |
port = 6667 | |
nick = "Ephemeral" | |
passHash = "hurrrrrr" | |
main = do | |
h <- connectTo server (PortNumber (fromIntegral port)) | |
hSetBuffering h NoBuffering | |
hSetEncoding stdout utf8 | |
write h "NICK" nick | |
write h "USER" (nick++" 0 * :Ephemeral") | |
write h "PASS" passHash | |
write h "JOIN" "#modhelp" | |
listen h | |
write :: Handle -> String -> String -> IO () | |
write h s t = do | |
hPrintf h "%s %s\r\n" s t | |
printf "> %s %s\n" s t | |
listen :: Handle -> IO () | |
listen h = forever $ do | |
s <- hGetLine h | |
if ping s then pong s else eval s | |
where | |
forever a = do a; forever a | |
clean = drop 1 . dropWhile (/= ':') . drop 1 | |
ping x = "PING" `isInfixOf` x | |
pong x = write h "PONG" (':' : drop 6 x) | |
eval :: String -> IO () | |
eval x | "PRIVMSG" `isInfixOf` x = outp x | |
eval _ = return () | |
outp :: String -> IO () | |
outp x = do | |
putStrLn (nickname x ++ " | " ++ (words x) !! 2 ++ " > " ++ message x) | |
where | |
nickname = drop 1 . takeWhile(/= '!') | |
--channel = dropWhile(/= '#') . takeWhile(/= ' ') | |
message = drop 1 . dropWhile(/= ':') . drop 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment