-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (31 loc) · 1.24 KB
/
index.js
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
const connection = require('./xmpp');
const { xml } = require('@xmpp/client');
const conArr = [];
const master = function () {
const con = new connection();
const id1 = con.init('username', 'password');
id1.on("stanza", async (stanza) => {
if (stanza.is('message') && stanza.getChild('body') && stanza.getChild('body').text()) {
if (stanza.attrs.type === 'chat') {
if (stanza.getChildText('body').trim().indexOf('join#') === 0 && stanza.getChildText('body').split('#').length === 4) {
conArr.push(new connection());
var d = stanza.getChildText('body').trim().toLowerCase().split('#');
try {
conArr[conArr.length - 1].init(d[1], d[2], d[3], 'quiz', stanza.attrs.from.split('@')[0]);
} catch (error) {
console.error(error)
}
}
}
} else if (stanza.attrs.type === 'subscribe') {
let message = xml(
"presence",
{
type: "subscribed", from: this.address,
to: stanza.attrs.from
});
id1.send(message);
}
});
}
master();