summaryrefslogtreecommitdiffstats
path: root/Hirc/Format.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Hirc/Format.hs')
-rw-r--r--Hirc/Format.hs15
1 files changed, 15 insertions, 0 deletions
diff --git a/Hirc/Format.hs b/Hirc/Format.hs
new file mode 100644
index 0000000..bf6546a
--- /dev/null
+++ b/Hirc/Format.hs
@@ -0,0 +1,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