- Native plugin system
To create a plugin, simply create an event handler that extends PluginEventHandler.
For example, create a
plugins/Danogentili/PingPlugin.php file: <?php declare(strict_types=1);And use a plugin base to run all plugins included in the
namespace MadelinePlugin\Danogentili\PingPlugin;
use danog\MadelineProto\PluginEventHandler;
use danog\MadelineProto\EventHandler\Filter\FilterText;
use danog\MadelineProto\EventHandler\Message;
use danog\MadelineProto\EventHandler\SimpleFilter\Incoming;
class PingPlugin extends PluginEventHandler
{
#[FilterCommand('echo')]
public function echoCmd(Incoming & Message $message): void
{
// Contains the arguments of the command
$args = $message->commandArgs;
$message->reply($args[0] ?? '');
}
#[FilterRegex('/.*(mt?proto).*/i')]
public function testRegex(Incoming & Message $message): void
{
$message->reply("Did you mean to write MadelineProto instead of ".$message->matches[1].'?');
}
#[FilterText('ping')]
public function pingCommand(Incoming&Message $message): void
{
$message->reply("Pong");
}
}
plugins folder. See the documentation for more info on how to create MadelineProto plugins!
- Message objects with bound methods
Both plugins and normal bots can make use of bound update methods like
reply(), delete(), getReply(), getHTML() and simplified properties like chatId, senderId, command, commandArgs and many more, see the documentation for more info!- Filters
Plugins and bots can now use three different filtering systems, to easily receive only updates satisfying certain conditions (incoming/outgoing, from group, channel, private, from an admin or a specific peer, with an audio/sticker/..., satisfying a certain regex or a certain /command, and much more!), see the documentation for more info!
- Built-in cron system
All event handler methods marked by the
Cron attribute are now automatically invoked by MadelineProto every period seconds: use danog\MadelineProto\EventHandler\Attributes\Cron;See the documentation for more info!
class MyEventHandler extends SimpleEventHandler
{
/**
* This cron function will be executed forever, every 60 seconds.
*/
#[Cron(period: 60.0)]
public function cron1(): void
{
$this->sendMessageToAdmins("The bot is online, current time ".date(DATE_RFC850)."!");
}
}
- IPC support for the event handler
You can now call event handler and plugin methods from outside of the event handler, using
getEventHandler() on an API instance, see the docs for more info!- Automatic static analysis of event handler code
Finally, all new bots and plugins will be automatically analyzed by MadelineProto, blocking execution if performance or security issues are detected!
See the documentation for info!