Skip to content

Commit 6d228a0

Browse files
authored
Merge pull request #19 from WizardLoop/dev
V 3.1.0
2 parents 8a44fe9 + 4c9d9f9 commit 6d228a0

9 files changed

Lines changed: 476 additions & 108 deletions

File tree

.gitattributes

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Force LF line endings
2+
* text=auto eol=lf
3+
4+
# Set file types
5+
*.php text
6+
*.sh text eol=lf
7+
*.md text
8+
*.yml text
9+
*.json text
10+
*.xml text
11+
*.env text
12+
13+
# Exclude tests and dev files from export
14+
phpcs.xml export-ignore
15+
php-cs-fixer.dist.php export-ignore
16+
.dockerignore export-ignore
17+
composer.lock export-ignore
18+
19+
README.md export-ignore
20+
CHANGELOG.md export-ignore

.github/workflows/ci.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
15+
- name: Setup PHP
16+
uses: shivammathur/setup-php@v2
17+
with:
18+
php-version: 8.2
19+
tools: composer:v2
20+
21+
- name: Validate composer.json
22+
run: composer validate --strict
23+
continue-on-error: true
24+
25+
- name: Install dependencies
26+
run: composer install --prefer-dist --no-progress --no-interaction
27+
continue-on-error: true
28+
29+
- name: PHP Syntax check
30+
run: find src -name "*.php" -exec php -l {} \;
31+
continue-on-error: true

.gitignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
.env
2+
.env.local
3+
.env.*.local
4+
/vendor/
5+
/node_modules/
6+
/.idea/
7+
/.vscode/
8+
.DS_Store
9+
*.log
10+
*.cache
11+
12+
docker-compose.override.yml
13+
*.pid
14+
15+
composer.lock
16+
17+
.phpunit.result.cache
18+
/tests/output/
19+
20+
/build/
21+
/dist/
22+
23+
*.bak
24+
*.swp
25+
*.swo
26+
27+
sessions
28+
docs_md
29+
session.mad
30+
*.madeline
31+
*.madeline.*
32+
madeline.phar
33+
madeline.phar.version
34+
madeline.php
35+
36+
*.save
37+
*.save.1
38+
39+
*.save.*

.php-cs-fixer.dist.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in(__DIR__)
5+
->exclude('vendor')
6+
->exclude('data');
7+
8+
return (new PhpCsFixer\Config())
9+
->setRiskyAllowed(true)
10+
->setRules([
11+
'@PSR12' => true,
12+
'array_syntax' => ['syntax' => 'short'],
13+
'no_unused_imports' => true,
14+
'single_quote' => true,
15+
'no_empty_phpdoc' => true,
16+
'not_operator_with_successor_space' => false,
17+
])
18+
->setFinder($finder);

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,20 @@ Added functionality to send initial status messages when gathering peers and sta
165165
### Added & Fixed:
166166

167167
* Handle additional RPCErrorException cases
168+
169+
---
170+
171+
## [3.1.0] - 2026-04-13
172+
173+
# Refactor BroadcastManager for improved functionality
174+
- Updated BroadcastManager class to improve functionality and code structure.
175+
- Added support for handling broadcast IDs, enhanced error handling, and refactored methods to accept optional chat IDs.
176+
177+
### Added:
178+
- added `isActive()` to check active
179+
- added option to set chatId as null
180+
181+
### Fixed:
182+
- fixed `progress()` to update progress state from all methods
183+
184+
---

README.md

