0.2.0 • Published 10 years ago
foxtail v0.2.0
FoxTail
みこーん。
Twitter bot generator for node.js
You can easily add plugin to your bot.
Installation
npm install foxtailEasy Example
1. Setup FoxTail.
index.js
var FoxTail = require('foxtail');
var fox = new FoxTail({
consumer_key: ...,
consumer_secret: ...,
access_token: ...,
access_token_secret: ...
});
// show timeline
fox.add(function (res) {
console.log("@" + res.screen_name + "(" + res.user_name + ") " + res.text + "\n");
});
// reply to words
fox.add(function (res) {
if (res.text === 'hello') res.reply('world');
});
fox.run();2. Run
$ node index.jsExample
If you want to separate plugins, you can place the plugin file into the plugin folder.
plugin/hello.js
module.exports = function (fox) {
fox.add(function (res) {
if (res.text === 'hello') res.reply('world');
});
};index.js
var FoxTail = require('foxtail');
var Path = require('path');
var fox = new FoxTail({
consumer_key: ...,
consumer_secret: ...,
access_token: ...,
access_token_secret: ...
});
fox.load(Path.resolve(__dirname, 'plugin'));
fox.run();Very Easy!
Using foxtail npm plugins
If you want to create bot more easily, You can use the npm plugins.
This is an example.
This plugin is that reply 'hello' to 'world' in the timeline.
First, Install foxtail plugin.
$ npm install foxtail-hello-worldAdd plugin name into json file.
fox.json
['foxtail-hello-world']Add loadNpmScript to index.js.
index.js
var FoxTail = require('foxtail');
var Path = require('path');
var fox = new FoxTail({
consumer_key: ...,
consumer_secret: ...,
access_token: ...,
access_token_secret: ...
});
fox.loadNpmScript(Path.resolve(__dirname, 'fox.json'));
fox.run();YEAR!!!!
Response Action
Tweet
fox.add(function (res) {
if (res.text === 'foo') res.post('bar');
});Reply
fox.add(function (res) {
if (res.text === 'hello') res.reply('world');
});Retweet
fox.add(function(res) {
if (res.screen_name === 'akameco') res.retweet();
});Favorite
fox.add(function(res) {
if (/happy/.test(res.text)) res.favorite();
});Schedule Tweet
install node-cron
$ npm install cron --savevar cron = require('cron');
var job = new cron.cronJob('0 0 0 * * *', function () {
fox.post('hello');
}, null, false);
module.exports = function (fox) {
fox.add(function () {
job.start();
});
};Development
# watch
npm run watch
# build
npm run build
# test
npm testContributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request :D
License
MIT