Added flag '-i' which makes go-sendxmpp work with 'tail -f'.

http_upload
Martin Dosch 6 years ago
parent 4a2a409bd1
commit d5bd444cd1

@ -46,6 +46,7 @@ Usage: go-sendxmpp [-cdtx] [-f value] [--help] [-j value] [-p value] [-r value]
-d, --debug Show debugging info.
-f, --file=value Set configuration file. (Default: ~/.sendxmpprc)
--help Show help.
-i, --interactive Interactive mode (for use with e.g. 'tail -f').
-j, --jserver=value
XMPP server address.
-m, --message=value
@ -59,6 +60,7 @@ Usage: go-sendxmpp [-cdtx] [-f value] [--help] [-j value] [-p value] [-r value]
-u, --username=value
Username for XMPP account.
-x, --start-tls Use StartTLS.
```
### examples
@ -80,3 +82,9 @@ Send a message to two groupchats (`-c`) using a configuration file.
```bash
cat message.txt | ./go-sendxmpp -cf ./sendxmpp chat1@conference.example.com chat2@conference.example.com
```
Send file changes to two groupchats (`-c`) using a configuration file.
```bash
tail -f example.log | ./go-sendxmpp -cif ./sendxmpp chat1@conference.example.com chat2@conference.example.com
```

@ -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,6 +274,8 @@ func main() {
log.Fatal(err)
}
// 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)
@ -291,6 +294,7 @@ func main() {
}
}
}
}
// Send message to chatroom(s) if the flag is set.
if *flagChatroom {
@ -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.
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).
// 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 {
// 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)
}
}
}
} 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)
}

Loading…
Cancel
Save