Merge pull request #34 from crackcomm/master

Status and status message options
This commit is contained in:
mattn 2014-10-06 12:25:55 +09:00
commit ac5d015101
3 changed files with 23 additions and 11 deletions

View File

@ -68,8 +68,8 @@ func main() {
os.Exit(0) os.Exit(0)
} }
xmpp.DefaultConfig = tls.Config { xmpp.DefaultConfig = tls.Config{
ServerName: "talk.google.com", ServerName: "talk.google.com",
InsecureSkipVerify: false, InsecureSkipVerify: false,
} }

View File

@ -14,6 +14,8 @@ import (
var server = flag.String("server", "talk.google.com:443", "server") var server = flag.String("server", "talk.google.com:443", "server")
var username = flag.String("username", "", "username") var username = flag.String("username", "", "username")
var password = flag.String("password", "", "password") var password = flag.String("password", "", "password")
var status = flag.String("status", "xa", "status")
var statusMessage = flag.String("status-msg", "I for one welcome our new codebot overlords.", "status message")
var notls = flag.Bool("notls", false, "No TLS") var notls = flag.Bool("notls", false, "No TLS")
var debug = flag.Bool("debug", false, "debug output") var debug = flag.Bool("debug", false, "debug output")
var session = flag.Bool("session", false, "use server session") var session = flag.Bool("session", false, "use server session")
@ -34,8 +36,8 @@ func main() {
} }
if !*notls { if !*notls {
xmpp.DefaultConfig = tls.Config { xmpp.DefaultConfig = tls.Config{
ServerName: serverName(*server), ServerName: serverName(*server),
InsecureSkipVerify: false, InsecureSkipVerify: false,
} }
} }
@ -43,11 +45,14 @@ func main() {
var talk *xmpp.Client var talk *xmpp.Client
var err error var err error
options := xmpp.Options{Host: *server, options := xmpp.Options{Host: *server,
User: *username, User: *username,
Password: *password, Password: *password,
NoTLS: *notls, NoTLS: *notls,
Debug: *debug, Debug: *debug,
Session: *session} Session: *session,
Status: *status,
StatusMessage: *statusMessage,
}
talk, err = options.NewClient() talk, err = options.NewClient()

11
xmpp.go
View File

@ -133,8 +133,14 @@ type Options struct {
// Debug output // Debug output
Debug bool Debug bool
//Use server sessions // Use server sessions
Session bool Session bool
// Presence Status
Status string
// Status message
StatusMessage string
} }
// NewClient establishes a new Client connection based on a set of Options. // NewClient establishes a new Client connection based on a set of Options.
@ -407,7 +413,8 @@ func (c *Client) init(o *Options) error {
} }
// We're connected and can now receive and send messages. // We're connected and can now receive and send messages.
fmt.Fprintf(c.conn, "<presence xml:lang='en'><show>xa</show><status>I for one welcome our new codebot overlords.</status></presence>") fmt.Fprintf(c.conn, "<presence xml:lang='en'><show>%s</show><status>%s</status></presence>", o.Status, o.StatusMessage)
return nil return nil
} }