Archived
1
0
Fork 0
This repository has been archived on 2025-03-10. You can view files and clone it, but cannot push or open issues or pull requests.
hsbot/Hsbot/Utils.hs
Julien Dessaux fd8d5faf5f Began a complete rewrite of command and plugin management.
Wrote a command routing statement, added an IrcPlugin monad.
2010-02-04 21:05:37 +01:00

42 lines
909 B
Haskell

module Hsbot.Utils
( error
, errorM
, 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 $ trace msg
-- | Logs an error message
error :: String -> IO ()
error msg = trace $ inColor msg [31]
errorM :: String -> a ()
error msg = liftIO $ error msg