You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.5 KiB
55 lines
1.5 KiB
|
14 years ago
|
{-# LANGUAGE PackageImports, OverloadedStrings #-}
|
||
|
14 years ago
|
module Example where
|
||
|
14 years ago
|
|
||
|
|
import Data.Text as T
|
||
|
|
|
||
|
|
import Network.XMPP
|
||
|
|
import Control.Concurrent
|
||
|
|
import Control.Concurrent.STM
|
||
|
|
import Control.Monad
|
||
|
|
import Control.Monad.IO.Class
|
||
|
|
|
||
|
|
philonous :: JID
|
||
|
|
philonous = read "uart14@species64739.dyndns.org"
|
||
|
|
|
||
|
|
attXmpp :: STM a -> XMPPThread a
|
||
|
|
attXmpp = liftIO . atomically
|
||
|
|
|
||
|
|
autoAccept :: XMPPThread ()
|
||
|
|
autoAccept = forever $ do
|
||
|
|
st <- pullPresence
|
||
|
|
case st of
|
||
|
14 years ago
|
Presence from _ idq (Just Subscribe) _ _ _ _ ->
|
||
|
14 years ago
|
sendS . SPresence $
|
||
|
14 years ago
|
Presence Nothing from idq (Just Subscribed) Nothing Nothing Nothing []
|
||
|
14 years ago
|
_ -> return ()
|
||
|
|
|
||
|
|
mirror :: XMPPThread ()
|
||
|
|
mirror = forever $ do
|
||
|
|
st <- pullMessage
|
||
|
|
case st of
|
||
|
14 years ago
|
Message (Just from) _ idq tp subject (Just bd) thr _ ->
|
||
|
14 years ago
|
sendS . SMessage $
|
||
|
14 years ago
|
Message Nothing from idq tp subject
|
||
|
14 years ago
|
(Just $ "you wrote: " `T.append` bd) thr []
|
||
|
|
_ -> return ()
|
||
|
|
|
||
|
|
|
||
|
|
main :: IO ()
|
||
|
|
main = do
|
||
|
14 years ago
|
sessionConnect "localhost" "species64739.dyndns.org" "bot" Nothing $ do
|
||
|
|
singleThreaded $ xmppStartTLS exampleParams
|
||
|
|
singleThreaded $ xmppSASL "pwd"
|
||
|
|
singleThreaded $ xmppBind (Just "botsi")
|
||
|
|
singleThreaded $ xmppSession
|
||
|
14 years ago
|
forkXMPP autoAccept
|
||
|
|
forkXMPP mirror
|
||
|
14 years ago
|
sendS . SPresence $ Presence Nothing Nothing Nothing Nothing
|
||
|
|
(Just Available) Nothing Nothing []
|
||
|
|
sendS . SMessage $ Message Nothing philonous Nothing Nothing Nothing
|
||
|
|
(Just "bla") Nothing []
|
||
|
14 years ago
|
liftIO . forever $ threadDelay 1000000
|
||
|
14 years ago
|
return ()
|
||
|
|
return ()
|
||
|
|
|