Created
May 28, 2014 13:59
-
-
Save ikr7/a55f6870f26cbe20a8d7 to your computer and use it in GitHub Desktop.
ツイート読み上げ
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
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; |
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
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