Skip to content

Instantly share code, notes, and snippets.

@hinaloe
Forked from chitoku-k/悲報ダメです.js
Last active August 29, 2015 14:15
Show Gist options
  • Save hinaloe/265cb8693f8e8e1420d6 to your computer and use it in GitHub Desktop.
Save hinaloe/265cb8693f8e8e1420d6 to your computer and use it in GitHub Desktop.
var Twitter = require("twitter");
var followers = [];
var count = 0;
var client = new Twitter({
consumer_key: process.env.TWITTER_CONSUMER_KEY,
consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
access_token_key: process.env.TWITTER_ACCESS_TOKEN,
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET,
});
client.stream("user", {}, function (stream) {
stream.on("data", function (data) {
if(!count++)first(data);
if (data.text !== undefined && !data.retweeted_status) {
Process(data);
}
});
stream.on("error", function (error) {
console.log(error);
});
});
function Process(data) {
var match;
if ((match = data.text.match(/ちとく/)) !== null) {
if (followers.indexOf(data.user.id_str) === -1) {
client.get("friendships/show", { target_id: data.user.id_str }, function (error, obj, response) {
if (error) {
console.log(error);
}
if (obj.relationship.target.following) {
Send(data, match);
}
})
} else {
Send(data, match);
}
}
}
function Send(data, match) {
var time = (new Date()-new Date(data.created_at))/1000;
var text = "@" + data.user.screen_name + " あの("+time+")";
console.log(text);
client.post("statuses/update", {
status: text,
in_reply_to_status_id: data.id_str
}, function () { });
}
function first(data){
client.post("statuses/update", {status:"んっ"},function(a,b){console.log(a,b);});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment