diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..74350b724 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +/.* export-ignore +/composer.lock export-ignore +/phpcs.xml.dist export-ignore +/phpunit.xml.dist export-ignore +/tests export-ignore diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 8d4d11af8..4b9cb19e9 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,4 +1,3 @@ -github: noplanman, akalongman, jacklul tidelift: packagist/longman%2Ftelegram-bot patreon: phptelegrambot liberapay: PHP-Telegram-Bot diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index c328ce25e..000000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,26 +0,0 @@ - - - - -### Required Information - -- Operating system: -- PHP version: -- PHP Telegram Bot version: -- Using MySQL database: yes / no -- MySQL version: -- Update Method: Webhook / getUpdates -- Self-signed certificate: yes / no -- RAW update (if available): - -### Expected behaviour - - -### Actual behaviour - - -### Steps to reproduce - - -### Extra details - diff --git a/.github/ISSUE_TEMPLATE/BC_Break.md b/.github/ISSUE_TEMPLATE/BC_Break.md new file mode 100644 index 000000000..10fded9e5 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/BC_Break.md @@ -0,0 +1,55 @@ +--- +name: 💥 BC Break +about: Have you encountered an issue during an upgrade? 💣 +--- + + + +### BC Break Report + +<-- +❗ NEVER put your Telegram API key or any other private details here. (like passwords, user IDs, etc.) +Substitute them like or etc. +--> + +#### Required Information + + + + +| ? | ! +| --- | --- +| Operating system | Name and version +| PHP Telegram Bot version | x.y.z +| PHP version | x.y.z +| MySQL version | x.y.z / none +| Update Method | Webhook / getUpdates +| Self-signed certificate | yes / no +| RAW update (if available) | `{...}` + +#### Summary + + + +#### Previous behaviour + + + +#### Current behaviour + + + +#### How to reproduce + + + +#### Expected behaviour + + diff --git a/.github/ISSUE_TEMPLATE/Bug.md b/.github/ISSUE_TEMPLATE/Bug.md new file mode 100644 index 000000000..3633b4c8c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/Bug.md @@ -0,0 +1,45 @@ +--- +name: 🐞 Bug Report +about: Something is broken? 🔨 +--- + +### Bug Report + +<-- +❗ NEVER put your Telegram API key or any other private details here. (like passwords, user IDs, etc.) +Substitute them like or etc. +--> + +#### Required Information + + + + +| ? | ! +| --- | --- +| Operating system | Name and version +| PHP Telegram Bot version | x.y.z +| PHP version | x.y.z +| MySQL version | x.y.z / none +| Update Method | Webhook / getUpdates +| Self-signed certificate | yes / no +| RAW update (if available) | `{...}` + +#### Summary + + + +### Current behaviour + + + +#### How to reproduce + + + +#### Expected behaviour + + diff --git a/.github/ISSUE_TEMPLATE/Feature_Request.md b/.github/ISSUE_TEMPLATE/Feature_Request.md new file mode 100644 index 000000000..bef698bf8 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/Feature_Request.md @@ -0,0 +1,10 @@ +--- +name: 🎉 Feature Request +about: You have a neat idea that should be implemented? 🎩 +--- + +### Feature Request + +#### Summary + + diff --git a/.github/ISSUE_TEMPLATE/Support_Question.md b/.github/ISSUE_TEMPLATE/Support_Question.md new file mode 100644 index 000000000..bbe95a70e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/Support_Question.md @@ -0,0 +1,37 @@ +--- +name: ❓ Support Question +about: Have a problem that you can't figure out? 🤔 +--- + +### Support Question + + + +<-- +❗ NEVER put your Telegram API key or any other private details here. (like passwords, user IDs, etc.) +Substitute them like or etc. +--> + +#### Required Information + + + + +| ? | ! +| --- | --- +| Operating system | Name and version +| PHP Telegram Bot version | x.y.z +| PHP version | x.y.z +| MySQL version | x.y.z / none +| Update Method | Webhook / getUpdates +| Self-signed certificate | yes / no +| RAW update (if available) | `{...}` + +#### Summary + + diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 61c208f96..d75c05408 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,5 +1,19 @@ - + +Make sure this pull request is pointed towards the "develop" branch and refers to any issue that it's related to! +--> - + + +| ? | ! +|--- | --- +| Type | bug / feature / improvement +| BC Break | yes / no +| Fixed issues | + +#### Summary + + diff --git a/.gitignore b/.gitignore index c0546a714..9ab75eb2f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,28 +5,20 @@ .DS_Store .idea .phpintel -composer.phar - -# Local System Files (i.e. cache, logs, etc.) # -/cache -/build/logs -/build/coverage -/tmp - -# Test Related Files # -/phpunit.xml - -#Exception output -TelegramException.log # Composer -vendor/ +/composer.phar +/vendor +# Test-Related Files +/clover.xml +/phpcs.xml +/phpunit.xml -# phpDocumentor Logs # +# phpDocumentor Logs phpdoc-* -# OSX # +# OSX ._* .Spotlight-V100 .Trashes diff --git a/.scrutinizer.yml b/.scrutinizer.yml index e270f48b1..1e75d1133 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -38,4 +38,4 @@ checks: tools: external_code_coverage: - timeout: 120 + timeout: 300 diff --git a/.travis.yml b/.travis.yml index 1c9ef29c1..6bcadc408 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,21 +1,22 @@ -dist: trusty -sudo: required language: php +sudo: required +dist: trusty addons: mariadb: 10.1 cache: directories: - - "$HOME/.composer/cache" + - vendor + - $HOME/.composer/cache php: - - 5.5 - - 5.6 - - 7.0 - - 7.1 - - 7.2 - 7.3 + - 7.2 + - 7.1 + - 7.0 + - 5.6 + - 5.5 - nightly - hhvm @@ -44,7 +45,7 @@ before_script: script: - composer check-code - - if [ "$TRAVIS_PHP_VERSION" == "7.2" ] ; then composer test-cov; else composer test; fi + - if [ "$TRAVIS_PHP_VERSION" == "7.3" ]; then composer test-cov; else composer test; fi after_script: - - if [ "$TRAVIS_PHP_VERSION" == "7.2" ]; then composer test-cov-upload; fi + - if [ "$TRAVIS_PHP_VERSION" == "7.3" ]; then composer test-cov-upload; fi diff --git a/.github/CONTRIBUTING.md b/CONTRIBUTING.md similarity index 83% rename from .github/CONTRIBUTING.md rename to CONTRIBUTING.md index 2f777b688..5e18c7b73 100644 --- a/.github/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,37 +1,37 @@ -Contributing -------------- +# Contributing The easiest way to contribute is to work on a checkout of your own fork. When working on the `core` repository, it makes sense to rename your fork to `php-telegram-bot`. -Before you contribute code, please make sure it conforms to the PSR-2 coding standard and that the unit tests still pass. +Before you contribute code, please make sure it conforms to the PSR-12 coding standard and that the unit tests still pass. You can run the following commands to check if everything is ready to submit: - cd php-telegram-bot - composer install - composer check-code +```bash +cd php-telegram-bot +composer install +composer check-code +``` Which should give you no output, indicating that there are no coding standard errors. And then (remember to set up your test database!): - composer test +```bash +composer test +``` Which should give you no failures or errors. You can ignore any skipped tests as these are for external tools. -Pushing -------- +## Pushing Development is based on the git flow branching model (see http://nvie.com/posts/a-successful-git-branching-model/) If you fix a bug please push in hotfix branch. If you develop a new feature please create a new branch. -Version -------- +## Version Version number: 0.#version.#hotfix -Further code convention adopted -------------------------------- +## Further code convention adopted - Each method and class is documented with a docblock diff --git a/README.md b/README.md index e4f5b6766..3c4f2af83 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,19 @@ +PHP Telegram Bot logo + # PHP Telegram Bot +A Telegram Bot based on the official [Telegram Bot API][Telegram-Bot-API] + [![Join the bot support group on Telegram](https://img.shields.io/badge/telegram-@PHP__Telegram__Bot__Support-32a2da.svg)](https://telegram.me/PHP_Telegram_Bot_Support) [![Donate](https://img.shields.io/badge/%F0%9F%92%99-Donate-blue.svg)](#donate) [![Build Status](https://travis-ci.org/php-telegram-bot/core.svg?branch=master)](https://travis-ci.org/php-telegram-bot/core) [![Dependencies](https://tidelift.com/badges/github/php-telegram-bot/core)][Tidelift] -[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/php-telegram-bot/core/develop.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-telegram-bot/core/?b=develop) -[![Code Quality](https://img.shields.io/scrutinizer/g/php-telegram-bot/core/develop.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-telegram-bot/core/?b=develop) -[![Latest Stable 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) -[![Downloads Month](https://img.shields.io/packagist/dm/Longman/telegram-bot.svg)](https://packagist.org/packages/longman/telegram-bot) +[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/php-telegram-bot/core/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-telegram-bot/core/?b=master) +[![Code Quality](https://img.shields.io/scrutinizer/g/php-telegram-bot/core/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-telegram-bot/core/?b=master) +[![Latest Stable 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) +[![Downloads Month](https://img.shields.io/packagist/dm/longman/telegram-bot.svg)](https://packagist.org/packages/longman/telegram-bot) [![Minimum PHP Version](http://img.shields.io/badge/php-%3E%3D5.6-8892BF.svg)](https://php.net/) [![License](https://img.shields.io/packagist/l/longman/telegram-bot.svg)](https://github.com/php-telegram-bot/core/LICENSE) @@ -23,10 +27,11 @@ A Telegram Bot based on the official [Telegram Bot API][Telegram-Bot-API] - [Create your first bot](#create-your-first-bot) - [Require this package with Composer](#require-this-package-with-composer) - [Choose how to retrieve Telegram updates](#choose-how-to-retrieve-telegram-updates) - - [Webhook installation](#webhook-installation) +- [Webhook installation](#webhook-installation) - [Self Signed Certificate](#self-signed-certificate) - [Unset Webhook](#unset-webhook) - - [getUpdates installation](#getupdates-installation) +- [getUpdates installation](#getupdates-installation) + - [getUpdates without database](#getupdates-without-database) - [Support](#support) - [Types](#types) - [Inline Query](#inline-query) @@ -39,14 +44,15 @@ A Telegram Bot based on the official [Telegram Bot API][Telegram-Bot-API] - [Send message to all active chats](#send-message-to-all-active-chats) - [Utils](#utils) - [MySQL storage (Recommended)](#mysql-storage-recommended) + - [External Database connection](#external-database-connection) - [Channels Support](#channels-support) - [Commands](#commands) - [Predefined Commands](#predefined-commands) - [Custom Commands](#custom-commands) - [Commands Configuration](#commands-configuration) -- [Admin Commands](#admin-commands) - - [Set Admins](#set-admins) - - [Channel Administration](#channel-administration) + - [Admin Commands](#admin-commands) + - [Set Admins](#set-admins) + - [Channel Administration](#channel-administration) - [Upload and Download directory path](#upload-and-download-directory-path) - [Logging](doc/01-utils.md) - [Documentation](#documentation) @@ -180,7 +186,7 @@ composer require longman/telegram-bot ### Choose how to retrieve Telegram updates -The bot can handle updates with **Webhook** or **getUpdates** method: +The bot can handle updates with [**Webhook**](#webhook-installation) or [**getUpdates**](#getupdates-installation) method: | | Webhook | getUpdates | | ---- | :----: | :----: | @@ -188,7 +194,6 @@ The bot can handle updates with **Webhook** or **getUpdates** method: | Host with https | Required | Not required | | MySQL | Not required | ([Not](#getupdates-without-database)) Required | - ## Webhook installation Note: For a more detailed explanation, head over to the [example-bot repository][example-bot-repository] and follow the instructions there. @@ -444,9 +449,9 @@ $telegram->enableExternalMySql($external_pdo_connection) All methods implemented can be used to manage channels. With [admin commands](#admin-commands) you can manage your channels directly with your bot private chat. -### Commands +## Commands -#### Predefined Commands +### Predefined Commands The bot is able to recognise commands in a chat with multiple bots (/command@mybot). @@ -472,14 +477,14 @@ Here's the list: - Favourite colour? */black, /red* - Favourite number? */1, /134* -#### Custom Commands +### Custom Commands Maybe you would like to develop your own commands. There is a guide to help you [create your own commands][wiki-create-your-own-commands]. Also, be sure to have a look at the [example commands][ExampleCommands-folder] to learn more about custom commands and how they work. -#### Commands Configuration +### Commands Configuration With this method you can set some command specific parameters, for example: @@ -548,7 +553,7 @@ $telegram->setCommandConfig('sendtochannel', [ ``` - Enjoy! -### Upload and Download directory path +## Upload and Download directory path To use the Upload and Download functionality, you need to set the paths with: ```php @@ -580,7 +585,11 @@ If you like living on the edge, please report any bugs you find on the ## Contributing -See [CONTRIBUTING](.github/CONTRIBUTING.md) for more information. +See [CONTRIBUTING](CONTRIBUTING.md) for more information. + +## Security + +See [SECURITY](SECURITY.md) for more information. ## Security @@ -599,7 +608,7 @@ Thank you for keeping this project alive :pray: - [![OpenCollective](https://user-images.githubusercontent.com/9423417/59235978-a561d500-8be3-11e9-89be-82ec54be1546.png) OpenCollective.com/php-telegram-bot][OpenCollective] - [![Ko-fi](https://user-images.githubusercontent.com/9423417/59235976-a561d500-8be3-11e9-911d-b1908c3e6a33.png) Ko-fi.com/phptelegrambot][Ko-fi] - [![Tidelift](https://user-images.githubusercontent.com/9423417/59235982-a6930200-8be3-11e9-8ac2-bfb6991d80c5.png) Tidelift.com/longman/telegram-bot][Tidelift] -- [![Liberapay](https://user-images.githubusercontent.com/9423417/59235977-a561d500-8be3-11e9-9d16-bc3b13d3ceba.png) Liberapay.com/PHP-Telegram-Bot][liberapay] +- [![Liberapay](https://user-images.githubusercontent.com/9423417/59235977-a561d500-8be3-11e9-9d16-bc3b13d3ceba.png) Liberapay.com/PHP-Telegram-Bot][Liberapay] - [![PayPal](https://user-images.githubusercontent.com/9423417/59235981-a5fa6b80-8be3-11e9-9761-15eb7a524cb0.png) PayPal.me/noplanman][PayPal-noplanman] (account of @noplanman) - [![Bitcoin](https://user-images.githubusercontent.com/9423417/59235974-a4c93e80-8be3-11e9-9fde-260c821b6eae.png) 166NcyE7nDxkRPWidWtG1rqrNJoD5oYNiV][Bitcoin] - [![Ethereum](https://user-images.githubusercontent.com/9423417/59235975-a4c93e80-8be3-11e9-8762-7a47c62c968d.png) 0x485855634fa212b0745375e593fAaf8321A81055][Ethereum] @@ -636,7 +645,7 @@ Credit list in [CREDITS](CREDITS) [OpenCollective]: https://opencollective.com/php-telegram-bot "Support us on Open Collective" [Ko-fi]: https://ko-fi.com/phptelegrambot "Support us on Ko-fi" [Tidelift]: https://tidelift.com/subscription/pkg/packagist-longman-telegram-bot?utm_source=packagist-longman-telegram-bot&utm_medium=referral&utm_campaign=readme "Support us on Tidelift" -[liberapay]: https://liberapay.com/PHP-Telegram-Bot "Donate with Liberapay" +[Liberapay]: https://liberapay.com/PHP-Telegram-Bot "Donate with Liberapay" [PayPal-noplanman]: https://paypal.me/noplanman "Donate with PayPal" [Bitcoin]: https://www.blockchain.com/btc/address/166NcyE7nDxkRPWidWtG1rqrNJoD5oYNiV "Donate with Bitcoin" [Ethereum]: https://etherscan.io/address/0x485855634fa212b0745375e593fAaf8321A81055 "Donate with Ethereum" diff --git a/build/.gitkeep b/build/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/composer.json b/composer.json index 8e683b152..b44ae7828 100644 --- a/composer.json +++ b/composer.json @@ -47,16 +47,16 @@ }, "scripts": { "check-code": [ - "\"vendor/bin/phpcs\" --standard=phpcs.xml -snp src/ tests/" + "\"vendor/bin/phpcs\" -snp src/ tests/" ], "test": [ "\"vendor/bin/phpunit\"" ], "test-cov": [ - "\"vendor/bin/phpunit\" --coverage-clover build/logs/clover.xml" + "\"vendor/bin/phpunit\" --coverage-clover clover.xml" ], "test-cov-upload": [ - "wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml" + "wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover clover.xml" ] } } diff --git a/phpcs.xml b/phpcs.xml.dist similarity index 100% rename from phpcs.xml rename to phpcs.xml.dist