A very basic IRC bot in Haskell
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

24 lines
767 B

{-# LANGUAGE OverloadedStrings #-}
module Lib where
import qualified Data.Text as T
import qualified Data.Text.Encoding as TE
import Data.ByteString
import Types
user name desc = Message Nothing "USER" [" ", name, " * * :", desc]
nick name = Message Nothing "NICK" [" ", name]
join channel = Message Nothing "JOIN" [" ", channel]
privmsg channel message = Message Nothing "PRIVMSG" [" ", channel, " :", message]
pong message = Message Nothing "PONG" [":", message]
quit = Message Nothing "QUIT" []
buildCommand :: Message -> ByteString
buildCommand (Message Nothing cmd args) = TE.encodeUtf8 $ (cmd `T.append` (mconcat args)) `T.append` "\r\n"
buildCommand (Message (Just source) cmd args) = TE.encodeUtf8 $ (cmd `T.append` (mconcat args)) `T.append` "\r\n"