Skip to content

Instantly share code, notes, and snippets.

@ikr7
Created May 28, 2014 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikr7/a55f6870f26cbe20a8d7 to your computer and use it in GitHub Desktop.
Save ikr7/a55f6870f26cbe20a8d7 to your computer and use it in GitHub Desktop.
ツイート読み上げ
var Command = require('../../lib/command.js'),
async = require('async'),
split = require('./split.js'),
exec = require('child_process').exec;
var say = new Command(function(twit, status, CONFIG){
if(status.retweeted_status){
status = status.retweeted_status
};
var text = status.text
.replace(/(\S)\1\1+/g, '$1$1$1')
.replace(/https?:\/\/[\w\/:%#\$&\?\(\)~\.=\+\-]+/g, '');
async.series(
split(text).map(function(e){
e = e.split(/(&&)|(\|)/)[0].replace(/^\s+/g, '');
var cmd = e.charCodeAt() < 0x7a ? 'say -v Agnes' : 'saykotoeri';
return function(callback){
// console.log(cmd + ' \"' + e + '\"');
exec(cmd + ' \"' + e + '\"', function(err){
callback(null);
});
};
})
);
});
say.setTrigger(function(data, CONFIG){
return 'text' in data;
});
say.setPermission({
'me': true,
'following': true,
'others': true
});
module.exports = say;
var split = module.exports = function(str){
var tokens = [];
var fulls = str.split(/[\u0030-\u007a]+/) || [];
var halfs = str.match(/[\u0030-\u007a]+/g) || [];
for(var i = 0; i < fulls.length; i++){
tokens[i * 2] = fulls[i];
}
for(var i = 0; i < halfs.length; i++){
tokens[i * 2 + 1] = halfs[i];
}
return tokens.filter(function(e){
return e && e != ' ';
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment