@@ -239,7 +239,6 @@ var commands = {
239
239
usage : "<invite>" ,
240
240
description : "joins the server it's invited to" ,
241
241
process : function ( bot , msg , suffix ) {
242
- console . log ( suffix ) ;
243
242
console . log ( bot . joinServer ( suffix , function ( error , server ) {
244
243
console . log ( "callback: " + arguments ) ;
245
244
if ( error ) {
@@ -316,11 +315,18 @@ var commands = {
316
315
wolfram_plugin . respond ( suffix , msg . channel , bot ) ;
317
316
}
318
317
} ,
319
- "hotspatch " : {
320
- description : "gets the latest patch notes for Heroes of the Storm from blizzpro " ,
318
+ "rss " : {
319
+ description : "lists available rss feeds " ,
321
320
process : function ( bot , msg , suffix ) {
322
- //http://heroesofthestorm.blizzpro.com/tag/patch-notes/feed/
323
- rssfeed ( "heroesofthestorm.blizzpro.com" , "/tag/patch-notes/feed/" , bot , msg , suffix ) ;
321
+ /*var args = suffix.split(" ");
322
+ var count = args.shift();
323
+ var url = args.join(" ");
324
+ rssfeed(bot,msg,url,count,full);*/
325
+ bot . sendMessage ( msg . channel , "Available feeds:" , function ( ) {
326
+ for ( var c in rssFeeds ) {
327
+ bot . sendMessage ( msg . channel , c + ": " + rssFeeds [ c ] . url ) ;
328
+ }
329
+ } ) ;
324
330
}
325
331
} ,
326
332
"reddit" : {
@@ -331,48 +337,66 @@ var commands = {
331
337
if ( suffix ) {
332
338
path = "/r/" + suffix + path ;
333
339
}
334
- rssfeed ( " www.reddit.com", path , bot , msg , "" ) ;
340
+ rssfeed ( bot , msg , "https:// www.reddit.com"+ path , 1 , false ) ;
335
341
}
336
342
}
337
343
} ;
344
+ try {
345
+ var rssFeeds = require ( "./rss.json" ) ;
346
+ function loadFeeds ( ) {
347
+ for ( var cmd in rssFeeds ) {
348
+ commands [ cmd ] = {
349
+ usage : "[count]" ,
350
+ description : rssFeeds [ cmd ] . description ,
351
+ url : rssFeeds [ cmd ] . url ,
352
+ process : function ( bot , msg , suffix ) {
353
+ var count = 1 ;
354
+ if ( suffix != null && suffix != "" && ! isNaN ( suffix ) ) {
355
+ count = suffix ;
356
+ }
357
+ rssfeed ( bot , msg , this . url , count , false ) ;
358
+ }
359
+ } ;
360
+ }
361
+ }
362
+ } catch ( e ) {
363
+ console . log ( "Couldn't load rss.json. See rss.json.example if you want rss feed commands. error: " + e ) ;
364
+ }
338
365
339
- function rssfeed ( host , path , bot , msg , suffix ) {
340
- var http = require ( 'http' ) ;
341
- http . get ( {
342
- host :host ,
343
- path :path
344
- } , function ( response ) {
366
+ function rssfeed ( bot , msg , url , count , full ) {
367
+ var FeedParser = require ( 'feedparser' ) ;
368
+ var feedparser = new FeedParser ( ) ;
369
+ var request = require ( 'request' ) ;
370
+ request ( url ) . pipe ( feedparser ) ;
371
+ feedparser . on ( 'error' , function ( error ) {
372
+ bot . sendMessage ( msg . channel , "failed reading feed: " + error ) ;
373
+ } ) ;
374
+ var shown = 0 ;
375
+ feedparser . on ( 'readable' , function ( ) {
345
376
var stream = this ;
346
- var FeedParser = require ( 'feedparser' ) ;
347
- var feedparser = new FeedParser ( ) ;
348
- response . pipe ( feedparser ) ;
349
- feedparser . on ( 'error' , function ( error ) {
350
- bot . sendMessage ( msg . channel , "failed reading feed: " + error ) ;
351
- } ) ;
352
- feedparser . on ( 'readable' , function ( ) {
353
- var stream = this ;
354
- if ( stream . alreadyRead ) {
355
- return ;
377
+ shown += 1
378
+ if ( shown > count ) {
379
+ return ;
380
+ }
381
+ var item = stream . read ( ) ;
382
+ bot . sendMessage ( msg . channel , item . title + " - " + item . link , function ( ) {
383
+ if ( full === true ) {
384
+ var text = htmlToText . fromString ( item . description , {
385
+ wordwrap :false ,
386
+ ignoreHref :true
387
+ } ) ;
388
+ bot . sendMessage ( msg . channel , text ) ;
356
389
}
357
- var item = stream . read ( ) ;
358
- bot . sendMessage ( msg . channel , item . title + " - " + item . link , function ( ) {
359
- if ( suffix === "full" ) {
360
- var text = htmlToText . fromString ( item . description , {
361
- wordwrap :false ,
362
- ignoreHref :true
363
- } ) ;
364
- bot . sendMessage ( msg . channel , text ) ;
365
- }
366
- } ) ;
367
- stream . alreadyRead = true ;
368
390
} ) ;
391
+ stream . alreadyRead = true ;
369
392
} ) ;
370
393
}
371
394
372
395
373
396
var bot = new Discord . Client ( ) ;
374
397
375
398
bot . on ( "ready" , function ( ) {
399
+ loadFeeds ( ) ;
376
400
console . log ( "Ready to begin! Serving in " + bot . channels . length + " channels" ) ;
377
401
} ) ;
378
402
@@ -385,7 +409,8 @@ bot.on("disconnected", function () {
385
409
386
410
bot . on ( "message" , function ( msg ) {
387
411
//check if message is a command
388
- if ( msg . author != bot . user && ( msg . content [ 0 ] === '!' || msg . content . indexOf ( bot . user . mention ( ) ) == 0 ) ) {
412
+ if ( msg . author . id != bot . user . id && ( msg . content [ 0 ] === '!' || msg . content . indexOf ( bot . user . mention ( ) ) == 0 ) ) {
413
+ console . log ( "treating " + msg . content + " from " + msg . author + " as command" ) ;
389
414
var cmdTxt = msg . content . split ( " " ) [ 0 ] . substring ( 1 ) ;
390
415
var suffix = msg . content . substring ( cmdTxt . length + 2 ) ; //add one for the ! and one for the space
391
416
if ( msg . content . indexOf ( bot . user . mention ( ) ) == 0 ) {
0 commit comments