Simplify combined

This commit is contained in:
Daniil Gentili 2020-02-26 14:15:27 +01:00
parent e44490c9dc
commit 648b0a1250
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 3 additions and 21 deletions

View File

@ -48,7 +48,7 @@ composer.json:
"description": "Project description",
"type": "project",
"require": {
"danog/madelineproto": "^5.0"
"danog/madelineproto": "^5"
},
"license": "AGPL-3.0-only",
"authors": [

View File

@ -173,28 +173,10 @@ foreach ([
'user2.madeline' => 'Userbot login (2)'
] as $session => $message) {
Logger::log($message, Logger::WARNING);
$MadelineProto = new API($session);
$MadelineProto->async(true);
$MadelineProto->loop(function () use ($MadelineProto) {
yield $MadelineProto->start();
yield $MadelineProto->setEventHandler(MyEventHandler::class);
});
$MadelineProtos []= $MadelineProto->loopFork();
$MadelineProtos []= (new API($session))->startAndLoopBackground(MyEventHandler::class);
}
do {
$thrown = false;
try {
Tools::wait(Tools::all($MadelineProtos));
} catch (\Throwable $e) {
$thrown = true;
try {
$MadelineProto->report("Surfaced: $e");
} catch (\Throwable $e) {
$MadelineProto->logger((string) $e, \danog\MadelineProto\Logger::FATAL_ERROR);
}
}
} while ($thrown);
Tools::wait(Tools::all($MadelineProtos));
```
This will create an event handler class `EventHandler`, create a **combined** MadelineProto session with session files `bot.madeline`, `user.madeline`, `user2.madeline`, and set the event handler class to our newly created event handler.