Exemple #1
0
while (!$caughtKill && time() < $loopStart + 60) {
    heartbeat();
    if (!($region = NextDataFile())) {
        break;
    }
    if ($region !== true) {
        $gotData[] = $region;
    }
    if ($loops++ > 30) {
        break;
    }
}
$forceBuild = isset($argv[1]) && $argv[1] == 'build';
if ($gotData || $forceBuild) {
    BuildIncludes(array_keys($timeZones));
    SendTweets($forceBuild ? array_keys($timeZones) : array_unique($gotData));
    SendAndroidNotifications(array_unique($gotData));
    DebugMessage('Done! Started ' . TimeDiff($startTime));
}
function NextDataFile()
{
    $dir = scandir(substr(SNAPSHOT_PATH, 0, -1), SCANDIR_SORT_ASCENDING);
    $gotFile = false;
    $wait = false;
    foreach ($dir as $fileName) {
        if (preg_match('/^(\\d+)-(US|EU|CN|TW|KR)\\.lua$/', $fileName, $res)) {
            if (filemtime(SNAPSHOT_PATH . $fileName) > time() - 5) {
                $wait = true;
                continue;
            }
            if (filesize(SNAPSHOT_PATH . $fileName) == 0) {
if (strlen($line) < 10) {
    echo "Line too short: " . strlen($line) . " \"{$line}\"\n";
    exit;
}
if (strlen($line) > 160) {
    echo "Line too long: " . strlen($line) . " \"{$line}\"\n";
    exit;
}
echo "Send \"{$line}\" (" . strlen($line) . ")? Y/N: ";
$yn = strtoupper(substr(trim(fgets(STDIN)), 0, 1));
if ($yn != "Y") {
    echo "Aborting.\n";
    exit;
}
echo "Sending \"{$line}\"\n";
SendTweets($line);
function SendTweets($msg)
{
    $tweetId = SendTweet($msg);
    if ($tweetId && $tweetId !== true) {
        Retweet($tweetId, 'WoWTokenNA');
        Retweet($tweetId, 'WoWTokenEU');
    }
}
function Retweet($tweetId, $accountName)
{
    global $twitterCredentials;
    $oauth = new OAuth($twitterCredentials['consumerKey'], $twitterCredentials['consumerSecret']);
    $oauth->setToken($twitterCredentials[$accountName]['accessToken'], $twitterCredentials[$accountName]['accessTokenSecret']);
    $url = 'https://api.twitter.com/1.1/statuses/retweet/' . $tweetId . '.json';
    $params = ['id' => $tweetId];