Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit 3b8bc38

Browse files
author
Ben Brown
committed
linter formatting changes
1 parent 35f7811 commit 3b8bc38

File tree

2 files changed

+54
-76
lines changed

2 files changed

+54
-76
lines changed

lib/JabberBot.js

Lines changed: 34 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var Botkit = require(__dirname + '/CoreBot.js');
22
const Stanza = require('node-xmpp-client').Stanza;
3-
const GroupManager = require('./JabberGroupManager.js')
3+
const GroupManager = require('./JabberGroupManager.js');
44

55
function JabberBot(configuration) {
66
// Create a core botkit bot
@@ -9,15 +9,15 @@ function JabberBot(configuration) {
99

1010
function toUTCDateTimeString(date) {
1111
var yyyy = date.getUTCFullYear();
12-
var mm = date.getUTCMonth() < 9 ? "0" + (date.getUTCMonth() + 1) : (date.getUTCMonth() + 1); // getMonth() is zero-based
13-
var dd = date.getUTCDate() < 10 ? "0" + date.getUTCDate() : date.getUTCDate();
14-
var hh = date.getUTCHours() < 10 ? "0" + date.getUTCHours() : date.getUTCHours();
15-
var min = date.getUTCMinutes() < 10 ? "0" + date.getUTCMinutes() : date.getUTCMinutes();
16-
var ss = date.getUTCSeconds() < 10 ? "0" + date.getUTCSeconds() : date.getUTCSeconds();
17-
return "".concat(yyyy).concat('-').concat(mm).concat('-').concat(dd).concat('T').concat(hh).concat(':').concat(min).concat(':').concat(ss);
12+
var mm = date.getUTCMonth() < 9 ? '0' + (date.getUTCMonth() + 1) : (date.getUTCMonth() + 1); // getMonth() is zero-based
13+
var dd = date.getUTCDate() < 10 ? '0' + date.getUTCDate() : date.getUTCDate();
14+
var hh = date.getUTCHours() < 10 ? '0' + date.getUTCHours() : date.getUTCHours();
15+
var min = date.getUTCMinutes() < 10 ? '0' + date.getUTCMinutes() : date.getUTCMinutes();
16+
var ss = date.getUTCSeconds() < 10 ? '0' + date.getUTCSeconds() : date.getUTCSeconds();
17+
return ''.concat(yyyy).concat('-').concat(mm).concat('-').concat(dd).concat('T').concat(hh).concat(':').concat(min).concat(':').concat(ss);
1818
};
1919

20-
controller.middleware.format.use(function (bot, message, platform_message, next) {
20+
controller.middleware.format.use(function(bot, message, platform_message, next) {
2121
// clone the incoming message
2222
for (var k in message) {
2323
platform_message[k] = message[k];
@@ -27,7 +27,7 @@ function JabberBot(configuration) {
2727

2828
// customize the bot definition, which will be used when new connections
2929
// spawn!
30-
controller.defineBot(function (botkit, config) {
30+
controller.defineBot(function(botkit, config) {
3131
var xmpp = require('simple-xmpp');
3232

3333
var bot = {
@@ -46,35 +46,35 @@ function JabberBot(configuration) {
4646
xmpp.conn.send(roster_stanza);
4747
}
4848

49-
xmpp.on('online', function (data) {
49+
xmpp.on('online', function(data) {
5050
console.log(toUTCDateTimeString(new Date()) + ':Connected with JID: ' + data.jid.user);
5151
console.log('Yes, I\'m connected!');
5252
request_roster();
5353

5454
// send whitespace to keep the connection alive
5555
// and prevent timeouts
56-
setInterval(function () {
56+
setInterval(function() {
5757
xmpp.conn.send(' ');
5858
}, 1800000);
5959
});
6060

61-
xmpp.on('close', function () {
61+
xmpp.on('close', function() {
6262
console.log(toUTCDateTimeString(new Date()) + ':connection has been closed!');
6363
process.exit();
6464
});
6565

66-
xmpp.on('error', function (err) {
67-
console.log(toUTCDateTimeString(new Date()) + ":" + err);
66+
xmpp.on('error', function(err) {
67+
console.log(toUTCDateTimeString(new Date()) + ':' + err);
6868
process.exit();
6969
});
7070

71-
xmpp.on('subscribe', function (from) {
71+
xmpp.on('subscribe', function(from) {
7272
xmpp.acceptSubscription(from);
7373
console.log(toUTCDateTimeString(new Date()) + ':accept subscribe from:' + from);
7474
controller.trigger('subscribe', [bot, from]);
7575
});
7676

77-
xmpp.on('unsubscribe', function (from) {
77+
xmpp.on('unsubscribe', function(from) {
7878
console.log(toUTCDateTimeString(new Date()) + ':accept unsubscribe from:' + from);
7979
xmpp.acceptUnsubscription(from);
8080
});
@@ -83,11 +83,9 @@ function JabberBot(configuration) {
8383
return jid === bot.client_jid;
8484
}
8585

86-
function IsBotMentioned(message)
87-
{
86+
function IsBotMentioned(message) {
8887
let mention_jids = extractMentionJids(message);
89-
if (mention_jids.find(findBotJid))
90-
{
88+
if (mention_jids.find(findBotJid)) {
9189
return true;
9290
}
9391
return false;
@@ -110,37 +108,29 @@ function JabberBot(configuration) {
110108
return mention_jids;
111109
}
112110

113-
controller.on('message_received', function (bot, message) {
114-
if (message.group == false)
115-
{
111+
controller.on('message_received', function(bot, message) {
112+
if (message.group == false) {
116113
if (message.user === bot.client_jid) {
117114
controller.trigger('self_message', [bot, message]);
118115
return false;
119116
} else {
120117
controller.trigger('direct_message', [bot, message]);
121118
return false;
122119
}
123-
}
124-
else
125-
{
126-
if (IsBotMentioned(message))
127-
{
128-
if (bot.client_jid == message.from_jid)
129-
{
120+
} else {
121+
if (IsBotMentioned(message)) {
122+
if (bot.client_jid == message.from_jid) {
130123
controller.trigger('self_message', [bot, message]);
131-
}
132-
else
133-
{
124+
} else {
134125
controller.trigger('direct_mention', [bot, message]);
135126
}
136127
return false;
137128
}
138129
}
139130
});
140131

141-
xmpp.on('stanza', function (stanza) {
142-
if (stanza.is('message'))
143-
{
132+
xmpp.on('stanza', function(stanza) {
133+
if (stanza.is('message')) {
144134
if (stanza.attrs.type == 'chat') {
145135
var body = stanza.getChild('body');
146136
if (body) {
@@ -156,9 +146,7 @@ function JabberBot(configuration) {
156146
xmpp_message.channel = 'chat',
157147
controller.ingest(bot, xmpp_message, null);
158148
}
159-
}
160-
else if (stanza.attrs.type == 'groupchat')
161-
{
149+
} else if (stanza.attrs.type == 'groupchat') {
162150
var body = stanza.getChild('body');
163151
if (body) {
164152
let message = body.getText();
@@ -188,21 +176,18 @@ function JabberBot(configuration) {
188176
}
189177
});
190178

191-
bot.startConversation = function (message, cb) {
179+
bot.startConversation = function(message, cb) {
192180
botkit.startConversation(this, message, cb);
193181
};
194182

195-
bot.createConversation = function (message, cb) {
183+
bot.createConversation = function(message, cb) {
196184
botkit.createConversation(this, message, cb);
197185
};
198186

199-
bot.send = function (message, cb) {
200-
if (message.stanza)
201-
{
187+
bot.send = function(message, cb) {
188+
if (message.stanza) {
202189
xmpp.conn.send(message.stanza);
203-
}
204-
else
205-
{
190+
} else {
206191
xmpp.send(message.user, message.text, message.group);
207192
}
208193

@@ -211,7 +196,7 @@ function JabberBot(configuration) {
211196
}
212197
};
213198

214-
bot.reply = function (src, resp, cb) {
199+
bot.reply = function(src, resp, cb) {
215200
var msg = {};
216201

217202
if (typeof (resp) == 'string') {
@@ -226,7 +211,7 @@ function JabberBot(configuration) {
226211
bot.say(msg, cb);
227212
};
228213

229-
bot.findConversation = function (message, cb) {
214+
bot.findConversation = function(message, cb) {
230215
botkit.debug('CUSTOM FIND CONVO', message.user, message.channel);
231216
for (var t = 0; t < botkit.tasks.length; t++) {
232217
for (var c = 0; c < botkit.tasks[t].convos.length; c++) {

lib/JabberGroupManager.js

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const caps = require('node-xmpp-caps');
1+
const caps = require('node-xmpp-caps');
22
const Stanza = require('node-xmpp-client').Stanza;
33
const MD5 = require('md5');
44

@@ -14,20 +14,18 @@ function JabberGroupManager(config, xmpp, bot, controller) {
1414
const bot_caps_node_addr = 'http://protocols.cisco.com/jabber-bot';
1515
var bot_caps = createCapsNode(bot_caps_node_addr);
1616

17-
xmpp.on('online', function (data) {
17+
xmpp.on('online', function(data) {
1818
publishCapabilities();
1919
joinPresetRooms();
2020
});
2121

22-
xmpp.on('stanza', function (stanza) {
22+
xmpp.on('stanza', function(stanza) {
2323
if (stanza.is('iq')) {
2424
handleCapabilityIq(stanza);
2525
handleRoomDiscoQueryIq(stanza);
26-
}
27-
else if (stanza.is('message')) {
26+
} else if (stanza.is('message')) {
2827
handleInviteMessage(stanza);
29-
}
30-
else if (stanza.is('presence')) {
28+
} else if (stanza.is('presence')) {
3129
handleMembershipPresence(stanza);
3230
}
3331
});
@@ -60,11 +58,11 @@ function JabberGroupManager(config, xmpp, bot, controller) {
6058
}
6159
}
6260

63-
controller.storage.teams.all(function (err, rooms) {
61+
controller.storage.teams.all(function(err, rooms) {
6462
for (let i = 0; i < rooms.length; i++) {
6563
let room = rooms[i];
6664
if (room.type === 'joined_persist_rooms') {
67-
let room_id = room.room_id + "/" + bot.client_jid;
65+
let room_id = room.room_id + '/' + bot.client_jid;
6866
let password = room.password;
6967
if (!joinedRoomsId.has(getBareRoomId(room_id))) {
7068
joinedRoomsPasswordMap.set(getBareRoomId(room_id), password);
@@ -117,15 +115,13 @@ function JabberGroupManager(config, xmpp, bot, controller) {
117115
return;
118116

119117
let features = query.getChildren('feature');
120-
for (let i = 0; i < features.length; i++)
121-
{
118+
for (let i = 0; i < features.length; i++) {
122119
let feature = features[i];
123120
if (feature.attrs.var === 'persistent' ||
124-
feature.attrs.var === 'muc_persistent')
125-
{
121+
feature.attrs.var === 'muc_persistent') {
126122
joinedPersistRoomsId.add(getBareRoomId(room_id));
127123
let password = joinedRoomsPasswordMap.get(getBareRoomId(room_id));
128-
saveJoinPersistRooms(getBareRoomId(room_id), password)
124+
saveJoinPersistRooms(getBareRoomId(room_id), password);
129125
return;
130126
}
131127
}
@@ -144,7 +140,7 @@ function JabberGroupManager(config, xmpp, bot, controller) {
144140
let password_node = muc_message.getChild('password');
145141
if (password_node)
146142
password = password_node.getText();
147-
let room_id = stanza.attrs.from + "/" + bot.client_jid;
143+
let room_id = stanza.attrs.from + '/' + bot.client_jid;
148144

149145
if (!joinedRoomsId.has(getBareRoomId(room_id))) {
150146
joinedRoomsPasswordMap.set(getBareRoomId(room_id), password);
@@ -179,8 +175,7 @@ function JabberGroupManager(config, xmpp, bot, controller) {
179175
saveLeavePersistRooms(getBareRoomId(room_id));
180176
}
181177
}
182-
}
183-
else if (item.attrs.role === 'participant') {
178+
} else if (item.attrs.role === 'participant') {
184179
joinedRoomsId.add(getBareRoomId(room_id));
185180

186181
sendRoomDiscoQueryIq(room_id, jid);
@@ -193,37 +188,35 @@ function JabberGroupManager(config, xmpp, bot, controller) {
193188
let disco_id = 'room_disco1';
194189
let node = to.split('@')[1];
195190
let iq_stanza = new Stanza('iq', { 'id': disco_id, 'type': 'get', 'to': to, 'from': from });
196-
iq_stanza.c('query', { xmlns: 'http://jabber.org/protocol/disco#info', 'node' : node});
197-
xmpp.conn.send(iq_stanza);
191+
iq_stanza.c('query', { xmlns: 'http://jabber.org/protocol/disco#info', 'node': node});
192+
xmpp.conn.send(iq_stanza);
198193
};
199194

200195
function saveJoinPersistRooms(room_id, room_password) {
201196
let id = MD5(room_id);
202-
controller.storage.teams.get(id, function (err, room) {
203-
if (!room)
204-
{
197+
controller.storage.teams.get(id, function(err, room) {
198+
if (!room) {
205199
room = {
206200
id: id,
207201
};
208202
}
209203
room.room_id = room_id;
210204
room.password = room_password;
211205
room.type = 'joined_persist_rooms';
212-
controller.storage.teams.save(room, function (err, room) {
206+
controller.storage.teams.save(room, function(err, room) {
213207
});
214208
});
215209
}
216210

217211
function saveLeavePersistRooms(room_id) {
218212
let id = MD5(room_id);
219-
controller.storage.teams.delete(id, function (err, room) {
213+
controller.storage.teams.delete(id, function(err, room) {
220214
});
221215
}
222216

223-
function getBareRoomId(room_id)
224-
{
217+
function getBareRoomId(room_id) {
225218
return room_id.split('/')[0];
226219
}
227220
}
228221

229-
module.exports = JabberGroupManager;
222+
module.exports = JabberGroupManager;

0 commit comments

Comments
 (0)