Skip to content
This repository was archived by the owner on Jan 13, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Codacy Badge](https://api.codacy.com/project/badge/Grade/a58c62e4bde1485f95b52fa56a2e4320)](https://www.codacy.com/app/LEXASOFT/PHP-Censor-Telegram-Plugin)
# PHP-Censor-Telegram-Plugin
Telegram plugin for [PHP Censor](https://github.com/corpsee/php-censor)
Telegram plugin for [PHP Censor](https://github.com/php-censor/php-censor)
# Installation
First of all - `composer require lexasoft/php-censor-telegram-plugin`

Expand Down
24 changes: 21 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
{
"name": "lexasoft/php-censor-telegram-plugin",
"description": "PHP Censor plugin for Telegram",
"minimum-stability": "stable",
"type": "php-censor-plugin",
"keywords": [
"php",
"php-censor",
"testing",
"open-source",
"ci",
"continuous integration",
"telegram"
],
"homepage": "https://github.com/LEXASOFT/PHP-Censor-Telegram-Plugin",
"license": "GPL-3.0",
"authors": [
{
"name": "LEXASOFT",
"email": "lexasoft83@gmail.com"
"email": "lexasoft83@gmail.com",
"role": "Developer"
}
],
"support": {
"issues": "https://github.com/LEXASOFT/PHP-Censor-Telegram-Plugin/issues",
"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": {
"PHPCensor\\Plugin\\": "src"
}
},
"extra": {
"phpci": {
"php-censor": {
"pluginNamespace": "PHPCensor\\Plugin\\",
"suppliedPlugins": [
{
Expand Down
42 changes: 25 additions & 17 deletions src/Telegram.php
Original file line number Diff line number Diff line change
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