Created
June 10, 2020 22:51
-
-
Save PJZ9n/a9a97852307bb533845bb58b497e922e to your computer and use it in GitHub Desktop.
自動フォローバックのソースコード。最悪な実装です。
This file contains hidden or 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
<?php | |
/** | |
* Copyright (c) 2020 PJZ9n. | |
* | |
* This file is part of Tuihai. | |
* | |
* Tuihai is free software: you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation, either version 3 of the License, or | |
* (at your option) any later version. | |
* | |
* Tuihai is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* You should have received a copy of the GNU General Public License | |
* along with Tuihai. If not, see <http://www.gnu.org/licenses/>. | |
*/ | |
declare(strict_types=1); | |
require_once __DIR__ . "/private/composer/vendor/autoload.php"; | |
use Abraham\TwitterOAuth\TwitterOAuth; | |
use PJZ9n\Tuihai\Environment\Environment; | |
use PJZ9n\Tuihai\Log\AppLog; | |
function response(int $code, string $message): void | |
{ | |
http_response_code($code); | |
echo json_encode([ | |
"code" => $code, | |
"message" => $message, | |
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); | |
exit(); | |
} | |
//response(503, "Service Unavailable"); | |
//ロガー | |
$logger = AppLog::getLogger("CheckFollow"); | |
//セキュリティチェック | |
if ($_SERVER["REMOTE_ADDR"] !== "0.0.0.0") { | |
$logger->warning("ip check failed", [ | |
"ip" => $_SERVER["REMOTE_ADDR"], | |
]); | |
response(401, "接続元IP不正"); | |
} | |
//bot取得 | |
$bot = new TwitterOAuth( | |
Environment::TWITTER_API_CONSUMER_KEY, | |
Environment::TWITTER_API_SECRET_KEY, | |
Environment::TWITTER_API_BOT_TOKEN, | |
Environment::TWITTER_API_BOT_TOKEN_SECRET | |
); | |
//フォロワー取得 | |
$followersList = $bot->get("followers/list"); | |
$processedCount = 0; | |
$logger->debug("check start"); | |
foreach ($followersList->users as $follower) { | |
if (!$follower->following) { | |
$bot->post("friendships/create", [ | |
"user_id" => $follower->id, | |
"follow" => true, | |
]); | |
$logger->info("SUCCESS FOLLOW!", [ | |
"screen_name" => $follower->screen_name, | |
]); | |
$processedCount++; | |
break; | |
} | |
} | |
response(200, "success {$processedCount} count"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment