Skip to content

Instantly share code, notes, and snippets.

@funrep
Created June 2, 2013 09:54
Show Gist options
  • Save funrep/5693194 to your computer and use it in GitHub Desktop.
Save funrep/5693194 to your computer and use it in GitHub Desktop.
module IRC where
import Network (connectTo, PortNumber)
import System.IO (hGetLine)
import Text.Printf (hPrintf, printf)
import Config
type Net = ReaderT Bot IO
data Bot = Bot { socket :: Handle }
connect :: IO Bot
connect =
connectTo server $ PortNumber $ fromIntegral port
>>= return . Bot
listen :: (String -> Net ()) -> Handle -> Net ()
listen cmd h = do
s <- fmap last $ liftIO $ hGetLine h
liftIO $ putStrLn s
if ping s then pong s else liftIO $ cmd $ clean s
listen cmd h
where
clean = drop 1 . dropWhile (/= ':' . drop 1
ping x = "PING :" `isPrefixOf` x
pong x = write "PONG" $ ':' : drop 6 x
privmsg :: String -> Net ()
privmsg s = write "PRIVMSG" $ chan ++ " :" ++ s
write :: String -> String -> Net ()
write s t = do
h <- asks socket
liftIO $ hPrintf h "%s %s\n" s t
liftIO $ printf "> %s %s\n" s t
@funrep
Copy link
Author

funrep commented Jun 2, 2013

Building tob-0.0...
Preprocessing executable 'tob' for tob-0.0...
[2 of 4] Compiling IRC ( src/IRC.hs, dist/build/tob/tob-tmp/IRC.o )

src/IRC.hs:25:5: parse error (possibly incorrect indentation)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment