packages feed

hsendxmpp 0.1.1.0 → 0.1.2.0

raw patch · 2 files changed

+25/−4 lines, 2 filesdep +pontarius-xmpp-extras

Dependencies added: pontarius-xmpp-extras

Files

Main.hs view
@@ -2,12 +2,15 @@  module Main where +import Control.Monad import Data.Maybe import qualified Data.String.Class as S import Network.Xmpp import Network.Xmpp.Internal hiding (priority, status)+import Network.Xmpp.Extras.MUC import System.Console.GetOpt import System.Environment+import System.Log.Logger   passWordEnvVar = "HSENDXMPP_PASSWORD"@@ -16,12 +19,18 @@ 	{ oUserName :: String 	, oPassWord :: String 	, oServer :: String+	, oResource :: String+	, oMessageType :: MessageType+	, oVerbose :: Bool 	} deriving (Eq, Show)  defaultOptions = Options 	{ oUserName = "" 	, oPassWord = "" 	, oServer = ""+	, oResource = "hsendxmpp"+	, oMessageType = Chat+	, oVerbose = False 	}  options :: [OptDescr (Options -> Options)]@@ -29,6 +38,9 @@ 	[ Option ['u']	["username"]	(ReqArg	(\str o -> o { oUserName = str }) "user")	"Use this username to authenticate to the server" 	, Option ['p']	["password"]	(ReqArg	(\str o -> o { oPassWord = str }) "password") $	"Use this password to authenticate to the server.\nThe password can also be provided via " ++ passWordEnvVar ++ " environment variable to avoid it leaking into process lists, and it will override the CLI option contents." 	, Option ['j']	["jserver"]	(ReqArg	(\str o -> o { oServer = str }) "server")	"Connect to this server"+	, Option ['r']	["resource"]	(ReqArg	(\str o -> o { oResource = str }) "res")	"Use resource res for the sender [default: 'hsendxmpp']"+	, Option ['c']	["chatroom"]	(NoArg	(\o -> o { oMessageType = GroupChat }))		"Send the message to a chatroom (MUC)"+	, Option ['v']	["verbose"]	(NoArg	(\o -> o { oVerbose = True }))			"Be verbose on what's happening on the wire" 	]  getOpts :: IO (Options, [String])@@ -42,12 +54,20 @@ main :: IO () main = do 	(opts, recipients) <- getOpts+	when (oVerbose opts) $ updateGlobalLogger "Pontarius.Xmpp" $ setLevel DEBUG 	text <- getContents 	envPassWord <- lookupEnv passWordEnvVar 	let justEnvPassWord = fromMaybe "" envPassWord 	let passWord = if null justEnvPassWord then oPassWord opts else justEnvPassWord -	eSess <- session (oServer opts) (simpleAuth (S.toText $ oUserName opts) (S.toText passWord)) def+	let authData = Just (fst $ fromJust (simpleAuth (S.toText $ oUserName opts) (S.toText passWord)), if null $ oResource opts then Nothing else Just $ S.toText $ oResource opts) :: AuthData+	eSess <- session (oServer opts) authData def 	let sess = either (error . show) id $ eSess 	sendPresence presenceOnline sess-	mapM_ (\tjid -> sendMessage ((simpleIM (parseJid tjid) $ S.toText text) { messageType = Chat }) sess >> pure ()) recipients+	mapM_ (\tjid -> do+		let parsedJid = parseJid tjid+		when (oMessageType opts == GroupChat) $ do+			let (roomName, roomServer, _) = jidToTexts parsedJid+			let roomJid = fromJust $ jidFromTexts roomName roomServer $ Just $ S.toText $ oResource opts+			joinMUC roomJid Nothing sess >> pure ()+		sendMessage ((simpleIM parsedJid $ S.toText text) { messageType = oMessageType opts }) sess >> pure ()) recipients
hsendxmpp.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                hsendxmpp-version:             0.1.1.0+version:             0.1.2.0 synopsis:            sendxmpp clone, sending XMPP messages via CLI -- description: license:             OtherLicense@@ -21,7 +21,7 @@ Source-repository this   type:              git   location:          https://github.com/l29ah/hsendxmpp.git-  tag:               0.1.1.0+  tag:               0.1.2.0  executable hsendxmpp   main-is:             Main.hs@@ -30,6 +30,7 @@   -- other-extensions:   build-depends:       base >=4.12 && <4.13,                        pontarius-xmpp >= 0.4.5 && < 0.6,+                       pontarius-xmpp-extras >= 0.1.0.1 && < 0.2,                        hslogger >= 1.2.8 && < 1.4,                        string-class >= 0.1.7.0 && < 0.2   -- hs-source-dirs: