|
|
|
@ -189,6 +189,7 @@ func main() {
|
|
|
|
|
"When sending to a chatroom this is used as 'alias'. (Default: go-sendxmpp)")
|
|
|
|
|
flagFile := getopt.StringLong("file", 'f', "", "Set configuration file. (Default: ~/.sendxmpprc)")
|
|
|
|
|
flagMessageFile := getopt.StringLong("message", 'm', "", "Set file including the message.")
|
|
|
|
|
flagInteractive := getopt.BoolLong("interactive", 'i', "Interactive mode (for use with e.g. 'tail -f').")
|
|
|
|
|
|
|
|
|
|
// Parse command line flags.
|
|
|
|
|
getopt.Parse()
|
|
|
|
@ -273,21 +274,24 @@ func main() {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if message == "" {
|
|
|
|
|
// Skip reading message if '-i' or '--interactive' is set to work with e.g. 'tail -f'.
|
|
|
|
|
if *flagInteractive == false {
|
|
|
|
|
if message == "" {
|
|
|
|
|
|
|
|
|
|
scanner := bufio.NewScanner(os.Stdin)
|
|
|
|
|
for scanner.Scan() {
|
|
|
|
|
scanner := bufio.NewScanner(os.Stdin)
|
|
|
|
|
for scanner.Scan() {
|
|
|
|
|
|
|
|
|
|
if message == "" {
|
|
|
|
|
message = scanner.Text()
|
|
|
|
|
} else {
|
|
|
|
|
message = message + "\n" + scanner.Text()
|
|
|
|
|
if message == "" {
|
|
|
|
|
message = scanner.Text()
|
|
|
|
|
} else {
|
|
|
|
|
message = message + "\n" + scanner.Text()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := scanner.Err(); err != nil {
|
|
|
|
|
if err != io.EOF {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
if err := scanner.Err(); err != nil {
|
|
|
|
|
if err != io.EOF {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -307,13 +311,32 @@ func main() {
|
|
|
|
|
if mucStatus > 300 {
|
|
|
|
|
log.Fatal("Couldn't join MUC. Status:", mucStatus)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Send in endless loop (for usage with e.g. "tail -f").
|
|
|
|
|
if *flagInteractive == true {
|
|
|
|
|
for {
|
|
|
|
|
scanner := bufio.NewScanner(os.Stdin)
|
|
|
|
|
scanner.Scan()
|
|
|
|
|
message = scanner.Text()
|
|
|
|
|
for _, recipient := range recipients {
|
|
|
|
|
_, err = client.Send(xmpp.Chat{Remote: recipient, Type: "groupchat", Text: message})
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Send the message.
|
|
|
|
|
_, err = client.Send(xmpp.Chat{Remote: recipient, Type: "groupchat", Text: message})
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
for _, recipient := range recipients {
|
|
|
|
|
_, err = client.Send(xmpp.Chat{Remote: recipient, Type: "groupchat", Text: message})
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, recipient := range recipients {
|
|
|
|
|
// After sending the message, leave the Muc
|
|
|
|
|
_, err = client.LeaveMUC(recipient)
|
|
|
|
|
if err != nil {
|
|
|
|
@ -321,15 +344,30 @@ func main() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// If the chatroom flag is not set, send message to contact(s).
|
|
|
|
|
|
|
|
|
|
for _, recipient := range recipients {
|
|
|
|
|
|
|
|
|
|
// If the chatroom flag is not set, send message to contact(s).
|
|
|
|
|
_, err = client.Send(xmpp.Chat{Remote: recipient, Type: "chat", Text: message})
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
// Send in endless loop (for usage with e.g. "tail -f").
|
|
|
|
|
if *flagInteractive == true {
|
|
|
|
|
for {
|
|
|
|
|
scanner := bufio.NewScanner(os.Stdin)
|
|
|
|
|
scanner.Scan()
|
|
|
|
|
message = scanner.Text()
|
|
|
|
|
for _, recipient := range recipients {
|
|
|
|
|
_, err = client.Send(xmpp.Chat{Remote: recipient, Type: "chat", Text: message})
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for _, recipient := range recipients {
|
|
|
|
|
_, err = client.Send(xmpp.Chat{Remote: recipient, Type: "chat", Text: message})
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
|
}
|
|
|
|
|