44
55use PHPCensor \Builder ;
66use 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