if ('LHT' == $post['phase']) {
                $message = ':toilet: ' . $language[LANG][5];
                postToSlack($message, array($language[LANG][2] => $response['match']['scores'][0] . ' - ' . $response['match']['scores'][1], $language[LANG][4] => $post['time']['label']), $db['last_message']);
            } elseif ('L2' == $post['phase']) {
                $message = ':runner: ' . $language[LANG][6];
                postToSlack($message, array($language[LANG][2] => $response['match']['scores'][0] . ' - ' . $response['match']['scores'][1], $language[LANG][4] => $post['time']['label']), $db['last_message']);
            } elseif ('LFT' == $post['phase']) {
                $message = ':mega: ' . $language[LANG][7];
                postToSlack($message, array($language[LANG][2] => $response['match']['scores'][0] . ' - ' . $response['match']['scores'][1], $language[LANG][4] => $post['time']['label']), $db['last_message']);
                $db['live_match'] = 0;
            }
            break;
            // replacement
        // replacement
        case 'Sub On':
            $message = ':arrow_up: ' . $defaultMessage . ': ' . $player;
            postToSlack($message, array(), $db['last_message']);
            break;
        case 'Sub Off':
            $message = ':arrow_down: ' . $defaultMessage . ': ' . $player;
            postToSlack($message, array($language[LANG][2] => $response['match']['scores'][0] . ' - ' . $response['match']['scores'][1], $language[LANG][4] => $post['time']['label']), $db['last_message']);
            break;
    }
}
if (isset($post)) {
    $db['last_second'] = $post['time']['secs'];
}
if (isset($message)) {
    $db['last_message'] = $message;
}
file_put_contents($dbFile, json_encode($db));
        die("An error occured (is the Go server up?)");
        //problem with the go server
    }
    curl_close($curlHandle);
    return json_decode($content, true);
}
function getLongUrl($slug)
{
    $links = getGoLinks(GO_SERVER . GO_LINKS_API_PATH);
    foreach ($links as $link) {
        if ($link['shortUri'] == $slug) {
            return $link['longUri'];
        }
    }
    die("No link found for " . $slug);
}
function postToSlack($message)
{
    $payload = array(text => $message, username => BOT_NAME, channel => $_POST["channel_id"], link_names => 1, mrkdwn => "true");
    $json_payload = json_encode($payload);
    $curlHandle = curl_init();
    curl_setopt($curlHandle, CURLOPT_URL, INCOMING_WEBHOOK);
    curl_setopt($curlHandle, CURLOPT_POST, 1);
    curl_setopt($curlHandle, CURLOPT_POSTFIELDS, "payload=" . $json_payload);
    curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($curlHandle);
}
$longUrl = getLongUrl($_POST["text"]);
$returnText = "@" . $_POST["user_name"] . " shared *<" . GO_SERVER_SHORT . $_POST["text"] . "|" . GO_SERVER_DISPLAY . "/" . $_POST["text"] . ">*\n" . "_ <" . GO_SERVER_SHORT . $_POST["text"] . "|" . urlencode($longUrl) . ">_";
postToSlack($returnText);
Example #3
0
    // TODO Replace <GITHUB_TOKEN> with valid github token
    run('composer config -g github-oauth.github.com <GITHUB_TOKEN>');
    run('composer global require "fxp/composer-asset-plugin:~1.1.1"');
});
/** Slack Tasks Begin */
task('slack:before_deploy', function () {
    postToSlack('Starting deploy on ' . env('server.name') . '...');
});
task('slack:after_deploy', function () {
    postToSlack('Deploy to ' . env('server.name') . ' done');
});
task('slack:after_migrate', function () {
    postToSlack('Migrations done on ' . env('server.name'));
});
task('slack:before_migrate', function () {
    postToSlack('Running migrations on ' . env('server.name') . '...');
});
/** Slack Tasks End */
/**
 * Main task
 */
task('deploy', ['deploy:prepare', 'deploy:release', 'deploy:update_code', 'deploy:shared', 'deploy:yii2_composer_config', 'deploy:vendors', 'deploy:upload_environments_file', 'deploy:run_migrations', 'deploy:symlink', 'deploy:writable', 'deploy:cleanup'])->desc('Deploy Project');
function postToSlack($message)
{
    $slackHookUrl = env('SLACK_HOOK_URL');
    if (!empty($slackHookUrl)) {
        runLocally('curl -s -S -X POST --data-urlencode payload="{\\"channel\\": \\"#' . env('SLACK_CHANNEL_NAME') . '\\", \\"username\\": \\"Release Bot\\", \\"text\\": \\"' . $message . '\\"}"' . env('SLACK_HOOK_URL'));
    } else {
        write('Configure the SLACK_HOOK_URL to post to slack');
    }
}
                            // extra time starts
                            postToSlack($preText . ':dizzy: ' . $text);
                            break;
                        case '2ET':
                            // second period of extra time
                            postToSlack($preText . ':runner: ' . $text);
                            break;
                        case 'PSO':
                            // penalty shout-out
                            postToSlack($preText . ':dart: ' . $text);
                            break;
                    }
                    break;
                    // penalty shout-out
                // penalty shout-out
                case 'PSG':
                    // pso goal
                    postToSlack($preText . ':+1: ' . $text);
                    break;
                case 'PSM':
                    // pso goal
                    postToSlack($preText . ':-1: ' . $text);
                    break;
            }
        }
    }
    if (isset($db[$liveMatch])) {
        $db[$liveMatch]['last_update'] = $post['d_Date'];
    }
}
file_put_contents($dbFile, json_encode($db));