This repository has been archived by the owner on Sep 28, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
autoFollow plugin, improve error handling, friendship bug fixes.
- Loading branch information
Showing
6 changed files
with
89 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* When the new follower is notified, the bot follow him/her. | ||
* | ||
* @author yssk22@gmail.com | ||
* | ||
*/ | ||
var inspect = require('util').inspect; | ||
exports.configure = function(options){ | ||
if( !options ){ | ||
options = {}; | ||
} | ||
this._autoFollow = options; | ||
} | ||
|
||
var events = []; | ||
events.push( | ||
['data', function(data){ | ||
if(data.event == 'follow'){ | ||
console.log(inspect(data)); | ||
var bot = this; | ||
bot.client.friendships.create({screen_name: data.source.screen_name}, function(err, result){ | ||
if( err ){ | ||
if( err.data && err.data.error ){ | ||
bot.logger.warn(err.data.error); | ||
}else{ | ||
bot.logger.error(inspect(err)); | ||
} | ||
}else{ | ||
bot.logger.info('AutoFollow: source = ' + data.source.screen_name + ')'); | ||
} | ||
}); | ||
} | ||
}] | ||
); | ||
|
||
exports.events = events; | ||
|
||
// for manual testing | ||
if(!module.parent){ | ||
var TwBot = require('../twbot').TwBot; | ||
var bot = new TwBot({ | ||
consumerKey : process.argv[2], | ||
consumerSecret : process.argv[3], | ||
accessKey : process.argv[4], | ||
accessSecret : process.argv[5] | ||
}); | ||
// debug pluin dumps all data event to stderr. | ||
bot.loadPlugin(__filename, {autoUnfollow: true}); | ||
bot.startUserStream(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
var assert = require('assert'); | ||
var twitter = require('twitter'); | ||
|
||
try{ | ||
var config = JSON.parse(require('fs').readFileSync(__dirname + '/../auth.json')); | ||
}catch(e){ | ||
console.error('Please prepare test/auth.json for testing'); | ||
process.exit(1); | ||
} | ||
|
||
var client = new twitter.createClient(config.consumerKey, config.consumerSecret, | ||
{ | ||
accessKey: config.accessKey, | ||
accessSecret: config.accessSecret | ||
}).friendships; | ||
|
||
module.exports = { | ||
"test createAndDelete": function(){ | ||
client.create({screen_name: 'yssk22_dev2'}, function(err, data){ | ||
assert.isUndefined(err); | ||
assert.isNotNull(data); | ||
client.destroy({screen_name: 'yssk22_dev2'}, function(err, data){ | ||
assert.isUndefined(err); | ||
assert.isNotNull(data); | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters