fu.get("/send", function (req, res) { var id = qs.parse(url.parse(req.url).query).id; var text = qs.parse(url.parse(req.url).query).text; var session = sessions[id]; if (!session || !text) { res.simpleJSON(400, { error: "No such session id" }); return; } session.poke(); channel.appendMessage(session.nick, "msg", text); // Debería enviar el mensaje a twitter if(express.session.oauth) { var twit = new twitter({ consumer_key: TwitterConfig.consumer_key, consumer_secret: TwitterConfig.consumer_secret, access_token_key: express.session.oauth.access_token, access_token_secret: express.session.oauth.access_token_secret }); try { twit.updateStatus(text, function(data) { }); } catch(e) { } } res.simpleJSON(200, { rss: mem.rss }); });
onTick: function() { var nichantekinananika = [ '(((( ;゚Д゚))))', '\(^o^)/', '("`д´)ゞ', '(# ゚Д゚)', '(;´Д`)', 'キタ━(゚∀゚)━!', '(´∀`*)ε` )', '(*´ω`*).', '( ´_ゝ`)', '(´・ω・`)ショボーン', '(・∀・)', '(´・ω・`) 人(´・ω・`)', '|・ω・`)ノ', '(´・(ェ)・)', '(*´・ω・)(´・ω・`)(・ω・`*)' ]; // 上の顔文字ランダムセット var no = Math.floor(Math.random() * nichantekinananika.length); var tweetText = 'Node.js study!! ' + nichantekinananika[no]; twitterBot.updateStatus(tweetText, function(json) { console.log(json); // つぶやき内容のNotificationをなげる notifier.notify({ title: 'Botがつぶやきやがりました', message: tweetText, open: 'https://twitter.com/' + json.user.screen_name + '/statuses/' + json.id_str }, function(error, response) { //console.log(response); }); }); },
if (isNaN(args[1]) || !votingTweets.some(function (votingTweet, index) { if (votingTweet.id != args[1]) return false; if ((!args[2]) || (args[2] != '--' && args[2] != '++')) { messages = ['Bad arg #2, use --|++.']; return true; } if (-1 !== votingTweet.voters.indexOf(nick)) { messages = ['It seems you already voted for this tweet.']; } else { votingTweet.voters.push(nick); votingTweet.votes += ('--' == args[2] ? -1 : 1); messages = ['Voted ! Current vote sum is ' + votingTweet.votes + '.']; if (votingTweet.votes <= -3) { messages = ['Too many negative votes, tweet removed.']; votingTweets.splice(index, 1); } else if (votingTweet.votes >= 5) { twit.updateStatus(votingTweet.tweet, function (data) { console.log(JSON.stringify(data)); }); messages = ['So, let\'s tweet it guys ;).']; votingTweets.splice(index, 1); } } return true; })) {
var reply = (id, word) => { word = (word instanceof Array) ? word : [word]; var index = Math.floor(Math.random() * word.length); var msg = printf('@%s %s [%s]', id, word[index], new Date().toFormat('YYYY/MM/DD HH24:MI:SS')); bot.updateStatus(msg, data => { // TODO: Error Check }); };
var tweetStatus = function (stories, cb) { if (process.env.NODE_ENV !== 'production') return cb(); var message = 'New story feed available with ' + stories + ' new stories - http://www.clustter.in. #clustter'; tweet .updateStatus(message, function (data) { console.log('updated twitter status'); cb(); }); };
setInterval(function(){ tweet = tweet.slice(0,139); if(tweet.length > 0){ twit.updateStatus(tweet, function(data){ console.log(tweet); tweet = ''; }); } }, 30000);
function sendTweet (status) { twttr.updateStatus(status, function (data) { if (data.id_str) { log(timestamp() + " Tweeted " + data.id_str + ": " + data.text); } } ); }
stream.on('data', function(data) { if (data.hasOwnProperty('direct_message')) { var text = '"@' + data['direct_message']['sender']['screen_name']; text = text + ': ' + data['direct_message']['text'] + '"'; twit.updateStatus(text, function(data) { console.log(text); }); } });
Interpreter.run(text, true, function(err, result, reply) { if (err) throw err; // 返事する言葉がないときはスルー if (reply == '') return; var msg = new Date().toFormat('@' + id + ' ' + reply + ' (HH24:MI:SS)'); hecomiroid.updateStatus(msg, function (data) { console.log('[Twitter] 「' + msg + '」とつぶやきました'); }); }, '@' + id /* caller */);
applescript.execFile('get_password.applescript', [pwLength], function(err, rtn) { if (err) { // Something went wrong! } console.log('length: ' + pwLength + ' password = ' + rtn); if (rtn) { twitter.updateStatus(rtn, function(data){ }); } setTimeout(function(){ executeAppleScript(pwLength < 31 ? pwLength + 1 : 8); }, 1000*60*10); // invoke in 10 minutes });
function statusUpdate(req, res) { var content = req.body.content console.log("your new tweet content is " + content); twit.updateStatus(content, function(data, error) { if (error) { res.json(500, error) } else { res.json(200, data); } }); }
stream.on('data', function(tweet) { if(!tweet.text) return; if(tweet.user.screen_name != TWITTER_USERNAME) return; console.log(humanize.date("Y-m-d H:i:s")+" tweet.text: ", tweet.text); // If the tweet is just correcting the score, just tweet it without generating a video if(tweet.text.match(/correction/i)) { twit.updateStatus(tweet.text, function(data) {}); return; } var text = makeMessage(tweet.text); var url = "http://localhost:"+settings.port+"/record"+RECORD_URL_QUERY+"&channel="+getChannel(text)+"&text="+encodeURIComponent(text); request(url, function(err, res, body) { console.log(humanize.date("Y-m-d H:i:s")+" "+url+": ", body); }); });
var notifyMe = function notifyMeF(timerMinutes) { var msg = util.format(config.msg, timerMinutes); twit.verifyCredentials(function(data) { config.debug > 2 && console.log(Date() + ' ' + 'TWIT BEG ' + JSON.stringify(data)); }); if (config.twitter.dm) { twit.sendDirectMessage(config.twitter.dm, msg, function(data) { config.debug && console.log(Date() + ' ' + 'TWIT DIRECT MSG:' + msg); config.debug > 2 && console.log(Date() + ' ' + 'TWIT END ' + JSON.stringify(data)); }); } else { twit.updateStatus(msg, function(data) { config.debug && console.log(Date() + ' ' + 'TWIT UPDATE MSG:' + msg); config.debug > 2 && console.log(Date() + ' ' + 'TWIT END ' + JSON.stringify(data)); }); } }
exports.twitea = function(eltweet) { var keys = require('./claves'); var util = require('util'); var twitter = require('twitter'); var tweet = new twitter({ consumer_key: keys.consumerKey, consumer_secret: keys.ConsumerSecret, access_token_key: keys.tokenKey, access_token_secret: keys.tokenSecret }); tweet.updateStatus(eltweet, function(data) { console.log(util.inspect(data)); } ); }
stream.on('data', function(data) { // ツイートにはtextがある。ツイート以外の場合は終了 if (!('text' in data)) { console.error('[ERROR] invalid data'); return; } // ツイートした人、内容、リプライか否かを取得 var twUserId = data.user.screen_name ; // 自分のツイートの場合は終了 if (twUserId === BOT_ID) { return; } // tweet var twStr = twUserId + ' さんが、"' + data.text + '"ってつぶやいた'; bot.updateStatus(twStr, function(data) { console.log(data); }); });
var sendMessage = function (moisture) { console.log("Sending... Moisture: " + moisture + "%") twitterClient.updateStatus("Moisture: " + moisture + "%", function () {}) }
setTimeout(function() { twit.updateStatus(tweet.text, function(data) {}); }, 15000);
function tweetAboutComplex (name) { twit.updateStatus(name + ' industrial complex', function (err, data) { console.log('tweet was ' + (!!err ? '' : 'NOT ') + 'OKAY'); }); }
// Commands function executeCommand(command, nick, origin) { var messages, dest; switch (command.split(' ')[0].toLowerCase()) { case 'ls': case 'help': case 'commands': dest = IRC_DEST_NICK; messages = ['I understand the following commands :', '- ls/commands : list commands', '- hello/lo : kinda cool to say hello!', '- watch <nickname> : tells you when <nickname> talk', '- unwatch <nickname> : stops telling you when <nickname> talk', '- dice <faces> <num> : Lets hazard comes', '- eval <code> : Life is dangerous', '- wannatweet <theTweet> : Launch a poll to tweet', '- vote : List all tweets that await votes', '- vote <voteId> ++|-- : Vote for a tweet', '- seen <nickname> : last connection of <nickname> (not implemented)', '- diffuse <message> : diffuse a message to each js chan (#parisjs,' +' #francejs) (not implemented)', '- log <n> <start> <date> : give the <n> messages nick <start> on <date>' +' (not implemented)', '- todo : adds items todo (not implemented)' ]; break; case 'lo': case 'hello': case 'hi': dest = IRC_DEST_SELECT; messages = ['Hi! Nice to see you!']; break; case 'd': case 'roll': case 'dice': dest = IRC_DEST_SELECT; var args = command.split(' '); if (args.length < 2) { messages = ['Not enought args given for the d command.']; break; } args[1] = parseInt(args[1]); args[2] = parseInt(args[2]); if (isNaN(args[1]) || args[1] < 2) { messages = ['Invalid face count for d command (numFaces >= 2).']; break; } if (args[2] && (isNaN(args[2]) || args[2] < 1 || args[2] > 11)) { messages = ['Invalid dice count for d command (11 < numDices >= 2).']; break; } var result = ''; for (var i = 0, j = (args[2] ? args[2] : 1); i < j; i++) result += (result ? ' ' : '') + Math.round((Math.random() * (args[1] - 1)) + 1); messages = [result]; break; case 'say': if (-1 === ADMINS.indexOf(nick)) { dest = IRC_DEST_NICK; messages = ['Not allowed to say that.']; break; } dest = IRC_DEST_CHAN | IRC_DEST_SILENT; messages = [command.split(' ').splice(1).join(' ')]; break; case 'eval': var s = new Sandbox(); s.run(command.split(' ').splice(1).join(' '), function (output) { client.say(MAIN_CHANNEL, logMessage( IRC_EVENT_MSG | IRC_EVENT_BOT, [BOT_NAME, nick + ': ' + output.result.substr(0, 50)])); }); messages = ['Running...']; break; case 'twittime': dest = IRC_DEST_NICK; if (-1 === ADMINS.indexOf(nick)) { messages = ['Not allowed to do that.']; break; } var args = command.split(' '); if (args.length < 2) { messages = ['Not enought args given for the twittime command.']; break; } twittLastDate = new Date(parseInt(args[1])), messages = ['You mastered the time, doc.']; break; case 'wannatweet': dest = IRC_DEST_SELECT; var tweet = command.split(' ').splice(1).join(' '); if (tweet.length < 5) { messages = ['No tweet or tweet too small.']; break; } votingTweets.push({ 'tweet': tweet, 'votes': 1, 'voters': [nick], 'id': (++votingIds) }); messages = ['Tweet #' + votingIds + ' added send "vote ' + votingIds + ' ++|--" to give your opinion.']; break; case 'vote': dest = IRC_DEST_SELECT; var args = command.split(' '); if (args.length < 2) { messages = votingTweets.map(function (v) { return '#' + v.id + ': ' + v.tweet + ' (votes: ' + v.votes + ').' }); break; } args[1] = parseInt(args[1]); if (isNaN(args[1]) || !votingTweets.some(function (votingTweet, index) { if (votingTweet.id != args[1]) return false; if ((!args[2]) || (args[2] != '--' && args[2] != '++')) { messages = ['Bad arg #2, use --|++.']; return true; } if (-1 !== votingTweet.voters.indexOf(nick)) { messages = ['It seems you already voted for this tweet.']; } else { votingTweet.voters.push(nick); votingTweet.votes += ('--' == args[2] ? -1 : 1); messages = ['Voted ! Current vote sum is ' + votingTweet.votes + '.']; if (votingTweet.votes <= -3) { messages = ['Too many negative votes, tweet removed.']; votingTweets.splice(index, 1); } else if (votingTweet.votes >= 5) { twit.updateStatus(votingTweet.tweet, function (data) { console.log(JSON.stringify(data)); }); messages = ['So, let\'s tweet it guys ;).']; votingTweets.splice(index, 1); } } return true; })) { messages = ['Invalid voting tweet number (format: vote [tweetid] ++|--).']; break; } break; case 'tweet': dest = IRC_DEST_NICK; if (-1 === ADMINS.indexOf(nick)) { messages = ['You aren\'t allowed to tweet.']; break; } var tweet = command.split(' ').splice(1).join(' '); if (tweet.length < 5) { messages = ['No tweet or tweet too small.']; break; } twit.updateStatus(tweet, function (data) { console.log(JSON.stringify(data)); }); messages = ['Your tweet has been sent (' + tweet + ').']; break; case 'quote': var req = http.request({ host: 'www.iheartquotes.com', port: 80, path: '/api/v1/random?source=esr+humorix_misc+humorix_stories+' +'joel_on_software+macintosh+math+mav_flame+osp_rules+paul_graham' +'+prog_style+subversion' + '&max_lines=4&max_characters=256' +'&format=json', method: 'GET' }, function (res) { var body = ''; res.setEncoding('utf8'); res.on('data', function (chunk) { body += chunk; }); res.on('end', function (chunk) { var result = JSON.parse(body); client.say(MAIN_CHANNEL, logMessage( IRC_EVENT_MSG | IRC_EVENT_BOT, [BOT_NAME, result.quote])); client.say(MAIN_CHANNEL, logMessage( IRC_EVENT_MSG | IRC_EVENT_BOT, [BOT_NAME, 'Source: ' + result.link])); }); }); req.on('error', function (e) { console.log('Couldn\'t retrieve the fortune: ' + e.message); }); req.write(''); req.end(); break; case 'bitch': case 'bastard': case 'm**********r': case 'f**k': case 'f****r': case 'idiot': case 'git': dest = IRC_DEST_SELECT; messages = [IRC_DEST_SELECT, 'Nice to meet you "' + command.split(' ')[0] + '", I\'m ' + BOT_NAME + ', waiting for commands!']; break; case 'watch': dest = IRC_DEST_NICK; var args = command.split(' '); if (args.length < 2) { messages = ['Not enought args given for the watch command.']; break; } if (args[1] == BOT_NAME) { messages = ['Bots have private life too.']; break; } if (watchs[args[1]] && -1 !== watchs[args[1]].indexOf(nick)) { messages = ['You\'re already watching ' + args[1] + '.']; break; } (undefined !== watchs[args[1]] && watchs[args[1]].push(nick) || (watchs[args[1]] = [nick + ''])); messages = ['Now you\'re watching ' + args[1] + '.']; break; case 'unwatch': dest = IRC_DEST_NICK; var args = command.split(' '); if (args.length < 2) { messages = ['Not enought args given for the unwatch command']; break; } var index = watchs[args[1]].indexOf(nick); if (watchs[args[1]] && -1 !== index && watchs[args[1]].splice(index, 1)); { messages = ['You unwatched ' + args[1] + '.']; break; } messages = ['You wasn\'t watching ' + args[1] + '.']; break; case 'seen': case 'diffuse': case 'log': case 'todo': dest = IRC_DEST_SELECT; messages = ['Not implemented, but feel free to:' +' https://github.com/francejs/irc-bot']; break; default: dest = IRC_DEST_NICK; messages = ["You\'re talking to me ?? Try ls."]; break; } if (dest === IRC_DEST_SELECT) dest |= origin; (dest & IRC_DEST_CHAN) && messages.forEach(function (msg, i) { client.say(MAIN_CHANNEL, logMessage(IRC_EVENT_MSG | IRC_EVENT_BOT, [BOT_NAME, (i === 0 && !(dest & IRC_DEST_SILENT) ? nick + ': ' : '') + msg])); }); (dest & IRC_DEST_NICK) && messages.forEach(function (msg) { client.say(nick, msg); }); }
function tweetMessage(message, callback) { _TWIT.updateStatus(message, callback); }
* Twitter でのつぶやきに反応する * ------------------------------------------------------------------------ */ // {{{ // OAuth でログイン var hecomiroid = new twitter({ consumer_key : TW_SETTING.CONSUMER_KEY, consumer_secret : TW_SETTING.CONSUMER_SECRET, access_token_key : TW_SETTING.ACCESS_TOKEN_KEY, access_token_secret : TW_SETTING.ACCESS_TOKEN_SECRET }); // 起動時刻をつぶやく var msg = new Date().toFormat('[YYYY/MM/DD HH24:MI:SS] 起動しました'); hecomiroid.updateStatus(msg, function (data) { console.log('[Twitter] 「' + msg + '」とつぶやきました'); }); // ストリームつないでコマンド待受 hecomiroid.stream('user', function(stream) { console.log('[Twitter] Stream に接続しました'); stream.on('data', function(data) { // フレンドリストがやってきたときは破棄 if (!('user' in data)) return; var id = data.user.screen_name; var user = data.user.name; var text = data.text.replace(new RegExp('^@' + TW_SETTING.BOT_ID + ' '), ''); var isMention = data.in_reply_to_user_id != null; // 自分のつぶやきの場合は終了