Lines changed: 111 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Manage broadcasts efficiently: send messages, media albums, pin/unpin messages,
88
[![Packagist
99
Version](https://img.shields.io/packagist/v/wizardloop/broadcastmanager)](https://packagist.org/packages/wizardloop/broadcastmanager)
1010
[![Packagist Downloads](https://img.shields.io/packagist/dt/wizardloop/broadcastmanager?color=blue)](https://packagist.org/packages/wizardloop/broadcastmanager)
11+
![CI](https://github.com/WizardLoop/BroadcastManager/actions/workflows/ci.yml/badge.svg)
1112

1213
---
1314

@@ -58,29 +59,6 @@ Version](https://img.shields.io/packagist/v/wizardloop/broadcastmanager)](https:
5859

5960
---
6061

61-
## 📁 Repository Structure
62-
63-
```
64-
BroadcastManager/
65-
├── src/
66-
│ └── BroadcastManager.php
67-
├── data/
68-
│ └── .gitkeep
69-
├── composer.json
70-
├── README.md
71-
├── LICENSE
72-
└── CHANGELOG.md
73-
```
74-
75-
---
76-
77-
## 💻 Requirements
78-
79-
* [MadelineProto](https://docs.madelineproto.xyz/)
80-
* [amphp/amp](https://amphp.org/)
81-
82-
---
83-
8462
## ⚡ Installation
8563

8664
```bash
@@ -97,6 +75,10 @@ require 'vendor/autoload.php';
9775

9876
## 🚀 Usage Example
9977

78+
---
79+
## Send Broadcast
80+
81+
### 1) live progress update in message to admin:
10082
```php
10183
use BroadcastTool\BroadcastManager;
10284

@@ -105,10 +87,90 @@ $manager = new BroadcastManager($api);
10587
$manager->broadcastWithProgress($users, $messages, $adminChatId, true, 20);
10688
```
10789

90+
### 2) track on progress without message:
91+
This method returns an integer ID that can be used.
92+
93+
```php
94+
use BroadcastTool\BroadcastManager;
95+
96+
$manager = new BroadcastManager($api);
97+
98+
$broadcastId = $manager->broadcastWithProgress($users, $messages, null, true, 20);
99+
100+
/**
101+
* Get progress (can be polled)
102+
*/
103+
$progress = $manager->progress($broadcastId);
104+
105+
if ($progress !== null) {
106+
107+
// 📊 Core stats
108+
$processed = $progress['processed'];
109+
$success = $progress['success'];
110+
$failed = $progress['failed'];
111+
$pending = $progress['pending'];
112+
$flood = $progress['flood'];
113+
114+
// 📈 Progress %
115+
$progressPercent = $progress['progressPercent'];
116+
117+
// 📦 Breakdown
118+
$sent = $progress['breakdown']['sent'];
119+
$deleted = $progress['breakdown']['deleted'];
120+
$unpin = $progress['breakdown']['unpin'];
121+
122+
// ⚙️ State
123+
$done = $progress['done'];
124+
$paused = $progress['paused'];
125+
$cancel = $progress['cancel'];
126+
127+
// ⏱ Timing
128+
$startedAt = $progress['startedAt'];
129+
130+
/**
131+
* Example usage
132+
*/
133+
echo "Progress: {$progressPercent}%\n";
134+
echo "Sent: {$sent}\n";
135+
echo "Failed: {$failed}\n";
136+
137+
if ($done) {
138+
echo "Broadcast finished!";
139+
}
140+
141+
if ($paused) {
142+
echo "Broadcast paused...";
143+
}
144+
}
145+
```
146+
147+
```php
148+
* progress return array|null {
149+
* processed: int, // total processed items (sent + deleted + unpin + failed)
150+
* success: int, // successful operations (sent + deleted + unpin)
151+
* failed: int, // failed operations count
152+
* pending: int, // remaining items in queue
153+
* flood: int, // FLOOD_WAIT occurrences
154+
*
155+
* progressPercent: float, // completion percentage (processed / total)
156+
*
157+
* breakdown: array {
158+
* sent: int,
159+
* deleted: int,
160+
* unpin: int
161+
* },
162+
*
163+
* done: bool, // process finished
164+
* paused: bool, // process paused
165+
* cancel: bool, // process cancelled
166+
*
167+
* startedAt: float // microtime start timestamp
168+
* }
169+
```
170+
108171
---
109172

110173
## Filer Peers
111-
112174
```php
113175
$filterSub = $manager->filterPeers($users, 'users');
114176
$targets = $filterSub['targets']; # array
@@ -121,64 +183,64 @@ $total = $filterSub['total']; # int
121183
## ⏸ Control Broadcasts
122184

123185
```php
124-
$manager->pause();
125-
$manager->resume();
126-
$manager->cancel();
186+
$manager->pause($broadcastId);
187+
$manager->resume($broadcastId);
188+
$manager->cancel($broadcastId);
127189
```
128190

129-
Check state:
191+
### Check state:
130192
```php
131-
if ($manager->isPaused()) echo "Paused";
132-
if ($manager->isCancelled()) echo "Cancelled";
133-
if (!$manager->hasLastBroadcast()) echo "No last Broadcast do delete";
134-
if (!$manager->hasAllBroadcast()) echo "No all Broadcast to delete";
135-
print_r($manager->progress());
193+
if ($manager->isActive($broadcastId));
194+
if ($manager->isPaused($broadcastId));
195+
if ($manager->isCancelled($broadcastId));
196+
if (!$manager->hasLastBroadcast($broadcastId));
197+
if (!$manager->hasAllBroadcast($broadcastId));
198+
print_r($manager->progress($broadcastId));
136199
```
137200

138-
Set data dir:
201+
### Set data dir:
139202
```php
140-
BroadcastManager::setDataDir(__DIR__ . '/data');
203+
BroadcastManager::setDataDir(__DIR__ . '/data'); // default: __DIR__ . '/../data'
141204
```
142-
_default is: __DIR__ . '/../data'_
143205

144206
---
145207

146208
## 🧹 Delete Last Broadcast
147209

148210
```php
149-
$manager->deleteLastBroadcastForAll($users, $adminChatId, 20);
211+
$broadcastId = $manager->deleteLastBroadcastForAll($users, $adminChatId, 20);
150212
```
151213

152214
---
153215

154216
## ♻️ Delete All Broadcast
155217

156218
```php
157-
$manager->deleteAllBroadcastsForAll($users, $adminChatId, 20);
219+
$broadcastId = $manager->deleteAllBroadcastsForAll($users, $adminChatId, 20);
158220
```
159221

160222
---
161223

162224
## 📊 Get Last Broadcast Data
163225

164226
```php
165-
$manager->lastBroadcastData();
227+
$broadcastId = $manager->lastBroadcastData();
166228
```
167229

168230
---
169231

170232
## 📌 Pin / Unpin Messages
171233

172-
Pin last broadcast automatically:
234+
## Pin last broadcast automatically:
173235

174236
```php
175-
$manager->broadcastWithProgress(..., pin: true);
237+
$broadcastId = $manager->broadcastWithProgress(..., pin: true);
176238
```
177239

178-
Unpin all messages:
240+
## Unpin all messages:
179241

180242
```php
181-
$manager->unpinAllMessagesForAll(...);
243+
$broadcastId = $manager->unpinAllMessagesForAll(...);
182244
```
183245

184246
---
@@ -199,11 +261,11 @@ $message = [
199261

200262
## ⚙️ Advanced Options
201263

202-
* **Concurrency** Number of parallel workers.
203-
* **Filter Types** 'users', 'groups', 'channels', 'all'
204-
* **Album Handling** JSON-based albums with multiple media files.
205-
* **Retries & Delays** Automatic retries with backoff.
206-
* **Progress Tracking** Real-time broadcast stats with `progress()`.
264+
* **Concurrency** - Number of parallel workers.
265+
* **Filter Types** - 'users', 'groups', 'channels', 'all'
266+
* **Album Handling** - JSON-based albums with multiple media files.
267+
* **Retries & Delays** - Automatic retries with backoff.
268+
* **Progress Tracking** - Real-time broadcast stats with `progress()`.
207269

208270
---
209271

@@ -219,7 +281,7 @@ $message = [
219281

220282
## 📄 License
221283

222-
**GNU AGPL-3.0** see [LICENSE](LICENSE).
284+
**GNU AGPL-3.0** - see [LICENSE](LICENSE).
223285

224286
---
225287

phpcs.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="BroadcastManager">
3+
<description>PHP CodeSniffer configuration</description>
4+
<file>src</file>
5+
<exclude-pattern>vendor/*</exclude-pattern>
6+
<rule ref="PSR12"/>
7+
</ruleset>

0 commit comments

Comments
 (0)