Skip to content

Commit

Permalink
Version 0.10.0, PHP 8 tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
noplanman committed Jun 14, 2021
1 parent 2a80ae3 commit e45b1bb
Show file tree
Hide file tree
Showing 14 changed files with 276 additions and 225 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c

## [Unreleased]
### Added
- Rules notice to use Pastebin instead of posting code directly.
### Changed
### Deprecated
### Removed
### Fixed
### Security

## [0.10.0] - 2021-06-14
### Added
- Rules notice to use Pastebin instead of posting code directly.
### Changed
- Bumped to manager 1.7.0 and core 0.73.
- Various code tweaks, make use of PHP 8.
### Security
- Bumped dependencies.

## [0.9.0] - 2021-03-14
### Changed
- Moved to PHP 8.
Expand Down
16 changes: 6 additions & 10 deletions commands/CallbackqueryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CallbackqueryCommand extends SystemCommand
/**
* @var string
*/
protected $version = '0.1.0';
protected $version = '0.2.0';

/**
* Command execute method
Expand All @@ -50,14 +50,10 @@ public function execute(): ServerResponse
$callback_query = $this->getCallbackQuery();
parse_str($callback_query->getData(), $callback_data);

if ('donate' === $callback_data['command']) {
return DonateCommand::handleCallbackQuery($callback_query, $callback_data);
}

if ('rules' === $callback_data['command']) {
return RulesCommand::handleCallbackQuery($callback_query, $callback_data);
}

return $callback_query->answer();
return match ($callback_data['command'] ?? null) {
'donate' => DonateCommand::handleCallbackQuery($callback_query, $callback_data),
'rules' => RulesCommand::handleCallbackQuery($callback_query, $callback_data),
default => $callback_query->answer(),
};
}
}
10 changes: 6 additions & 4 deletions commands/DonateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
use function TelegramBot\SupportBot\cache;

/**
* User "/donate" command
*
* Donate using Telegram Payments.
*/
class DonateCommand extends UserCommand
Expand All @@ -51,7 +53,7 @@ class DonateCommand extends UserCommand
/**
* @var string
*/
protected $version = '0.1.0';
protected $version = '0.1.1';

