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

Commit c89a48e

Browse files
committed
Fixed plugin for PHP Censor 0.16.0. See php-censor/php-censor@9041457
1 parent 5281d76 commit c89a48e

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"source": "https://github.com/LEXASOFT/PHP-Censor-Telegram-Plugin"
2727
},
2828
"require": {
29-
"php": ">=5.3.3"
29+
"php": ">=5.3.3",
30+
"guzzlehttp/guzzle": "6.2.*"
3031
},
3132
"autoload": {
3233
"psr-4": {

src/Telegram.php

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
use PHPCensor\Builder;
66
use PHPCensor\Model\Build;
7-
use b8\HttpClient;
7+
use GuzzleHttp\Client;
88

99
/**
1010
* Telegram Plugin
11-
*
11+
*
1212
* @author LEXASOFT <lexasoft83@gmail.com>
1313
* @package PHPCensor
1414
* @subpackage Plugins
@@ -77,28 +77,36 @@ public function execute()
7777
{
7878

7979
$message = $this->buildMessage();
80-
81-
$http = new HttpClient('https://api.telegram.org');
82-
$http->setHeaders(['Content-Type: application/json']);
83-
$uri = '/bot'. $this->apiKey . '/sendMessage';
80+
$client = new Client();
81+
$url = '/bot'. $this->apiKey . '/sendMessage';
8482

8583
foreach ($this->recipients as $chatId) {
8684
$params = [
87-
'chat_id' => $chatId,
88-
'text' => $message,
85+
'chat_id' => $chatId,
86+
'text' => $message,
8987
'parse_mode' => 'Markdown',
9088
];
9189

92-
$http->post($uri, json_encode($params));
90+
$client->post(('https://api.telegram.org' . $url), [
91+
'headers' => [
92+
'Content-Type' => 'application/json',
93+
],
94+
'json' => $params,
95+
]);
9396

9497
if ($this->sendLog) {
9598
$params = [
96-
'chat_id' => $chatId,
97-
'text' => $this->buildMsg,
99+
'chat_id' => $chatId,
100+
'text' => $this->buildMsg,
98101
'parse_mode' => 'Markdown',
99102
];
100103

101-
$http->post($uri, json_encode($params));
104+
$client->post(('https://api.telegram.org' . $url), [
105+
'headers' => [
106+
'Content-Type' => 'application/json',
107+
],
108+
'json' => $params,
109+
]);
102110
}
103111
}
104112

@@ -112,13 +120,13 @@ public function execute()
112120
private function buildMessage()
113121
{
114122
$this->buildMsg = '';
115-
$buildIcon = $this->build->isSuccessful() ? '' : '';
116-
$buildLog = $this->build->getLog();
117-
$buildLog = str_replace(['[0;32m', '[0;31m', '[0m', '/[0m'], '', $buildLog);
118-
$buildMessages = explode('RUNNING PLUGIN: ', $buildLog);
123+
$buildIcon = $this->build->isSuccessful() ? '' : '';
124+
$buildLog = $this->build->getLog();
125+
$buildLog = str_replace(['[0;32m', '[0;31m', '[0m', '/[0m'], '', $buildLog);
126+
$buildMessages = explode('RUNNING PLUGIN: ', $buildLog);
119127

120128
foreach ($buildMessages as $bm) {
121-
$pos = mb_strpos($bm, "\n");
129+
$pos = mb_strpos($bm, "\n");
122130
$firstRow = mb_substr($bm, 0, $pos);
123131

124132
//skip long outputs

0 commit comments

Comments
 (0)