Archived
1
0
Fork 0

Reorganized code and types, changed slightly the architecture.

This commit is contained in:
Julien Dessaux 2010-02-04 20:36:58 +01:00
parent 57f559f3a1
commit 884c6c9f2e
10 changed files with 272 additions and 164 deletions

33
Hsbot/Utils.hs Normal file
View file

@ -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