mirror of
https://salsa.debian.org/mdosch/feed-to-muc.git
synced 2024-12-22 21:05:25 +01:00
Added processing of disco#info queries as I learned this is good style (thx jonasw).
This commit is contained in:
parent
14d58011cd
commit
1cf49e8121
1 changed files with 25 additions and 3 deletions
|
@ -174,22 +174,44 @@ func pingMUC(client *xmpp.Client, botJid string, Muc string, MucNick string) {
|
|||
|
||||
// Check for result IQ as long as there was no reply yet.
|
||||
for (time.Since(pingSent).Seconds() < 10.0) && (pingReceived == false) {
|
||||
// Receive Stanzas.
|
||||
// Receive stanzas. ToDo: Receive stanzas continiously without 30s delay.
|
||||
stanza, err := client.Recv()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Check IQs for type result and UID.
|
||||
// Check IQs for ping results and disco#info queries.
|
||||
switch v := stanza.(type) {
|
||||
case xmpp.IQ:
|
||||
if (v.Type == "error") && (v.ID == id) {
|
||||
log.Fatal("MUC not available.")
|
||||
}
|
||||
|
||||
if (v.Type == "result") && (v.ID == id) {
|
||||
pingReceived = true
|
||||
}
|
||||
break
|
||||
|
||||
if v.Type == "get" {
|
||||
// Reply to disco#info requests according to https://xmpp.org/extensions/xep-0030.html.
|
||||
if strings.Contains(string(v.Query),
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'/>") == true {
|
||||
_, err := client.RawInformation(client.JID(), v.From, v.ID,
|
||||
"result", "<query xmlns='http://jabber.org/protocol/disco#info'>"+
|
||||
"<identity category='client' type='bot' name='feedbot'/>"+
|
||||
"<feature var='http://jabber.org/protocol/disco#info'/></query>")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
// Send error replies for all other IQs.
|
||||
_, err := client.RawInformation(client.JID(), v.From, v.ID, "error",
|
||||
string(v.Query))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue