forked from xperimental/xmppsend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (49 loc) · 1.13 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"flag"
"log"
xmpp "github.com/mattn/go-xmpp"
)
var user string
var password string
var recipient string
var message string
func init() {
flag.StringVar(&user, "user", "", "JID of sender.")
flag.StringVar(&password, "password", "", "Password of sender.")
flag.StringVar(&recipient, "to", "", "JID of recipient.")
flag.StringVar(&message, "msg", "", "Message to send.")
}
func main() {
flag.Parse()
if len(user) == 0 {
log.Println("user is required")
flag.Usage()
return
}
if len(password) == 0 {
log.Println("password is required")
flag.Usage()
return
}
if len(recipient) == 0 {
log.Println("recipient is required")
flag.Usage()
return
}
if len(message) == 0 {
log.Println("message is required")
flag.Usage()
return
}
log.Printf("Logging in with %s...", user)
cl, err := xmpp.NewClientNoTLS("", user, password, false)
if err != nil {
log.Fatalf("Error connecting: %s", err)
return
}
defer cl.Close()
log.Printf("Sending message to %s...", recipient)
cl.Send(xmpp.Chat{Remote: recipient, Type: "chat", Text: message})
log.Printf("Closing connection (30s timeout).")
}