From 8d828bc21fe2e5dbbc8cf8cd7b67b755fd3343ff Mon Sep 17 00:00:00 2001 From: anekos Date: Wed, 18 Aug 2010 11:08:19 +0000 Subject: プロテクトユーザに優しい機能 git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@38299 d0d07461-0603-4401-acd4-de1884942a52 --- twittperator.js | 64 +++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 9 deletions(-) diff --git a/twittperator.js b/twittperator.js index 39bd487..424d37c 100755 --- a/twittperator.js +++ b/twittperator.js @@ -28,7 +28,7 @@ let PLUGIN_INFO = twittperator Twitter Client using ChirpStream OAuth対応Twitterクライアント - 1.1.6 + 1.2.0 2.3 2.4 teramako @@ -1403,22 +1403,33 @@ let PLUGIN_INFO = }, // }}} say: function (stat) { // {{{ let sendData = {}; + let prefix, replyUser, replyID, postfix; if (stat.match(/^(.*)@([^\s#]+)(?:#(\d+))(.*)$/)) { - let [prefix, replyUser, replyID, postfix] = [RegExp.$1, RegExp.$2, RegExp.$3, RegExp.$4]; + [prefix, replyUser, replyID, postfix] = [RegExp.$1, RegExp.$2, RegExp.$3, RegExp.$4]; if (stat.indexOf("RT @" + replyUser + "#" + replyID) == 0) { - Twitter.reTweet(replyID); + Twittperator.withProtectedUserConfirmation( + {screenName: replyUser, statusId: replyID}, + 'retweet', + function () Twitter.reTweet(replyID) + ); return; } stat = prefix + "@" + replyUser + postfix; if (replyID && !prefix) sendData.in_reply_to_status_id = replyID; } - sendData.status = stat; - sendData.source = "Twittperator"; - tw.post("http://api.twitter.com/1/statuses/update.json", sendData, function(text) { - let t = Utils.fixStatusObject(JSON.parse(text || "{}")).text; - Twittperator.echo("Your post " + '"' + t + '" (' + t.length + " characters) was sent."); - }); + Twittperator.withProtectedUserConfirmation( + {screenName: replyUser, statusId: replyID}, + 'reply', + function() { + sendData.status = stat; + sendData.source = "Twittperator"; + tw.post("http://api.twitter.com/1/statuses/update.json", sendData, function(text) { + let t = Utils.fixStatusObject(JSON.parse(text || "{}")).text; + Twittperator.echo("Your post " + '"' + t + '" (' + t.length + " characters) was sent."); + }); + } + ); }, // }}} reTweet: function (id) { // {{{ let url = "http://api.twitter.com/1/statuses/retweet/" + id + ".json"; @@ -1472,6 +1483,24 @@ let PLUGIN_INFO = echo: function (msg) { // {{{ liberator.echo("[Twittperator] " + msg); }, // }}} + isProtected: function ({statusId, userId, screenName}) { // {{{ + function isp(f) { + let r; + history.some(function(st) f(st) && (r = st)); + return r && r.user.protected && r.user.screen_name; + } + + if (screenName && isp(function(st) st.user && st.user.screen_name == screenName)) + return true; + + if (statusId && isp(function(st) st.user && st.id == statusId)) + return true; + + if (userId && find(function(st) st.user && st.user.id == userId)) + return true; + + return false; + }, // }}} loadPlugins: function () { // {{{ function isEnabled(file) let (name = file.leafName.replace(/\..*/, "").replace(/-/g, "_")) @@ -1611,6 +1640,23 @@ let PLUGIN_INFO = file.toString = toString; } }, // }}} + withProtectedUserConfirmation: function(check, actionName, action) { // {{{ + function canceled() + Twittperator.echo('Canceled.'); + + let protectedUserName = Twittperator.isProtected(check); + if (protectedUserName) { + commandline.input( + protectedUserName + ' is protected user! Do you really want to ' + actionName + '? Input "yes" if you want. => ', + function (s) (s === 'yes' ? action : canceled)(), + { + onCancel: canceled + } + ); + } else { + action(); + } + }, // }}} }; // }}} function setup() { // {{{ -- cgit v1.2.3