diff options
author | Julien Dessaux | 2009-08-06 00:11:14 +0200 |
---|---|---|
committer | Julien Dessaux | 2009-08-06 00:11:14 +0200 |
commit | b9c8e4d404c444d57fe7320c25ba0654d9c5193c (patch) | |
tree | 98796cc7cf2b74b51feaf6214c5b1ae8c49688d8 /Hsbot/IRC.hs | |
parent | renamed "Server" algebraic data type to "IrcServer" (diff) | |
download | hsbot-b9c8e4d404c444d57fe7320c25ba0654d9c5193c.tar.gz hsbot-b9c8e4d404c444d57fe7320c25ba0654d9c5193c.tar.bz2 hsbot-b9c8e4d404c444d57fe7320c25ba0654d9c5193c.zip |
Added IRC connection and initialisation stuff.
Diffstat (limited to 'Hsbot/IRC.hs')
-rw-r--r-- | Hsbot/IRC.hs | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/Hsbot/IRC.hs b/Hsbot/IRC.hs index 6ff1013..ead044c 100644 --- a/Hsbot/IRC.hs +++ b/Hsbot/IRC.hs @@ -1,11 +1,15 @@ module Hsbot.IRC ( IrcInput(..) , IrcOutput(..) + , connectServer + , initServer , parseIrcMsg )where -import qualified Network.IRC as Irc -import System.IO (Handle) +import Control.Monad +import Network +import qualified Network.IRC as IRC +import System.IO import Hsbot.Core @@ -32,3 +36,22 @@ data IrcOutput = Str String -- a regular string parseIrcMsg :: String -> IrcInput parseIrcMsg _ = Err "Parsing not yet implemented" +-- | Connects to a server +connectServer :: IrcServer -> IO (IrcServer, Handle) +connectServer server = do + let name = address server + port_number = port server + handle <- connectTo name (PortNumber $ fromIntegral port_number) + hSetBuffering handle NoBuffering + return (server, handle) + +-- | Setup a newly connected server by sending nick and join stuff +initServer :: (IrcServer, Handle) -> IO () +initServer (server, handle) = do + sendstr handle (IRC.encode $ IRC.nick (nickname server)) + sendstr handle (IRC.encode $ IRC.user (nickname server) "0" "*" (realname server)) + when (not . null $ (password server)) $ do + sendstr handle (IRC.encode $ IRC.privmsg "nickserv" ("identify" ++ (password server))) + mapM_ (sendstr handle . IRC.encode . IRC.joinChan) (channels server) + return () + |