Skip to content

Commit

Permalink
Merge pull request #1 from nutgram/update-nutgram-to-4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
sergix44 authored May 16, 2023
2 parents 58e2b24 + c33b136 commit 443b0e2
Show file tree
Hide file tree
Showing 34 changed files with 947 additions and 718 deletions.
1 change: 0 additions & 1 deletion README.md

This file was deleted.

6 changes: 5 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ ij_php_space_after_type_cast = false
ij_php_concat_spaces = false

[*.json]
indent_size = 2
indent_size = 2

[src/Facades/Telegram.php]
max_line_length = off
ij_php_phpdoc_wrap_long_lines = false
44 changes: 36 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,36 @@
# WIP - Do not use before Nutgram 4.0

#### TODO:
- [ ] Replace namespace from "SergiX44\Nutgram" to "Nutgram"
- [ ] Bump PHP version to 8.1
- [ ] Bump Laravel version to 9.0
- [ ] Update this README.md
- [ ] Add github workflows for tests and changelog
# Nugram Package for Laravel

[![Version](https://img.shields.io/packagist/v/nutgram/laravel?label=composer&logo=composer)](https://packagist.org/packages/nutgram/laravel)
[![Total Downloads](https://img.shields.io/packagist/dt/nutgram/laravel.svg)](https://packagist.org/packages/nutgram/laravel)
![License](https://img.shields.io/github/license/nutgram/laravel)
![PHP](https://img.shields.io/packagist/dependency-v/nutgram/laravel/php?logo=php)
![Laravel](https://img.shields.io/packagist/dependency-v/nutgram/laravel/illuminate/support?label=laravel&logo=laravel)

![Tests](https://img.shields.io/github/actions/workflow/status/nutgram/laravel/php.yml?label=Test%20Suite&logo=github)
[![Test Coverage](https://api.codeclimate.com/v1/badges/feaa33a8d1431d16998d/test_coverage)](https://codeclimate.com/github/nutgram/laravel/test_coverage)
[![Maintainability](https://api.codeclimate.com/v1/badges/feaa33a8d1431d16998d/maintainability)](https://codeclimate.com/github/nutgram/laravel/maintainability)

[Nutgram](https://github.com/nutgram/nutgram) Package for Laravel 9.0+.

## Installation

You can install the package via composer:

```bash
composer require nutgram/laravel
```

## Usage

- [Official Documentation for Laravel](https://nutgram.dev/docs/configuration/laravel)

## Credits

- [Sergio Brighenti](https://github.com/SergiX44)
- [Luca Patera](https://github.com/Lukasss93)
- [All Contributors](../../contributors)

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^8.0",
"nutgram/nutgram": "^3.13"
"php": "^8.2",
"nunomaduro/termwind": "^1.15",
"nutgram/nutgram": "^4.0"
},
"require-dev": {
"illuminate/testing": "^8.0|^9.0|^10.0",
"orchestra/testbench": "^6.0|^7.0|^8.0",
"illuminate/testing": "^9.0|^10.0",
"orchestra/testbench": "^7.0|^8.0",
"pestphp/pest": "^1.1",
"pestphp/pest-plugin-mock": "^1.0",
"roave/security-advisories": "dev-latest",
Expand Down
1 change: 1 addition & 0 deletions resources/views/terminal/fail.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="text-red-500 mx-2 my-1">{{$value}}</div>
12 changes: 12 additions & 0 deletions resources/views/terminal/list.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@


<div class="mx-2 my-1">
@foreach($items as $item)
<div class="flex space-x-1">
<span class="text-yellow">{{$item['handler']}}</span>
<span class="text-gray">{{$item['pattern']}}</span>
<span class="flex-1 content-repeat-['.']"></span>
<span class="text-blue">{{$item['callable']}}</span>
</div>
@endforeach
</div>
1 change: 1 addition & 0 deletions resources/views/terminal/success.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="text-green-500 mx-2 my-1">{{$value}}</div>
9 changes: 9 additions & 0 deletions resources/views/terminal/table.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="mx-2 my-1">
@foreach($items as $key => $value)
<div class="flex space-x-1">
<span class="text-yellow">{{$key}}</span>
<span class="flex-1 content-repeat-['.']"></span>
<span class="text-blue">{{$value}}</span>
</div>
@endforeach
</div>
4 changes: 2 additions & 2 deletions routes/telegram.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/** @var SergiX44\Nutgram\Nutgram $bot */

use Nutgram\Laravel\Facades\Bot;
use SergiX44\Nutgram\Nutgram;

/*
Expand All @@ -13,6 +13,6 @@
|
*/

Bot::onCommand('start', function (Nutgram $bot) {
$bot->onCommand('start', function (Nutgram $bot) {
return $bot->sendMessage('Hello, world!');
})->description('The start command!');
28 changes: 16 additions & 12 deletions src/Console/HookInfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use JsonException;
use SergiX44\Nutgram\Nutgram;
use SergiX44\Nutgram\Telegram\Exceptions\TelegramException;
use function Termwind\{render};


class HookInfoCommand extends Command
{
Expand All @@ -24,7 +26,7 @@ public function handle(Nutgram $bot): int
$webhookInfo = $bot->getWebhookInfo();

if ($webhookInfo === null) {
$this->error('Unable to get webhook info');
render(view('terminal::fail', ['value' => 'Unable to get webhook info']));
return 1;
}

Expand All @@ -38,17 +40,19 @@ public function handle(Nutgram $bot): int
$lastSynchronizationErrorDate = date('Y-m-d H:i:s', $webhookInfo->last_synchronization_error_date).' UTC';
}

$this->table(['Info', 'Value'], [
['url', $webhookInfo->url],
['has_custom_certificate', $webhookInfo->has_custom_certificate ? 'true' : 'false'],
['pending_update_count', $webhookInfo->pending_update_count],
['ip_address', $webhookInfo->ip_address],
['last_error_date', $lastErrorDate],
['last_error_message', $webhookInfo->last_error_message],
['last_synchronization_error_date', $lastSynchronizationErrorDate],
['max_connections', $webhookInfo->max_connections],
['allowed_updates', implode(', ', $webhookInfo->allowed_updates ?: [])],
]);
render(view('terminal::table', [
'items' => [
'url' => $webhookInfo->url,
'has_custom_certificate' => $webhookInfo->has_custom_certificate ? 'true' : 'false',
'pending_update_count' => $webhookInfo->pending_update_count,
'ip_address' => $webhookInfo->ip_address,
'last_error_date' => $lastErrorDate,
'last_error_message' => $webhookInfo->last_error_message,
'last_synchronization_error_date' => $lastSynchronizationErrorDate,
'max_connections' => $webhookInfo->max_connections,
'allowed_updates' => implode(', ', $webhookInfo->allowed_updates ?: []),
]
]));

return 0;
}
Expand Down
9 changes: 2 additions & 7 deletions src/Console/HookRemoveCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,11 @@ class HookRemoveCommand extends Command
* @throws GuzzleException
* @throws JsonException
*/
public function handle(): int
public function handle(Nutgram $bot): int
{
$dropPendingUpdates = $this->option('drop-pending-updates');

/** @var Nutgram $bot */
$bot = app(Nutgram::class);

$bot->deleteWebhook([
'drop_pending_updates' => $dropPendingUpdates,
]);
$bot->deleteWebhook($dropPendingUpdates);

if ($dropPendingUpdates) {
$this->info('Pending updates dropped.');
Expand Down
11 changes: 6 additions & 5 deletions src/Console/HookSetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class HookSetCommand extends Command
* @throws GuzzleException
* @throws JsonException
*/
public function handle(): int
public function handle(Nutgram $bot): int
{
/** @var string $url */
$url = $this->argument('url');
Expand All @@ -35,10 +35,11 @@ public function handle(): int
$max_connections = (int)$max_connections;
}

/** @var Nutgram $bot */
$bot = app(Nutgram::class);

$bot->setWebhook($url, array_filter(compact('ip_address', 'max_connections')));
$bot->setWebhook(
url: $url,
ip_address: $ip_address,
max_connections: $max_connections,
);

$this->info("Bot webhook set with url: $url");

Expand Down
2 changes: 1 addition & 1 deletion src/Console/IdeGenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class IdeGenerateCommand extends Command

public function handle(): int
{
$this->info('Generating IDE helper...');
$this->warn('Generating IDE helper...');

$helper = file_get_contents(__DIR__.'/../Stubs/Ide.stub');

Expand Down
Loading

0 comments on commit 443b0e2

Please sign in to comment.