summaryrefslogtreecommitdiff
path: root/Hsbot/Utils.hs
diff options
context:
space:
mode:
authorJulien Dessaux2010-02-04 20:36:58 +0100
committerJulien Dessaux2010-02-04 20:36:58 +0100
commit884c6c9f2e3a03d6666c8dd6c6d6b6513db88ad5 (patch)
treec5941649d7fe1ac23d5ee673c240efb8508b3db2 /Hsbot/Utils.hs
parentRewrote the whole architecture. (diff)
downloadhsbot-884c6c9f2e3a03d6666c8dd6c6d6b6513db88ad5.tar.gz
hsbot-884c6c9f2e3a03d6666c8dd6c6d6b6513db88ad5.tar.bz2
hsbot-884c6c9f2e3a03d6666c8dd6c6d6b6513db88ad5.zip
Reorganized code and types, changed slightly the architecture.
Diffstat (limited to 'Hsbot/Utils.hs')
-rw-r--r--Hsbot/Utils.hs33
1 files changed, 33 insertions, 0 deletions
diff --git a/Hsbot/Utils.hs b/Hsbot/Utils.hs
new file mode 100644
index 0000000..640d16f
--- /dev/null
+++ b/Hsbot/Utils.hs
@@ -0,0 +1,33 @@
+module Hsbot.Utils
+ ( inColor
+ , sendstr
+ , trace
+ , traceM
+ ) where
+
+import Control.Monad.State
+import Data.List
+import System.IO
+
+import Hsbot.Types
+
+-- |Wrap a string with ANSI escape sequences.
+inColor :: String -> [Int] -> String
+inColor str vals = "\ESC[" ++ valstr ++ "m" ++ str ++ "\ESC[0m"
+ where valstr = concat $ intersperse ";" $ map show vals
+
+-- | Sends a string over handle
+sendstr :: String -> IrcBot ()
+sendstr str = do
+ handle <- gets botHandle
+ traceM $ inColor ("--> " ++ str) [33]
+ liftIO $ hPutStr handle (str ++ "\r\n")
+
+-- | Log a message string
+trace :: String -> IO ()
+trace msg = putStrLn msg
+
+-- | Log a message string
+traceM :: String -> IrcBot ()
+traceM msg = liftIO $ putStrLn msg
+