Commit 583799ab authored by MBoretto's avatar MBoretto

Merge branch 'master' into develop

parents b1b32ed2 cdbec9fe
root = true
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
...@@ -12,11 +12,11 @@ before_install: ...@@ -12,11 +12,11 @@ before_install:
- composer self-update - composer self-update
install: install:
- travis_retry composer install --no-interaction --prefer-source - travis_retry composer install --no-interaction
script: script:
- phpunit - vendor/bin/phpunit
- sh -c "if [ '$TRAVIS_PHP_VERSION' != '7.0' ]; then vendor/bin/phpcs --report=full --extensions=php -p --standard=build/phpcs .; fi" - sh -c "if [ '$TRAVIS_PHP_VERSION' != '7.0' ]; then vendor/bin/phpcs --report=full --extensions=php -np --standard=build/phpcs .; fi"
matrix: matrix:
allow_failures: allow_failures:
......
...@@ -5,11 +5,11 @@ Before you contribute code to php-telegram-bot, please make sure it conforms to ...@@ -5,11 +5,11 @@ Before you contribute code to php-telegram-bot, please make sure it conforms to
cd php-telegram-bot cd php-telegram-bot
composer update composer update
vendor/bin/phpcs --report=full --extensions=php -p --standard=build/phpcs . vendor/bin/phpcs --report=full --extensions=php -np --standard=build/phpcs .
Which should give you no output, indicating that there are no coding standard errors. And then: Which should give you no output, indicating that there are no coding standard errors. And then:
phpunit vendor/bin/phpunit
Which should give you no failures or errors. You can ignore any skipped tests as these are for external tools. Which should give you no failures or errors. You can ignore any skipped tests as these are for external tools.
......
The MIT License (MIT) The [MIT License](http://opensource.org/licenses/mit-license.php)
Copyright (c) 2015 Avtandil Kikabidze aka LONGMAN Copyright (c) 2015 [Avtandil Kikabidze aka LONGMAN](https://github.com/akalongman)
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
......
# PHP Telegram Bot # PHP Telegram Bot
[![Join the chat at [![Join the chat at https://gitter.im/akalongman/php-telegram-bot](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/akalongman/php-telegram-bot?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
https://gitter.im/akalongman/php-telegram-bot](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/akalongman/php-telegram-bot?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Build Status](https://travis-ci.org/akalongman/php-telegram-bot.svg?branch=master)](https://travis-ci.org/akalongman/php-telegram-bot) [![Build Status](https://travis-ci.org/akalongman/php-telegram-bot.svg?branch=master)](https://travis-ci.org/akalongman/php-telegram-bot)
[![Latest Stable [![Latest Stable Version](https://img.shields.io/packagist/v/Longman/telegram-bot.svg)](https://packagist.org/packages/longman/telegram-bot)
Version](https://img.shields.io/packagist/v/Longman/telegram-bot.svg)](https://packagist.org/packages/longman/telegram-bot)
[![Total Downloads](https://img.shields.io/packagist/dt/Longman/telegram-bot.svg)](https://packagist.org/packages/longman/telegram-bot) [![Total Downloads](https://img.shields.io/packagist/dt/Longman/telegram-bot.svg)](https://packagist.org/packages/longman/telegram-bot)
[![Downloads Month](https://img.shields.io/packagist/dm/Longman/telegram-bot.svg)](https://packagist.org/packages/longman/telegram-bot) [![Downloads Month](https://img.shields.io/packagist/dm/Longman/telegram-bot.svg)](https://packagist.org/packages/longman/telegram-bot)
[![License](https://img.shields.io/packagist/l/Longman/telegram-bot.svg)](https://packagist.org/packages/longman/telegram-bot) [![License](https://img.shields.io/packagist/l/Longman/telegram-bot.svg)](https://github.com/akalongman/php-telegram-bot/LICENSE.md)
A Telegram Bot based on the official [Telegram Bot A Telegram Bot based on the official [Telegram Bot API](https://core.telegram.org/bots/api)
API](https://core.telegram.org/bots/api)
### Introduction ### Introduction
...@@ -102,7 +99,7 @@ Create *composer.json* file: ...@@ -102,7 +99,7 @@ Create *composer.json* file:
"name": "yourproject/yourproject", "name": "yourproject/yourproject",
"type": "project", "type": "project",
"require": { "require": {
"php": ">=5.4.0", "php": ">=5.5.0",
"longman/telegram-bot": "*" "longman/telegram-bot": "*"
} }
} }
...@@ -127,7 +124,7 @@ The bot can handle updates with **webhook** or **getUpdate** method: ...@@ -127,7 +124,7 @@ The bot can handle updates with **webhook** or **getUpdate** method:
## Webhook installation ## Webhook installation
You need server with https and composer support. You need server with https and composer support.
You must set a [WebHook](https://core.telegram.org/bots/api#setwebhook). You must set a [WebHook](https://core.telegram.org/bots/api#setwebhook).
Create *set.php* (just edit *example-set.php*) and put into it: Create *set.php* (just copy and edit *examples/set.php*) and put into it:
```php ```php
<?php <?php
//Composer Loader //Composer Loader
...@@ -151,7 +148,7 @@ try { ...@@ -151,7 +148,7 @@ try {
And open your *set.php* via browser. And open your *set.php* via browser.
After, create *hook.php* (or just edit *example-hook.php*) and put: After, create *hook.php* (or just copy and edit *examples/hook.php*) and put:
```php ```php
<?php <?php
$loader = require __DIR__.'/vendor/autoload.php'; $loader = require __DIR__.'/vendor/autoload.php';
...@@ -180,7 +177,7 @@ $result = $telegram->setWebHook($url, $certificate_path); ...@@ -180,7 +177,7 @@ $result = $telegram->setWebHook($url, $certificate_path);
## getUpdate installation ## getUpdate installation
You need the database Mysql active. You need the database Mysql active.
Create *getUpdateCLI.php* (just edit *example-getUpdateCLI.php*) and put into it: Create *getUpdateCLI.php* (just copy and edit *examples/getUpdateCLI.php*) and put into it:
```php ```php
#!/usr/bin/env php #!/usr/bin/env php
<?php <?php
...@@ -302,7 +299,7 @@ $COMMANDS_FOLDER = __DIR__.'/Commands/'; ...@@ -302,7 +299,7 @@ $COMMANDS_FOLDER = __DIR__.'/Commands/';
$telegram->addCommandsPath($COMMANDS_FOLDER); $telegram->addCommandsPath($COMMANDS_FOLDER);
``` ```
Inside *CommandsExamples/* there are some sample that show how to use types. Inside *examples/Commands/* there are some sample that show how to use types.
### Admin Commands ### Admin Commands
Enabling this feature, the admin bot can perform some super user command like: Enabling this feature, the admin bot can perform some super user command like:
...@@ -352,15 +349,24 @@ $telegram->setLogVerbosity(3); ...@@ -352,15 +349,24 @@ $telegram->setLogVerbosity(3);
----- -----
This code is available on This code is available on
[Github](https://github.com/akalongman/php-telegram-bot). Pull [Github](https://github.com/akalongman/php-telegram-bot). Pull requests are welcome.
requests are welcome.
## Troubleshooting ## Troubleshooting
If you like living on the edge, please report any bugs you find on the If you like living on the edge, please report any bugs you find on the
[PHP Telegram Bot [PHP Telegram Bot issues](https://github.com/akalongman/php-telegram-bot/issues) page.
issues](https://github.com/akalongman/php-telegram-bot/issues) page.
## Contributing ## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md) for information. See [CONTRIBUTING.md](CONTRIBUTING.md) for information.
## License
Please see the [LICENSE](LICENSE.md) included in this repository for a full copy of the MIT license,
which this project is licensed under.
## Credits ## Credits
Credit list in [CREDITS](CREDITS) Credit list in [CREDITS](CREDITS)
2015-11-24 20:08:51 exception 'Longman\TelegramBot\Exception\TelegramException' with message 'Bot Username not defined!' in /media/D/applications/repositories/php-telegram-bot/src/Telegram.php:168
Stack trace:
#0 /media/D/applications/repositories/php-telegram-bot/tests/Unit/TelegramTest.php(43): Longman\TelegramBot\Telegram->__construct('testapikey', NULL)
#1 [internal function]: Tests\Unit\TelegramTest->newInstanceWithoutParams()
#2 phar:///usr/local/bin/phpunit/phpunit/Framework/TestCase.php(908): ReflectionMethod->invokeArgs(Object(Tests\Unit\TelegramTest), Array)
#3 phar:///usr/local/bin/phpunit/phpunit/Framework/TestCase.php(771): PHPUnit_Framework_TestCase->runTest()
#4 phar:///usr/local/bin/phpunit/phpunit/Framework/TestResult.php(617): PHPUnit_Framework_TestCase->runBare()
#5 phar:///usr/local/bin/phpunit/phpunit/Framework/TestCase.php(727): PHPUnit_Framework_TestResult->run(Object(Tests\Unit\TelegramTest))
#6 phar:///usr/local/bin/phpunit/phpunit/Framework/TestSuite.php(747): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult))
#7 phar:///usr/local/bin/phpunit/phpunit/Framework/TestSuite.php(747): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#8 phar:///usr/local/bin/phpunit/phpunit/TextUI/TestRunner.php(425): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#9 phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php(154): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array)
#10 phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php(105): PHPUnit_TextUI_Command->run(Array, true)
#11 /usr/local/bin/phpunit(509): PHPUnit_TextUI_Command::main()
#12 {main}
2015-11-24 20:31:17 exception 'Longman\TelegramBot\Exception\TelegramException' with message 'Bot Username not defined!' in /media/D/applications/repositories/php-telegram-bot/src/Telegram.php:168
Stack trace:
#0 /media/D/applications/repositories/php-telegram-bot/tests/Unit/TelegramTest.php(43): Longman\TelegramBot\Telegram->__construct('testapikey', NULL)
#1 [internal function]: Tests\Unit\TelegramTest->newInstanceWithoutParams()
#2 phar:///usr/local/bin/phpunit/phpunit/Framework/TestCase.php(908): ReflectionMethod->invokeArgs(Object(Tests\Unit\TelegramTest), Array)
#3 phar:///usr/local/bin/phpunit/phpunit/Framework/TestCase.php(771): PHPUnit_Framework_TestCase->runTest()
#4 phar:///usr/local/bin/phpunit/phpunit/Framework/TestResult.php(617): PHPUnit_Framework_TestCase->runBare()
#5 phar:///usr/local/bin/phpunit/phpunit/Framework/TestCase.php(727): PHPUnit_Framework_TestResult->run(Object(Tests\Unit\TelegramTest))
#6 phar:///usr/local/bin/phpunit/phpunit/Framework/TestSuite.php(747): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult))
#7 phar:///usr/local/bin/phpunit/phpunit/Framework/TestSuite.php(747): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#8 phar:///usr/local/bin/phpunit/phpunit/TextUI/TestRunner.php(425): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#9 phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php(154): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array)
#10 phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php(105): PHPUnit_TextUI_Command->run(Array, true)
#11 /usr/local/bin/phpunit(509): PHPUnit_TextUI_Command::main()
#12 {main}
...@@ -13,13 +13,18 @@ ...@@ -13,13 +13,18 @@
<!-- Exclude 3rd party libraries and Framework code. --> <!-- Exclude 3rd party libraries and Framework code. -->
<exclude-pattern type="relative">vendor/*</exclude-pattern> <exclude-pattern type="relative">vendor/*</exclude-pattern>
<!-- Include all sniffs in an external standard directory --> <arg name="colors"/>
<!-- Include some additional sniffs from the Generic standard --> <!-- Include some additional sniffs from the Generic standard -->
<rule ref="PSR2"> <rule ref="PSR2">
<exclude name="PEAR.Functions.FunctionCallSignature"/> <exclude name="PEAR.Functions.FunctionCallSignature"/>
<exclude name="PEAR.Functions.FunctionCallSignature.SpaceAfterCloseBracket"/> <exclude name="PEAR.Functions.FunctionCallSignature.SpaceAfterCloseBracket"/>
</rule> </rule>
<rule ref="Generic.Files.LineLength">
<properties>
<property phpcs-only="true" name="lineLimit" value="100"/>
<property phpcbf-only="true" name="lineLimit" value="120"/>
</properties>
</rule>
</ruleset> </ruleset>
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
{ {
"name": "Avtandil Kikabidze aka LONGMAN", "name": "Avtandil Kikabidze aka LONGMAN",
"email": "akalongman@gmail.com", "email": "akalongman@gmail.com",
"homepage": "http://longman.ge", "homepage": "http://longman.me",
"role": "Developer" "role": "Developer"
} }
], ],
...@@ -32,10 +32,9 @@ ...@@ -32,10 +32,9 @@
"Tests\\": "tests/" "Tests\\": "tests/"
} }
}, },
"minimum-stability": "dev",
"require-dev": { "require-dev": {
"phpunit/phpunit": "4.1.*", "phpunit/phpunit": "~4.1",
"phpspec/phpspec": "~2.1", "phpspec/phpspec": "~2.1",
"squizlabs/php_codesniffer": "2.3.*" "squizlabs/php_codesniffer": "~2.3"
} }
} }
This diff is collapsed.
...@@ -4,12 +4,18 @@ ...@@ -4,12 +4,18 @@
#while true; do ./getUpdatesCLI.php; done #while true; do ./getUpdatesCLI.php; done
//Composer Loader //Composer Loader
$loader = require __DIR__.'/vendor/autoload.php'; $dir = realpath(__DIR__.'/..');
$loader = require $dir.'/vendor/autoload.php';
$API_KEY = 'your_bot_api_key'; $API_KEY = 'your_bot_api_key';
$BOT_NAME = 'namebot'; $BOT_NAME = 'namebot';
//$COMMANDS_FOLDER = __DIR__.'/Commands/'; //$COMMANDS_FOLDER = __DIR__.'/Commands/';
$credentials = array('host'=>'localhost', 'user'=>'dbuser', 'password'=>'dbpass', 'database'=>'dbname'); $credentials = array(
'host'=>'localhost',
'user'=>'dbuser',
'password'=>'dbpass',
'database'=>'dbname'
);
try { try {
// create Telegram API object // create Telegram API object
......
<?php <?php
//Composer Loader //Composer Loader
$loader = require __DIR__.'/vendor/autoload.php'; $dir = realpath(__DIR__.'/..');
$loader = require $dir.'/vendor/autoload.php';
$API_KEY = 'your_bot_api_key'; $API_KEY = 'your_bot_api_key';
$BOT_NAME = 'namebot'; $BOT_NAME = 'namebot';
//$COMMANDS_FOLDER = __DIR__.'/Commands/'; //$COMMANDS_FOLDER = __DIR__.'/Commands/';
//$credentials = array('host'=>'localhost', 'user'=>'dbuser', 'password'=>'dbpass', 'database'=>'dbname'); /*$credentials = array(
'host'=>'localhost',
'user'=>'dbuser',
'password'=>'dbpass',
'database'=>'dbname'
);*/
try { try {
// create Telegram API object // create Telegram API object
......
<?php <?php
//Composer Loader //Composer Loader
$loader = require __DIR__.'/vendor/autoload.php'; $dir = realpath(__DIR__.'/..');
$loader = require $dir.'/vendor/autoload.php';
$API_KEY = 'your_bot_api_key'; $API_KEY = 'your_bot_api_key';
$BOT_NAME = 'namebot'; $BOT_NAME = 'namebot';
......
...@@ -57,7 +57,8 @@ abstract class Command ...@@ -57,7 +57,8 @@ abstract class Command
abstract public function execute(); abstract public function execute();
//this methods is executed if $need_mysql is true but DB connection for some reason is not avaiable // this methods is executed if $need_mysql is true
// but DB connection for some reason is not avaiable
public function executeNoDB() public function executeNoDB()
{ {
......
...@@ -199,15 +199,7 @@ class Message extends Entity ...@@ -199,15 +199,7 @@ class Message extends Entity
public function getFullCommand() public function getFullCommand()
{ {
if (substr($this->text, 0, 1) === '/') { if (substr($this->text, 0, 1) === '/') {
$no_EOL = strtok($this->text, PHP_EOL); return strtok($this->text, ' ');
$no_space = strtok($this->text, ' ');
//try to understand which separator \n or space divide /command from text
if (strlen($no_space) < strlen($no_EOL)) {
return $no_space;
} else {
return $no_EOL;
}
} else { } else {
return; return;
} }
...@@ -281,8 +273,7 @@ class Message extends Entity ...@@ -281,8 +273,7 @@ class Message extends Entity
if ($without_cmd) { if ($without_cmd) {
$command = $this->getFullCommand(); $command = $this->getFullCommand();
if (!empty($command)) { if (!empty($command)) {
//$text = substr($text, strlen($command.' '), strlen($text)); $text = substr($text, strlen($command.' '), strlen($text));
$text = substr($text, strlen($command) + 1, strlen($text));
} }
} }
......
...@@ -17,7 +17,11 @@ class TelegramException extends \Exception ...@@ -17,7 +17,11 @@ class TelegramException extends \Exception
parent::__construct($message, $code); parent::__construct($message, $code);
$path = 'TelegramException.log'; $path = 'TelegramException.log';
$status = file_put_contents($path, date('Y-m-d H:i:s', time()) .' '. self::__toString() . "\n", FILE_APPEND); $status = file_put_contents(
$path,
date('Y-m-d H:i:s', time()) .' '. self::__toString() . "\n",
FILE_APPEND
);
} }
} }
...@@ -100,7 +100,12 @@ class Request ...@@ -100,7 +100,12 @@ class Request
if (isset($data['chat_id'])) { if (isset($data['chat_id'])) {
$data['message_id'] = '1234'; $data['message_id'] = '1234';
$data['date'] = '1441378360'; $data['date'] = '1441378360';
$data['from'] = array( 'id' => 123456789 ,'first_name' => 'botname', 'username'=> 'namebot'); $data['from'] = array(
'id' => 123456789,
'first_name' =>
'botname',
'username'=> 'namebot'
);
$data['chat'] = array('id'=> $data['chat_id'] ); $data['chat'] = array('id'=> $data['chat_id'] );
$fake_response['result'] = $data; $fake_response['result'] = $data;
...@@ -152,7 +157,9 @@ class Request ...@@ -152,7 +157,9 @@ class Request
//Logging getUpdates Update //Logging getUpdates Update
//Logging curl updates //Logging curl updates
if ($action == 'getUpdates' & self::$telegram->getLogVerbosity() >=1 | self::$telegram->getLogVerbosity() >=3) { if ($action == 'getUpdates'
& self::$telegram->getLogVerbosity() >=1
| self::$telegram->getLogVerbosity() >=3) {
self::setInputRaw($result); self::setInputRaw($result);
self::log($result); self::log($result);
} }
......
<?php <?php
/* /*
* This file is part of the TelegramBot package. * This file is part of the TelegramBot package.
* *
...@@ -30,7 +29,7 @@ class Telegram ...@@ -30,7 +29,7 @@ class Telegram
* *
* @var string * @var string
*/ */
protected $version = '0.21.1'; protected $version = '0.20.2';
/** /**
* Telegram API key * Telegram API key
...@@ -537,6 +536,7 @@ class Telegram ...@@ -537,6 +536,7 @@ class Telegram
//$str[0] = strtolower($str[0]); //$str[0] = strtolower($str[0]);
return $str; return $str;
} }
/** /**
* Enable Admin Account * Enable Admin Account
* *
...@@ -550,7 +550,7 @@ class Telegram ...@@ -550,7 +550,7 @@ class Telegram
if ($admin > 0) { if ($admin > 0) {
$this->admins_list[] = $admin; $this->admins_list[] = $admin;
} else { } else {
throw new TelegramException('Only users can be admin not chat!'); throw new TelegramException('Invalid value "'.$admin.'" for admin!');
} }
} }
...@@ -564,7 +564,6 @@ class Telegram ...@@ -564,7 +564,6 @@ class Telegram
* *
* @return bool * @return bool
*/ */
public function isDbEnabled() public function isDbEnabled()
{ {
if ($this->mysql_enabled) { if ($this->mysql_enabled) {
......
...@@ -86,26 +86,5 @@ class MessageTest extends TestCase ...@@ -86,26 +86,5 @@ class MessageTest extends TestCase
$this->assertEquals('help', $this->message->getCommand()); $this->assertEquals('help', $this->message->getCommand());
$this->assertEquals('/help@testbot some text', $this->message->getText()); $this->assertEquals('/help@testbot some text', $this->message->getText());
$this->assertEquals('some text', $this->message->getText(true)); $this->assertEquals('some text', $this->message->getText(true));
// /commmad\n text
$this->message = new Message($this->generateMessage("/help\n some text"), 'testbot');
$this->assertEquals('/help', $this->message->getFullCommand());
$this->assertEquals('help', $this->message->getCommand());
$this->assertEquals("/help\n some text", $this->message->getText());
$this->assertEquals(' some text', $this->message->getText(true));
// /command@bot\nsome text
$this->message = new Message($this->generateMessage("/help@testbot\nsome text"), 'testbot');
$this->assertEquals('/help@testbot', $this->message->getFullCommand());
$this->assertEquals('help', $this->message->getCommand());
$this->assertEquals("/help@testbot\nsome text", $this->message->getText());
$this->assertEquals('some text', $this->message->getText(true));
// /command@bot \nsome text
$this->message = new Message($this->generateMessage("/help@testbot \nsome text"), 'testbot');
$this->assertEquals('/help@testbot', $this->message->getFullCommand());
$this->assertEquals('help', $this->message->getCommand());
$this->assertEquals("/help@testbot \nsome text", $this->message->getText());
$this->assertEquals("\nsome text", $this->message->getText(true));
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment