예제 #1
0
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. * 
 * You may obtain a copy of the License at * 
 * http://www.apache.org/licenses/LICENSE-2.0 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
require_once __DIR__ . '/cli/composer.php';
$cli = new League\CLImate\CLImate();
$cli->arguments->add(['file' => ['prefix' => 'f', 'longPrefix' => 'file', 'description' => 'Path to credentials file to parse', 'defaultValue' => null], 'help' => ['prefix' => 'h', 'longPrefix' => 'help', 'description' => 'Show this help', 'defaultValue' => false, 'noValue' => true], 'section' => ['description' => '.edgerc section to create', 'defaultValue' => 'default']]);
$cli->arguments->parse($_SERVER['argv']);
if ($cli->arguments->get('help')) {
    $cli->usage();
    exit;
}
define('HOME', $_SERVER['HOME']);
define('EDGERC', realpath(HOME . '/.edgerc'));
define('SECTION', $cli->arguments->get('section'));
if (file_exists(EDGERC) && !is_writable(EDGERC) || !is_writable(HOME)) {
    $cli->to('error')->error("Unable to write to file " . EDGERC);
    exit(-1);
}
echo "After authorizing your client in the {OPEN} API Administration tool,\n";
echo "export the credentials and paste the contents of the export file below,\n";
echo "followed by control-D. (You may need to enter is twice)\n";
echo ">>> ";
$inputStream = fopen('php://stdin', 'r+');
if (!($file = $cli->arguments->get('file'))) {
예제 #2
0
<?php

require dirname(__DIR__) . '/vendor/autoload.php';
use Pod\Slack\Api;
$dotenv = new Dotenv\Dotenv(getenv('HOME'), '.slackbot');
$dotenv->load();
$dotenv->required('SLACKBOT_TOKEN');
$climate = new League\CLImate\CLImate();
$climate->arguments->add(['help' => ['longPrefix' => 'help', 'description' => 'Prints a usage statement', 'noValue' => true], 'name' => ['description' => 'Name or real name to send message to', 'required' => true], 'message' => ['description' => 'message to send', 'required' => true]]);
$climate->arguments->parse();
if ($climate->arguments->defined('help')) {
    $climate->usage();
    exit;
}
$name = $climate->arguments->get('name');
$message = $climate->arguments->get('message');
$token = getenv('SLACKBOT_TOKEN');
$api = new Api\Api($token);
$auth = $api->auth->test();
$bot = $api->users->info($auth->user_id);
$ul = $api->users->list();
$user = $ul->findByNameOrRealName($name);
if ($user === null) {
    echo "No such user" . PHP_EOL;
    exit(1);
}
$api->chat->postMessage($user->id, $message, $bot->name, $bot->profile->image_48);