Пример #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     //
     $interactor = new CurlInteractor();
     $interactor->setResponseFactory(new SlackResponseFactory());
     $commander = new Commander($_ENV['SLACK_KEY'], $interactor);
     $response = $commander->execute('channels.list');
     $responseBody = $response->getBody();
     if (!$responseBody or !$responseBody['ok']) {
         throw new Exception('Sth Error Happened!');
     }
     foreach ($responseBody['channels'] as $chan) {
         if (!$chan['is_channel']) {
             continue;
         }
         $chanData = ['sid' => $chan['id'], 'name' => $chan['name'], 'created' => $chan['created'], 'creator' => $chan['creator'], 'purpose' => (object) $chan['purpose'], 'is_archived' => $chan['is_archived'], 'is_member' => $chan['is_member'], 'num_members' => $chan['num_members'], 'members' => $chan['members'], 'topic' => (object) $chan['topic']];
         if ($channel = Channel::where('sid', $chan['id'])->first()) {
             foreach ($chanData as $k => $v) {
                 $channel->{$k} = $v;
             }
             $channel->save();
         } else {
             $chanData['latest'] = 0;
             Channel::create($chanData);
         }
     }
 }
Пример #2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     //
     $interactor = new CurlInteractor();
     $interactor->setResponseFactory(new SlackResponseFactory());
     $commander = new Commander($_ENV['SLACK_KEY'], $interactor);
     $channels = Channel::where('is_member', true)->get();
     foreach ($channels as $channel) {
         $latest = $channel->latest ?: 0;
         do {
             $response = $commander->execute('channels.history', ['channel' => $channel->sid, 'oldest' => $latest, 'count' => 1000]);
             $responseBody = $response->getBody();
             foreach ($responseBody['messages'] as $msg) {
                 $latest = $msg['ts'] > $latest ? $msg['ts'] : $latest;
                 $message = new Message();
                 foreach ($msg as $k => $v) {
                     $message->{$k} = is_string($v) ? $v : (object) $v;
                 }
                 $message->channel = $channel->sid;
                 $message->save();
             }
         } while ($responseBody['has_more']);
         $channel->latest = $latest;
         $channel->save();
     }
 }
 /**
  * @return array
  */
 protected function _getData()
 {
     $interactor = new CurlInteractor();
     $interactor->setResponseFactory(new SlackResponseFactory());
     $commander = new Commander($this->_token, $interactor);
     $x = $commander->execute('channels.list');
     return Arrays::value($x->getBody(), 'channels', []);
 }
 /**
  * @return mixed
  */
 protected function _getData()
 {
     $interactor = new CurlInteractor();
     $interactor->setResponseFactory(new SlackResponseFactory());
     $commander = new Commander($this->_token, $interactor);
     $x = $commander->execute('channels.history', ['channel' => $this->_channelId, 'inclusive' => 1, 'count' => 100]);
     return Arrays::value($x->getBody(), 'messages', []);
 }
function report($message)
{
    global $config;
    $interactor = new CurlInteractor();
    $interactor->setResponseFactory(new SlackResponseFactory());
    $commander = new Commander($config['slack'], $interactor);
    $commander->execute('chat.postMessage', ['username' => 'Backup validator', 'icon_emoji' => ':x:', 'channel' => '#server', 'text' => $message]);
}
 public function postSlack()
 {
     $request = $this->_getRequest()->request;
     $interactor = new CurlInteractor();
     $interactor->setResponseFactory(new SlackResponseFactory());
     $commander = new Commander($this->getConfigItem('slack', 'token'), $interactor);
     $response = $commander->execute('users.admin.invite', ['first_name' => $request->get('first_name'), 'last_name' => $request->get('last_name'), 'email' => $request->get('email'), 'set_active' => 'true', '_attempts' => 1]);
     return $this->slack($response);
 }
Пример #7
0
 /**
  * @param SlackTimestamp $slackTimestamp
  * @return SlackMessage[]
  */
 public function getMessages(SlackTimestamp $slackTimestamp)
 {
     $response = $this->commander->execute('channels.history', ['channel' => $this->channel, 'oldest' => $slackTimestamp->getValue()]);
     $responseBody = $response->getBody();
     $responses = [];
     if (isset($responseBody['messages'])) {
         foreach ($responseBody['messages'] as $message) {
             \array_push($responses, new SlackMessage($message['text'], SlackTimestamp::createFromSlackString($message['ts'])));
         }
     }
     return $responses;
 }
Пример #8
0
 /**
  * Query the Slack API
  *
  * @param string $command
  * @param array $params
  * @return OauthTokenError|mixed
  */
 public static final function execute($command, $params = [])
 {
     if (!Cache::has('slack_token')) {
         return new Util\OauthTokenError('Slack', url('auth/slack'));
     }
     try {
         $interactor = new CurlInteractor();
         $interactor->setResponseFactory(new SlackResponseFactory());
         $commander = new Commander(Cache::get('slack_token'), $interactor);
         $response = $commander->execute($command, $params);
         return $response->getBody();
     } catch (\Exception $e) {
     }
     return false;
 }
 /**
  * Count total and active users
  *
  * @return array
  */
 private function totalUsers()
 {
     /**
      * @var
      */
     $response = $this->slack->execute('rtm.start');
     $rtm = $response->getBody();
     foreach ($rtm['users'] as $user) {
         if ($this->isReal($user)) {
             $this->count['total']++;
         }
         if ($this->isActive($user) && $this->isReal($user)) {
             $this->count['actives']++;
         }
     }
     return $this->count;
 }
