mirror of
https://github.com/danog/MadelineProto.git
synced 2025-01-22 19:51:11 +01:00
Add Cron attribute (rename the old Periodic attribute)
This commit is contained in:
parent
a401ea2495
commit
b8bc4cafe5
@ -6,7 +6,7 @@ Features:
|
|||||||
- You can now automatically pin messages broadcasted using `broadcastMessages`, `broadcastForwardMessages` by using the new `pin: true` parameter!
|
- You can now automatically pin messages broadcasted using `broadcastMessages`, `broadcastForwardMessages` by using the new `pin: true` parameter!
|
||||||
- You can now use `@admin` to send messages to the bot's admin, which will be the first peer returned by `getReportPeers`.
|
- You can now use `@admin` to send messages to the bot's admin, which will be the first peer returned by `getReportPeers`.
|
||||||
- Added `wrapUpdate`, `wrapMessage`, `wrapMedia`
|
- Added `wrapUpdate`, `wrapMessage`, `wrapMedia`
|
||||||
- Added `Periodic`
|
- Added `Cron`
|
||||||
- Added plugins, filters, simple filters
|
- Added plugins, filters, simple filters
|
||||||
- The `waveform` attribute of `Voice` objects is now automatically encoded and decoded to an array of 100 integer values!
|
- The `waveform` attribute of `Voice` objects is now automatically encoded and decoded to an array of 100 integer values!
|
||||||
- Added a custom PeerNotInDbException class for "This peer is not present in the internal peer database" errors
|
- Added a custom PeerNotInDbException class for "This peer is not present in the internal peer database" errors
|
||||||
|
@ -23,7 +23,7 @@ use danog\MadelineProto\API;
|
|||||||
use danog\MadelineProto\Broadcast\Progress;
|
use danog\MadelineProto\Broadcast\Progress;
|
||||||
use danog\MadelineProto\Broadcast\Status;
|
use danog\MadelineProto\Broadcast\Status;
|
||||||
use danog\MadelineProto\EventHandler;
|
use danog\MadelineProto\EventHandler;
|
||||||
use danog\MadelineProto\EventHandler\Attributes\Periodic;
|
use danog\MadelineProto\EventHandler\Attributes\Cron;
|
||||||
use danog\MadelineProto\Logger;
|
use danog\MadelineProto\Logger;
|
||||||
use danog\MadelineProto\Settings;
|
use danog\MadelineProto\Settings;
|
||||||
use danog\MadelineProto\Settings\Database\Mysql;
|
use danog\MadelineProto\Settings\Database\Mysql;
|
||||||
@ -97,9 +97,9 @@ class MyEventHandler extends EventHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function will be executed every 60 seconds.
|
* This cron function will be executed forever, every 60 seconds.
|
||||||
*/
|
*/
|
||||||
#[Periodic(period: 60.0)]
|
#[Cron(period: 60.0)]
|
||||||
public function cron1(): void
|
public function cron1(): void
|
||||||
{
|
{
|
||||||
$this->messages->sendMessage(
|
$this->messages->sendMessage(
|
||||||
|
@ -27,6 +27,7 @@ use AssertionError;
|
|||||||
use Closure;
|
use Closure;
|
||||||
use danog\Loop\PeriodicLoop;
|
use danog\Loop\PeriodicLoop;
|
||||||
use danog\MadelineProto\Db\DbPropertiesTrait;
|
use danog\MadelineProto\Db\DbPropertiesTrait;
|
||||||
|
use danog\MadelineProto\EventHandler\Attributes\Cron;
|
||||||
use danog\MadelineProto\EventHandler\Attributes\Periodic;
|
use danog\MadelineProto\EventHandler\Attributes\Periodic;
|
||||||
use danog\MadelineProto\EventHandler\Filter\Combinator\FiltersAnd;
|
use danog\MadelineProto\EventHandler\Filter\Combinator\FiltersAnd;
|
||||||
use danog\MadelineProto\EventHandler\Filter\Filter;
|
use danog\MadelineProto\EventHandler\Filter\Filter;
|
||||||
@ -178,7 +179,7 @@ abstract class EventHandler extends AbstractAPI
|
|||||||
];
|
];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ($periodic = $methodRefl->getAttributes(Periodic::class)) {
|
if ($periodic = $methodRefl->getAttributes(Cron::class)) {
|
||||||
$periodic = $periodic[0]->newInstance();
|
$periodic = $periodic[0]->newInstance();
|
||||||
$this->periodicLoops[$method] = new PeriodicLoop(
|
$this->periodicLoops[$method] = new PeriodicLoop(
|
||||||
function (PeriodicLoop $loop) use ($closure): bool {
|
function (PeriodicLoop $loop) use ($closure): bool {
|
||||||
|
@ -6,7 +6,7 @@ use Attribute;
|
|||||||
|
|
||||||
/** Attribute that enables periodic execution of a certain method. */
|
/** Attribute that enables periodic execution of a certain method. */
|
||||||
#[Attribute(Attribute::TARGET_METHOD)]
|
#[Attribute(Attribute::TARGET_METHOD)]
|
||||||
final class Periodic
|
final class Cron
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public readonly float $period
|
public readonly float $period
|
Loading…
x
Reference in New Issue
Block a user