initial commit
This commit is contained in:
49
xmpp-helpers.go
Normal file
49
xmpp-helpers.go
Normal file
@@ -0,0 +1,49 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user