Пример #10
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     //
     $interactor = new CurlInteractor();
     $interactor->setResponseFactory(new SlackResponseFactory());
     $commander = new Commander($_ENV['SLACK_KEY'], $interactor);
     $response = $commander->execute('users.list');
     $responseBody = $response->getBody();
     if (!$responseBody or !$responseBody['ok']) {
         throw new Exception('Sth Error Happened!');
     }
     foreach ($responseBody['members'] as $member) {
         $userData = ['sid' => $member['id'], 'name' => $member['name'], 'deleted' => $member['deleted'], 'color' => array_get($member, 'color'), 'profile' => (object) $member['profile']];
         if ($user = User::where('sid', $member['id'])->first()) {
             foreach ($userData as $k => $v) {
                 $user->{$k} = $v;
             }
             $user->save();
         } else {
             User::create($userData);
         }
     }
 }
 /**
  * @param Rfc $rfc
  * @param array $voteDiff
  */
 public function notify(Rfc $rfc, array $voteDiff)
 {
     $attachments = [];
     foreach ($voteDiff['votes'] as $title => $voteDiffs) {
         $attachment = ['text' => $title, 'color' => 'good', 'fields' => []];
         if (!empty($voteDiffs['new'])) {
             $newVotes = array_map(function ($voter, $vote) {
                 return sprintf('%s: %s', $voter, $vote);
             }, array_keys($voteDiffs['new']), $voteDiffs['new']);
             $attachment['fields'][] = ['title' => 'New Votes', 'value' => implode(", ", $newVotes)];
         }
         if (!empty($voteDiffs['updated'])) {
             $updatedVotes = array_map(function ($voter, $vote) {
                 return sprintf('%s: %s', $voter, $vote);
             }, array_keys($voteDiffs['updated']), $voteDiffs['updated']);
             $attachment['fields'][] = ['title' => 'Updated Votes', 'value' => implode(", ", $updatedVotes)];
         }
         $counts = [];
         foreach ($rfc->getVotes()[$title]['counts'] as $header => $standing) {
             if ($header === 'Real name') {
                 continue;
             }
             $counts[$header] = $standing;
         }
         $counts = array_map(function ($vote, $count) {
             return sprintf('%s: %s', $vote, $count);
         }, array_keys($counts), $counts);
         $attachment['fields'][] = ['title' => 'Current Standings', 'value' => implode(", ", $counts)];
         $attachments[] = $attachment;
     }
     $message = ['text' => sprintf("*PHP RFC Updates for %s*", $rfc->getName()), 'username' => 'PHP RFC Digestor', 'icon_url' => 'http://php.net/images/logos/php.ico', 'attachments' => json_encode($attachments)];
     foreach ($this->slackSubscriberRepository->findAll() as $slackSubscriber) {
         $this->commander->setToken($slackSubscriber->getToken());
         $message['channel'] = '#' . $slackSubscriber->getChannel();
         $this->commander->execute('chat.postMessage', $message);
     }
 }
Пример #12
0
 /**
  * @param $channel
  * @param $message
  * @param string $botName
  * @param string $botImage
  * @return \Frlnc\Slack\Contracts\Http\Response
  */
 public function postMessage($channel, $message, $botName = 'bot', $botImage = '')
 {
     return $this->commander->execute('chat.postMessage', ['channel' => $channel, 'text' => $message, 'username' => $botName, 'icon_url' => $botImage]);
 }
Пример #13
0
 /**
  * Sent a invitation
  *
  * @param array $fields
  *
  * @return array
  */
 public function sendInvitation(array $fields)
 {
     $request = $this->slack->execute('users.admin.invite', $fields);
     return $request->getBody();
 }
Пример #14
0
chdir(__DIR__);
header("Content-Type: text/json; charset=UTF-8");
date_default_timezone_set('America/New_York');
$pattern = '/M(.*)\\n[\\W]*T(.*)\\n[\\W]*W(.*)\\n[\\W]*[TRH](.*)\\n[\\W]*F(.*)/i';
$cleanup = '/[^a-zA-Z\\d\\s:\\>\\-\\.,\\(\\)\\@\\/\\!]/i';
$startOfWeek = strtotime("last sunday");
$today = strtotime("today");
require 'vendor/autoload.php';
require './config.php';
use Frlnc\Slack\Http\SlackResponseFactory;
use Frlnc\Slack\Http\CurlInteractor;
use Frlnc\Slack\Core\Commander;
$interactor = new CurlInteractor();
$interactor->setResponseFactory(new SlackResponseFactory());
$commander = new Commander($config['schedule']['slackWebhookId'], $interactor);
$standups = array();
$users = array();
$officeDays = array();
ob_start();
$response = $commander->execute('users.list', ['channel' => $config['schedule']['slackStandupChannel'], 'oldest' => $startOfWeek]);
foreach ($response->getBody()['members'] as $user) {
    $user['nice_name'] = $user['profile']['real_name'];
    if (!$user['nice_name']) {
        $user['nice_name'] = '@' . $user['name'];
    }
    $users[$user['id']] = $user;
}
$response = $commander->execute('channels.history', ['channel' => $config['schedule']['slackStandupChannel'], 'oldest' => $startOfWeek]);
//print_r($response);
foreach ($response->getBody()['messages'] as $message) {