{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RecordWildCards #-}
module Hirc.Format where

import Hirc.Types

formatMessage :: Message -> String
formatMessage Message{..} =
    maybe "" prefix m_prefix ++ m_command ++ params
  where
    prefix Prefix{..} =
      ":" ++ p_name ++ maybe "" user p_user ++ maybe "" host p_host ++ " "
    user x = "!" ++ x
    host x = "@" ++ x
    params = concatMap (" "++) (init m_params) ++ " :" ++ last m_params