@@ -116,7 +116,8 @@ class ISawYou {
116116 return a . username > b . username ? 1 : - 1 ;
117117 }
118118 return b . points - a . points ;
119- } ) . slice ( 0 , k ) ;
119+ } )
120+ . slice ( 0 , k ) ;
120121 }
121122
122123 // returns true iff the message is a picture message
@@ -141,12 +142,8 @@ module.exports = (robot) => {
141142 // only listen to messages in the #i-saw-you channel
142143 if ( robotConfig ( 'room' ) === msg . message . room ) {
143144 const username = msg . message . user . name ;
144- const matchesInc = msg . message . text . match (
145- / ^ @ ( [ - \w . \\ ^ | { } ` [ \] ] + ) \+ \+ $ / ,
146- ) ;
147- const matchesDec = msg . message . text . match (
148- / ^ @ ( [ - \w . \\ ^ | { } ` [ \] ] + ) - - $ / ,
149- ) ;
145+ const matchesInc = msg . message . text . match ( / ^ @ ( [ - \w . \\ ^ | { } ` [ \] ] + ) \+ \+ $ / ) ;
146+ const matchesDec = msg . message . text . match ( / ^ @ ( [ - \w . \\ ^ | { } ` [ \] ] + ) - - $ / ) ;
150147 if ( matchesInc && matchesInc . length === 2 ) {
151148 iSawYou . increment ( matchesInc [ 1 ] ) ;
152149 reportCount ( msg , matchesInc [ 1 ] ) ;
@@ -163,49 +160,37 @@ module.exports = (robot) => {
163160 } ) ;
164161
165162 // respond to i-saw-you increments
166- robot . respond (
167- / i s a w y o u @ ? ( [ - \w . \\ ^ | { } ` [ \] ] + ) \+ \+ $ / ,
168- ( msg ) => {
169- const username = msg . match [ 1 ] ;
170- iSawYou . increment ( username ) ;
171- reportCount ( msg , username ) ;
172- } ,
173- ) ;
163+ robot . respond ( / i s a w y o u @ ? ( [ - \w . \\ ^ | { } ` [ \] ] + ) \+ \+ $ / , ( msg ) => {
164+ const username = msg . match [ 1 ] ;
165+ iSawYou . increment ( username ) ;
166+ reportCount ( msg , username ) ;
167+ } ) ;
174168
175169 // respond to i-saw-you leaderboard requests
176- robot . respond (
177- / i s a w y o u l e a d e r b o a r d / ,
178- ( msg ) => {
179- const k = parseInt ( robotConfig ( 'k' ) , 10 ) ;
180- const users = iSawYou . getTopK ( k ) ;
181- const prefix = '~ i-saw-you leaderboard ~\n' ;
182- const message = prefix + users
183- . reduce ( ( a , user ) => `${ a } *${ user . username } *: ${ user . points } points\n` , '' ) ;
184- msg . send ( message ) ;
185- } ,
186- ) ;
170+ robot . respond ( / i s a w y o u l e a d e r b o a r d / , ( msg ) => {
171+ const k = parseInt ( robotConfig ( 'k' ) , 10 ) ;
172+ const users = iSawYou . getTopK ( k ) ;
173+ const prefix = '~ i-saw-you leaderboard ~\n' ;
174+ const message = prefix
175+ + users . reduce ( ( a , user ) => `${ a } *${ user . username } *: ${ user . points } points\n` , '' ) ;
176+ msg . send ( message ) ;
177+ } ) ;
187178
188179 // respond to i-saw-you get requests
189- robot . respond (
190- / i s a w y o u g e t @ ? ( [ - \w . \\ ^ | { } ` [ \] ] + ) $ / ,
191- ( msg ) => {
192- const username = msg . match [ 1 ] ;
193- reportCount ( msg , username ) ;
194- } ,
195- ) ;
180+ robot . respond ( / i s a w y o u g e t @ ? ( [ - \w . \\ ^ | { } ` [ \] ] + ) $ / , ( msg ) => {
181+ const username = msg . match [ 1 ] ;
182+ reportCount ( msg , username ) ;
183+ } ) ;
196184
197185 // respond to point set requests
198- robot . respond (
199- / i s a w y o u s e t @ ? ( [ - \w . \\ ^ | { } ` [ \] ] + ) ( \d + ) / ,
200- ( msg ) => {
201- if ( msg . match . length < 3 ) {
202- msg . send ( 'Usage: hackbot isawyou set <user> <number>' ) ;
203- } else {
204- const username = msg . match [ 1 ] ;
205- const newPoints = parseInt ( msg . match [ 2 ] , 10 ) ;
206- iSawYou . set ( username , newPoints ) ;
207- msg . send ( `*${ username } * now has ${ newPoints } i-saw-you points.` ) ;
208- }
209- } ,
210- ) ;
186+ robot . respond ( / i s a w y o u s e t @ ? ( [ - \w . \\ ^ | { } ` [ \] ] + ) ( \d + ) / , ( msg ) => {
187+ if ( msg . match . length < 3 ) {
188+ msg . send ( 'Usage: hackbot isawyou set <user> <number>' ) ;
189+ } else {
190+ const username = msg . match [ 1 ] ;
191+ const newPoints = parseInt ( msg . match [ 2 ] , 10 ) ;
192+ iSawYou . set ( username , newPoints ) ;
193+ msg . send ( `*${ username } * now has ${ newPoints } i-saw-you points.` ) ;
194+ }
195+ } ) ;
211196} ;
0 commit comments