This commit is contained in:
Mickael Remond
2019-07-27 16:50:10 -07:00
parent e553028754
commit 6a5f2750f1
7 changed files with 516 additions and 13 deletions

View File

@@ -15,10 +15,8 @@ import (
var configFile = ""
var jid = ""
var password = ""
var receiverMUC = false
// FIXME: Remove global variables
var isMUCRecipient = false
var cmd = &cobra.Command{
Use: "sendxmpp <recipient,> [message]",
@@ -48,7 +46,7 @@ var cmd = &cobra.Command{
log.Info("client connected")
if receiverMUC {
if isMUCRecipient {
for _, muc := range receiver {
joinMUC(c, muc, "sendxmpp")
}
@@ -93,7 +91,7 @@ func init() {
cmd.Flags().StringP("addr", "", "", "host[:port]")
viper.BindPFlag("addr", cmd.Flags().Lookup("addr"))
cmd.Flags().BoolVarP(&receiverMUC, "muc", "m", false, "recipient is a muc (join it before sending messages)")
cmd.Flags().BoolVarP(&isMUCRecipient, "muc", "m", false, "recipient is a muc (join it before sending messages)")
}
// initConfig reads in config file and ENV variables if set.

View File

@@ -7,6 +7,7 @@ import (
"gosrc.io/xmpp/stanza"
)
// FIXME: Remove global variables
var mucsToLeave []string
func joinMUC(c xmpp.Sender, to, nick string) error {

View File

@@ -7,25 +7,27 @@ import (
"gosrc.io/xmpp/stanza"
)
func send(c xmpp.Sender, receiver []string, msgText string) {
func send(c xmpp.Sender, recipient []string, msgText string) {
msg := stanza.Message{
Attrs: stanza.Attrs{Type: stanza.MessageTypeChat},
Body: msgText,
}
if receiverMUC {
if isMUCRecipient {
msg.Type = stanza.MessageTypeGroupchat
}
for _, to := range receiver {
for _, to := range recipient {
msg.To = to
if err := c.Send(msg); err != nil {
log.WithFields(map[string]interface{}{
"muc": receiverMUC,
"muc": isMUCRecipient,
"to": to,
"text": msgText,
}).Errorf("error on send message: %s", err)
} else {
log.WithFields(map[string]interface{}{
"muc": receiverMUC,
"muc": isMUCRecipient,
"to": to,
"text": msgText,
}).Info("send message")