Skip to content
This repository has been archived by the owner on Jan 13, 2019. It is now read-only.

Commit

Permalink
Fixed plugin for PHP Censor 0.16.0. See php-censor/php-censor@9041457
Browse files Browse the repository at this point in the history
  • Loading branch information
corpsee committed Aug 29, 2017
1 parent 5281d76 commit c89a48e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -26,7 +26,8 @@
"source": "https://github.com/LEXASOFT/PHP-Censor-Telegram-Plugin"
},
"require": {
"php": ">=5.3.3"
"php": ">=5.3.3",
"guzzlehttp/guzzle": "6.2.*"
},
"autoload": {
"psr-4": {
Expand Down
42 changes: 25 additions & 17 deletions src/Telegram.php
Expand Up @@ -4,11 +4,11 @@

use PHPCensor\Builder;
use PHPCensor\Model\Build;
use b8\HttpClient;
use GuzzleHttp\Client;

/**
* Telegram Plugin
*
*
* @author LEXASOFT <lexasoft83@gmail.com>
* @package PHPCensor
* @subpackage Plugins
Expand Down Expand Up @@ -77,28 +77,36 @@ public function execute()
{

$message = $this->buildMessage();

$http = new HttpClient('https://api.telegram.org');
$http->setHeaders(['Content-Type: application/json']);
$uri = '/bot'. $this->apiKey . '/sendMessage';
$client = new Client();
$url = '/bot'. $this->apiKey . '/sendMessage';

foreach ($this->recipients as $chatId) {
$params = [
'chat_id' => $chatId,
'text' => $message,
'chat_id' => $chatId,
'text' => $message,
'parse_mode' => 'Markdown',
];

$http->post($uri, json_encode($params));
$client->post(('https://api.telegram.org' . $url), [
'headers' => [
'Content-Type' => 'application/json',
],
'json' => $params,
]);

if ($this->sendLog) {
$params = [
'chat_id' => $chatId,
'text' => $this->buildMsg,
'chat_id' => $chatId,
'text' => $this->buildMsg,
'parse_mode' => 'Markdown',
];

$http->post($uri, json_encode($params));
$client->post(('https://api.telegram.org' . $url), [
'headers' => [
'Content-Type' => 'application/json',
],
'json' => $params,
]);
}
}

Expand All @@ -112,13 +120,13 @@ public function execute()
private function buildMessage()
{
$this->buildMsg = '';
$buildIcon = $this->build->isSuccessful() ? '✅' : '❎';
$buildLog = $this->build->getLog();
$buildLog = str_replace(['[0;32m', '[0;31m', '[0m', '/[0m'], '', $buildLog);
$buildMessages = explode('RUNNING PLUGIN: ', $buildLog);
$buildIcon = $this->build->isSuccessful() ? '✅' : '❎';
$buildLog = $this->build->getLog();
$buildLog = str_replace(['[0;32m', '[0;31m', '[0m', '/[0m'], '', $buildLog);
$buildMessages = explode('RUNNING PLUGIN: ', $buildLog);

foreach ($buildMessages as $bm) {
$pos = mb_strpos($bm, "\n");
$pos = mb_strpos($bm, "\n");
$firstRow = mb_substr($bm, 0, $pos);

//skip long outputs
Expand Down

0 comments on commit c89a48e

Please sign in to comment.