Skip to content

Commit 94e9ee7

Browse files
committed
Because why not, let’s allow multiple groups to be called in 1 cron call.
1 parent b15a6cf commit 94e9ee7

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ There are a few parameters available to get things rolling:
5353
| i | **i**nterval: Number of seconds to wait between getUpdates requests (used for getUpdates method, default is 2). |
5454
| | This would be used mainly via CLI, to continually get updates for a certain period, every **i** seconds. |
5555
| g | **g**roup: Commands group for cron (only used together with `cron` action, default group is `default`). |
56-
| | Define which group of commands to execute via cron. |
56+
| | Define which group of commands to execute via cron. Can be a comma separated list of groups. |
5757

5858
#### via browser
5959

@@ -76,6 +76,12 @@ Handle updates once:
7676
Handle updates for 30 seconds, fetching every 5 seconds:
7777
- `http://example.com/manager.php?s=super_secret&l=30&i=5`
7878

79+
**cron**
80+
81+
Execute commands via cron:
82+
- `http://example.com/manager.php?s=super_secret&a=cron&g=maintenance` or multiple groups
83+
- `http://example.com/manager.php?s=super_secret&a=cron&g=maintenance,cleanup`
84+
7985
#### via CLI
8086

8187
When using CLI, the secret is not necessary (since it could just be read from the file itself).
@@ -99,6 +105,12 @@ Handle updates once:
99105
Handle updates for 30 seconds, fetching every 5 seconds:
100106
- `$ php manager.php l=30 i=5`
101107

108+
**cron**
109+
110+
Execute commands via cron:
111+
- `$ php manager.php a=cron g=maintenance` or multiple groups
112+
- `$ php manager.php a=cron g=maintenance,cleanup`
113+
102114
### Create the manager PHP file
103115

104116
You can name this file whatever you like, it just has to be somewhere inside your PHP project (preferably in the root folder to make things easier).

src/BotManager.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,12 @@ public function handleRequest(): self
351351
*/
352352
public function handleCron(): self
353353
{
354-
$group = $this->params->getScriptParam('g', 'default');
355-
$commands = $this->params->getBotParam('cron.groups.' . $group, []);
354+
$groups = explode(',', $this->params->getScriptParam('g', 'default'));
355+
356+
$commands = [];
357+
foreach ($groups as $group) {
358+
$commands = array_merge($commands, $this->params->getBotParam('cron.groups.' . $group, []));
359+
}
356360
$this->telegram->runCommands($commands);
357361

358362
return $this;

0 commit comments

Comments
 (0)