blob: b84b028d52f92facbc9793f1c85a6cb5b3e35eef (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
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
|