1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-12-12 12:27:21 +01:00
MadelineProto/examples/PluginBase.php

42 lines
1.4 KiB
PHP
Raw Normal View History

2023-07-14 16:34:52 +02:00
<?php declare(strict_types=1);
2024-02-02 18:06:50 +01:00
if (file_exists('vendor/autoload.php')) {
require_once 'vendor/autoload.php';
} else {
// Otherwise download an !!! alpha !!! version of MadelineProto via madeline.php
if (!file_exists('madeline.php')) {
copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
}
require_once 'madeline.php';
}
2023-07-14 16:34:52 +02:00
use danog\MadelineProto\Logger;
use danog\MadelineProto\Settings;
use danog\MadelineProto\Settings\Database\Mysql;
use danog\MadelineProto\Settings\Database\Postgres;
use danog\MadelineProto\Settings\Database\Redis;
use danog\MadelineProto\SimpleEventHandler;
/** Base event handler class that only includes plugins */
class BaseHandler extends SimpleEventHandler
{
public static function getPluginPaths(): array|string|null
{
return 'plugins/';
}
}
$settings = new Settings;
$settings->getLogger()->setLevel(Logger::LEVEL_ULTRA_VERBOSE);
// You can also use Redis, MySQL or PostgreSQL
// $settings->setDb((new Redis)->setDatabase(0)->setPassword('pony'));
// $settings->setDb((new Postgres)->setDatabase('MadelineProto')->setUsername('daniil')->setPassword('pony'));
// $settings->setDb((new Mysql)->setDatabase('MadelineProto')->setUsername('daniil')->setPassword('pony'));
// For users or bots
BaseHandler::startAndLoop('bot.madeline', $settings);
// For bots only
// BaseHandler::startAndLoopBot('bot.madeline', 'bot token', $settings);