/**
* @var bool
Expand Down Expand Up @@ -192,7 +194,7 @@ public static function createPaymentInvoice(int $chat_id, int $amount, string $c
* @return array|ServerResponse
* @throws TelegramException
*/
protected function validateCurrencyFetching()
protected function validateCurrencyFetching(): array|ServerResponse
{
if ($currencies = $this->fetchCurrenciesFromTelegram()) {
return $currencies;
Expand All @@ -216,7 +218,7 @@ protected function validateCurrencyFetching()
* @return array|ServerResponse
* @throws TelegramException
*/
protected function validateCurrency(string $currency_code)
protected function validateCurrency(string $currency_code): array|ServerResponse
{
$currencies = $this->fetchCurrenciesFromTelegram();

Expand Down Expand Up @@ -244,7 +246,7 @@ protected function validateCurrency(string $currency_code)
* @return int|ServerResponse
* @throws TelegramException
*/
protected function validateAmount(string $amount, array $currency)
protected function validateAmount(string $amount, array $currency): int|ServerResponse
{
$int_amount = (int) ceil((float) $amount);

Expand Down
2 changes: 1 addition & 1 deletion commands/NewchatmembersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
use TelegramBot\SupportBot\Helpers;

/**
* New chat members command
* Send a welcome message to new chat members.
*/
class NewchatmembersCommand extends SystemCommand
{
Expand Down
5 changes: 4 additions & 1 deletion commands/PreCheckoutQueryCommand.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?php

namespace Longman\TelegramBot\Commands\UserCommands;
namespace Longman\TelegramBot\Commands\SystemCommands;

use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Entities\ServerResponse;

/**
* No pre-checkout checks required at this point, just approve.
*/
class PreCheckoutQueryCommand extends SystemCommand
{
/**
Expand Down
13 changes: 8 additions & 5 deletions commands/RulesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

/**
* User "/rules" command
*
* Display the rules of the support group.
* Provide an inline button for the user to agree to the rules.
*/
class RulesCommand extends UserCommand
{
Expand All @@ -41,7 +44,7 @@ class RulesCommand extends UserCommand
/**
* @var string
*/
protected $version = '0.1.0';
protected $version = '0.2.0';

/**
* @var string
Expand Down Expand Up @@ -109,19 +112,19 @@ public static function handleCallbackQuery(CallbackQuery $callback_query, array
public function execute(): ServerResponse
{
$text = "
Rules: `English only | No Spamming or Nonsense Posting | No Bots`
Rules: `English only | No Spam | No Bots | No long Code`
**:uk: English only**
Please keep your conversations in English inside this chatroom, otherwise your message will be deleted.
**:do_not_litter: No Spamming or Nonsense Posting**
Don't spam or send Messages with useless Content. When repeated you may be kicked or banned.
Don't spam or send Messages with useless Content. When repeated, you may be kicked or banned.
**:robot: No Bots**
Please do not add a Bot inside this Chat without asking the Admins first. Feel free to mention the Bot in a Message
**:paper: Use Pastebin to post Source Code**
If you want to share your Code for troubleshooting, please upload it to [Pastebin](https://pastebin.com) and post the link. Don't send longer code parts directly in the Chat.
**:memo: Use Pastebin to post Source Code**
If you want to share your Code for troubleshooting, please upload it to [Pastebin](https://pastebin.com) and post the link. Don't send long code parts directly in the Chat.
Also keep in mind that the [PHP Telegram Bot Support Chat](https://t.me/PHP_Telegram_Bot_Support) applies only for the [PHP Telegram Bot library](https://github.com/php-telegram-bot/core).
";
Expand Down
19 changes: 9 additions & 10 deletions commands/StartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@

declare(strict_types=1);

namespace Longman\TelegramBot\Commands\SystemCommands;
namespace Longman\TelegramBot\Commands\UserCommands;

use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Exception\TelegramException;

/**
* System "/start" command
*/
class StartCommand extends SystemCommand
class StartCommand extends UserCommand
{
/**
* @var string
Expand All @@ -35,7 +35,7 @@ class StartCommand extends SystemCommand
/**
* @var string
*/
protected $version = '0.1.0';
protected $version = '0.2.0';

/**
* @var string
Expand All @@ -53,14 +53,13 @@ class StartCommand extends SystemCommand
*/
public function execute(): ServerResponse
{
if ('activate' === $this->getMessage()->getText(true)) {
return $this->getTelegram()->executeCommand('activate');
}
$text = $this->getMessage()->getText(true);

if ('rules' === $this->getMessage()->getText(true)) {
return $this->getTelegram()->executeCommand('rules');
// Fall back to /help command.
if (!in_array($text, ['activate', 'rules'])) {
$text = 'help';
}

return $this->getTelegram()->executeCommand('help');
return $this->getTelegram()->executeCommand($text);
}
}
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@
"php": "^8.0",
"ext-json": "*",
"ext-pdo": "*",
"php-telegram-bot/telegram-bot-manager": "^1.6",
"longman/telegram-bot": "0.71.0 as 0.70",
"php-telegram-bot/telegram-bot-manager": "^1.7",
"longman/telegram-bot": "0.73.0 as 0.73",
"noplanman/service-webhook-handler": "^0.2",
"vlucas/phpdotenv": "^5.3",
"elvanto/litemoji": "^4.0",
"monolog/monolog": "^2.2",
"matthiasmullie/scrapbook": "^1.4",
"knplabs/github-api": "^3.1",
"guzzlehttp/guzzle": "^7.2",
"knplabs/github-api": "^3.3",
"guzzlehttp/guzzle": "^7.3",
"http-interop/http-factory-guzzle": "^1.0"
},
"require-dev": {
"roave/security-advisories": "dev-master",
"squizlabs/php_codesniffer": "^3.5",
"php-parallel-lint/php-parallel-lint": "^1.2",
"symfony/var-dumper": "^5.2"
"squizlabs/php_codesniffer": "^3.6",
"php-parallel-lint/php-parallel-lint": "^1.3",
"symfony/var-dumper": "^5.3"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit e45b1bb

Please sign in to comment.