summaryrefslogtreecommitdiffstats
path: root/Hirc/Format.hs
blob: bf6546a8bb955a77c3544b8c4646b83ca0e1b852 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{-# 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