Last active
August 29, 2015 14:00
-
-
Save ikr7/3f209bd9fcb40f10fad1 to your computer and use it in GitHub Desktop.
bbop.js
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
// github.com/ikr7/twitter_commands_v2 で bbop | |
// 参考: https://gist.github.com/laco0416/8ffe20bfd393e1344112 | |
var Command = require('../lib/command.js'); | |
var makebbop = function(){ | |
var elements = ['ビ','ビ','ド','レ','ド','オ','ペ','レ','ショ']; | |
var indice = []; | |
var matches = 0; | |
elements.forEach(function(ch, i, arr){ | |
indice[i] = elements[Math.floor(Math.random() * elements.length)]; | |
if(elements[i] === indice[i]){ | |
matches += 1; | |
} | |
}); | |
var score = matches / 9.0 * 100; | |
var result = | |
indice[0] + | |
indice[1] + | |
'ッ' + | |
indice[2] + | |
indice[3] + | |
'ッ' + | |
indice[4] + | |
'・' + | |
indice[5] + | |
indice[6] + | |
indice[7] + | |
'ー' + | |
indice[8] + | |
'ン' + | |
' (' + Math.round(score*10)/10 + '%)'; | |
return result; | |
}; | |
var bbop = new Command(function(twit, reply, CONFIG){ | |
twit.post('/statuses/update.json', { | |
'status': '@' + reply.user.screen_name + ' ' + makebbop() | |
}, function(err, res){ | |
if(!err){ | |
console.log(res); | |
}else{ | |
console.error(err); | |
} | |
}); | |
}); | |
bbop.setTrigger( | |
new RegExp('@' + Command.CONFIG.MY_SCREEN_NAME + '\\s+bbop\\s*', 'i') | |
); | |
bbop.setPermission({ | |
'me': true, | |
'following': true, | |
'others': true | |
}); | |
module.exports = bbop; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment