11var Botkit = require ( __dirname + '/CoreBot.js' ) ;
22const Stanza = require ( 'node-xmpp-client' ) . Stanza ;
3- const GroupManager = require ( './JabberGroupManager.js' )
3+ const GroupManager = require ( './JabberGroupManager.js' ) ;
44
55function 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 ++ ) {
0 commit comments