/** * Sends a notification via Slack * @param string $message */ public function sendNotification($message) { // Only send a notification if we are running in production mode if (Director::isLive()) { $config = SiteConfig::current_site_config(); $message = $config->Title . ' (' . Director::absoluteBaseURL() . ') - ' . $message; $this->client->send($message); } }
/** * Define the application's command schedule. * * @param \Illuminate\Console\Scheduling\Schedule $schedule * @return void */ protected function schedule(Schedule $schedule) { $schedule->call(function () { $users = User::all(); foreach ($users as $user) { $user->update(['available_points' => 40]); } $settings = ['username' => 'BenisBot', 'channel' => '#tempel_der_weisheit', 'link_names' => true, 'icon_emoji' => ':squirrel:']; $client = new \Maknz\Slack\Client('https://hooks.slack.com/services/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', $settings); $client->send('Mitternacht! Alle haben nun wieder 40 Benispunkte zu verteilen!'); })->daily(); }
public function slack() { // Instantiate with defaults, so all messages created // will be sent from 'Cyril' and to the #accounting channel // by default. Any names like @regan or #channel will also be linked. $settings = ['username' => env('SLACK_USERNAME'), 'channel' => env('SLACK_CHANNEL'), 'link_names' => true]; $client = new \Maknz\Slack\Client(env('SLACK_WEBHOOKS'), $settings); $client->send('Test Message!'); $client->to(array_get($settings, 'channel'))->send('Are we rich yet?'); $client->from('lubri')->to(array_get($settings, 'channel'))->send('Adventure time!'); return ''; }
public function fire() { // get last update $latestLog = DB::table('steam_log')->orderBy('updated', 'DESC')->first(); if (count($latestLog) == 0) { // create new record for player DB::table('steam_log')->insert(['steam_id' => env('STEAM_ID'), 'in_game' => 0, 'updated' => time()]); $currentStatus = 0; } else { $currentStatus = $latestLog->in_game; } $client = new \GuzzleHttp\Client(); $request = $client->createRequest('GET', 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' . env('STEAM_KEY') . '&steamids=' . env('STEAM_ID')); $response = $client->send($request); $responseData = json_decode($response->getBody()->getContents()); $player = $responseData->response->players[0]; //dd(isset($player->gameid)); if (isset($player->gameid)) { // in game $status = 1; $game_id = $player->gameid; $game_name = $player->gameextrainfo; } else { // out of game $status = 0; $game_id = null; $game_name = null; } // save latest status DB::table('steam_log')->where('steam_id', env('STEAM_ID'))->update(['in_game' => $status, 'game_id' => $game_id, 'game_name' => $game_name, 'updated' => time()]); // check to see if notification needs to be sent if ($currentStatus != $status) { if ($status == 1) { $pushMessage = 'In Game: ' . $game_name; } else { $pushMessage = 'No longer playing game'; } if (env('STEAM_NOTIFY_METHOD') == 'pushover') { // send to Pushover curl_setopt_array($ch = curl_init(), array(CURLOPT_URL => "https://api.pushover.net/1/messages.json", CURLOPT_POSTFIELDS => array("token" => env('PUSHOVER_API_KEY'), "user" => env('PUSHOVER_USER_KEY'), "message" => $pushMessage), CURLOPT_SAFE_UPLOAD => true)); curl_exec($ch); curl_close($ch); } else { // send to Slack $settings = ['username' => env('STEAM_SLACK_USERNAME'), 'channel' => '#' . env('STEAM_SLACK_CHANNEL'), 'link_names' => true, 'icon' => ':ghost:']; // send to slack $client = new \Maknz\Slack\Client(env('STEAM_SLACK_WEBHOOK'), $settings); $client->send($pushMessage); } } $this->info('Complete'); }
public function handle(Request $request) { $command = new BenisBotCommand($request->channel_id, $request->user_name, $request->text); $channel = "#{$request->channel_name}"; if (!($channel == "#privategroup")) { $handler = new BenisBotCommandHandler(); $response = "@{$request->user_name}: /BenisBot {$request->text}\n"; $response .= $handler->handle($command); $settings = ['username' => 'BenisBot', 'channel' => $channel, 'link_names' => true, 'icon_emoji' => ':squirrel:']; $client = new \Maknz\Slack\Client('https://hooks.slack.com/services/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', $settings); try { Log::info('OK'); $client->send($response); } catch (ServerException $e) { Log::info($e->getResponse()->getBody()); } } }
/** * Execute the console command. * * @return mixed */ public function handle() { $this->info('Generating reports ...'); $generators = Generator::where('is_active', 1)->get(); foreach ($generators as $generator) { $activation_hours = explode(',', $generator['activation_hours']); $activation_days = explode(',', $generator['activation_days']); $this->info('Testing ' . $generator['name'] . ' ...'); $is_day = false; $is_hour = false; $actual_time = time() + 3600; // UTC+1 = 3600 secondes $actual_day = date("w", $actual_time); foreach ($activation_days as $day) { if ($day == $actual_day) { $is_day = true; } } if ($is_day) { $this->info('It is today !'); } $actual_hour = date("H", $actual_time); foreach ($activation_hours as $hour) { if ($hour == $actual_hour) { $is_hour = true; } } if ($is_hour) { $this->info('It is hour !'); } if ($is_day == true && $is_hour == true) { $this->info('Publishing to slack ...'); $data = Generator::createReport($generator); $settings = ['username' => 'Slackreport', 'link_names' => true]; $client = new \Maknz\Slack\Client($data['generator']['slack_service']['var2'], $settings); $client->send($data['message']); } } }
/** * Run the Slack plugin. * @return bool */ public function execute() { $message = $this->phpci->interpolate($this->message); $successfulBuild = $this->build->isSuccessful(); if ($successfulBuild) { $status = 'Success'; $color = 'good'; } else { $status = 'Failed'; $color = 'danger'; } // Build up the attachment data $attachment = new \Maknz\Slack\Attachment(array('fallback' => $message, 'pretext' => $message, 'color' => $color, 'fields' => array(new \Maknz\Slack\AttachmentField(array('title' => 'Status', 'value' => $status, 'short' => false))))); $client = new \Maknz\Slack\Client($this->webHook); if (!empty($this->room)) { $client->setChannel($this->room); } if (!empty($this->username)) { $client->setUsername($this->username); } if (!empty($this->icon)) { $client->setIcon($this->icon); } $client->attach($attachment); $success = true; $client->send(''); // FIXME: Handle errors return $success; }
public function actions($action, $param = null, $param2 = null, $param3 = null) { if ($action == "getservices") { return Service::transformMany(Service::where('slug', 'slack')->orWhere('slug', 'ga')->where('user_id', Auth::user()->id)->get()); } if ($action == "getaccounts") { $service = Service::where('id', (int) $param)->where('user_id', Auth::user()->id)->first(); $client = new \Google_Client(); $client->setAuthConfigFile(public_path() . '/private/google_oauth.json'); $client->refreshToken($service['var2']); $analytics = new \Google_Service_Analytics($client); $accounts = $analytics->management_accounts->listManagementAccounts(); return $accounts->getItems(); } if ($action == "getproperties") { $service = Service::where('id', (int) $param)->where('user_id', Auth::user()->id)->first(); $client = new \Google_Client(); $client->setAuthConfigFile(public_path() . '/private/google_oauth.json'); $client->refreshToken($service['var2']); $analytics = new \Google_Service_Analytics($client); $properties = $analytics->management_webproperties->listManagementWebproperties($param2); return $properties->getItems(); } if ($action == "getprofiles") { $service = Service::where('id', (int) $param)->where('user_id', Auth::user()->id)->first(); $client = new \Google_Client(); $client->setAuthConfigFile(public_path() . '/private/google_oauth.json'); $client->refreshToken($service['var2']); $analytics = new \Google_Service_Analytics($client); $profiles = $analytics->management_profiles->listManagementProfiles($param2, $param3); return $profiles->getItems(); } if ($action == "testslack") { $service = Service::where('id', (int) $param)->where('user_id', Auth::user()->id)->first(); $client = new \Maknz\Slack\Client($service['var2'], ['username' => 'Cyril', 'channel' => '#' . $param2, 'link_names' => true]); $client->send('Hey, this is a test message from SlackReport !'); return 'success'; } }