From 7b2c43b8d6c1d55f7058c58532b20cbaaad58102 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 8 Oct 2015 22:45:15 +0200 Subject: Remove trailing spaces --- hirc.hs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'hirc.hs') diff --git a/hirc.hs b/hirc.hs index c5de6f3..b22ad36 100644 --- a/hirc.hs +++ b/hirc.hs @@ -12,25 +12,25 @@ import Hirc.Parser as P import Hirc.Types import Text.Parsec (parse) import Text.Printf - + server = "irc.freenode.org" port = 6667 chan = "#hirc-testing" nick = "hirc" filename = server <> (':' : show port) - + -- The 'Net' monad, a wrapper over IO, carrying the bot's immutable state. type Net = ReaderT Bot IO data Bot = Bot { socket :: Handle } - + -- Set up actions to run on start and end, and run the main loop main :: IO () main = bracket connect disconnect loop where disconnect = hClose . socket loop st = runReaderT run st - + -- Connect to the server and return the initial bot state connect :: IO Bot connect = notify $ do @@ -42,7 +42,7 @@ connect = notify $ do (printf "Connecting to %s ... " server >> hFlush stdout) (putStrLn "done.") a - + -- We're in the Net monad now, so we've connected successfully -- Join a channel, and start processing commands run :: Net () @@ -50,7 +50,7 @@ run = do write "NICK" nick write "USER" (nick++" 0 * :hirc bot") asks socket >>= listen - + -- Process each line from the server listen :: Handle -> Net () listen h = forever $ do @@ -59,7 +59,7 @@ listen h = forever $ do case parse P.message filename s of Right m -> eval m x -> io $ putStrLn $ show x - + -- Dispatch a command eval :: Message -> Net () eval = \case @@ -75,18 +75,18 @@ eval = \case m -> do io (putStrLn $ show m) return () -- ignore everything else - + -- Send a privmsg to the current chan + server privmsg :: String -> Net () privmsg s = write "PRIVMSG" (chan ++ " :" ++ s) - + -- Send a message out to the server we're currently connected to write :: String -> String -> Net () write s t = do h <- asks socket io $ hPrintf h "%s %s\r\n" s t io $ printf "> %s %s\n" s t - + -- Convenience. io :: IO a -> Net a io = liftIO -- cgit v1.2.3