package main import ( "fmt" "gosrc.io/xmpp" "gosrc.io/xmpp/stanza" ) // This file has small functions that can be used to do XMPP stuff without writing tons of boilerplate // Basic message sender. Anything more complex should be written by hand func sendMessage(c xmpp.Sender, sendTo string, msgType stanza.StanzaType, body string, subject string, thread string) error { m := stanza.Message{ Attrs: stanza.Attrs{ To: sendTo, Type: msgType, }, Body: body, Subject: subject, Thread: thread, } err := c.Send(m) if err != nil { return err } return nil } // Joins a MUC func joinMuc(c xmpp.Sender, jid string, muc string, nick string) error { addr := muc + "/" + nick fmt.Println(addr) joinPresence := stanza.Presence{ Attrs: stanza.Attrs{ From: jid, To: addr, }, Extensions: []stanza.PresExtension{ &stanza.MucPresence{}, }, } err := client.Send(joinPresence) if err != nil { return err } return nil } // jid MustParse but using gosrc's instead of mellium // This function will panic if its an invalid JID func JidMustParse(s string) (*stanza.Jid) { j, err := stanza.NewJid(s) if err != nil { panic(err) } return j }