mkChatMsg JID JID String String Stanza mkChatMsg from to threadId msg

 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
mkChatMsg :: JID -> JID -> String -> String -> Stanza
mkChatMsg from to threadId msg = Message from to threadId Chat "" msg "" []
isChat :: Stanza -> Bool
isChat (Message _ _ _ Chat _ _ _ _) = True
isChat _ = False
entities :: String -> String
entities = concat . map entities'
entities' :: Char -> String
entities' '&' = "&"
entities' '<' = "&lt;"
entities' '>' = "&gt;"
entities' '"' = "&quot;"
entities' '\'' = "&apos;"
entities' c = c : []
action to from post = mkChatMsg to from "" $ "echo " ++ post
run = do
msg <- readChanS
when (isChat msg) $ do
let textMessage = mBody msg
from = mFrom msg
to = mTo msg
threadId = mId msg
action to from $ entities textMessage
run
main =
do
withNewStream $
do h <- liftIO $ connectViaTcp server 5222
(jid,_) <- initiateStream h server user pass resource
outStanza $ presAvailable "On"
runThreaded $ do
withNewThread $ iqVersion
withNewThread $ run
return ()