mirror of
https://github.com/danog/MadelineProto.git
synced 2024-11-30 08:18:59 +01:00
Add simple example
This commit is contained in:
parent
a42fe534b2
commit
a860cb2dbb
54
examples/simpleBot.php
Normal file
54
examples/simpleBot.php
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
// Simple example bot.
|
||||||
|
// PHP 8.1.15+ or 8.2.4+ is required.
|
||||||
|
|
||||||
|
// Run via CLI (recommended: `screen php bot.php`) or via web.
|
||||||
|
|
||||||
|
// To reduce RAM usage, follow these instructions: https://docs.madelineproto.xyz/docs/DATABASE.html
|
||||||
|
|
||||||
|
use danog\MadelineProto\EventHandler\Attributes\Handler;
|
||||||
|
use danog\MadelineProto\EventHandler\Message;
|
||||||
|
use danog\MadelineProto\EventHandler\SimpleFilter\Incoming;
|
||||||
|
use danog\MadelineProto\SimpleEventHandler;
|
||||||
|
|
||||||
|
// Load via composer
|
||||||
|
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';
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyEventHandler extends SimpleEventHandler
|
||||||
|
{
|
||||||
|
// !!! Change this to your username !!!
|
||||||
|
const ADMIN = "@me";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get peer(s) where to report errors.
|
||||||
|
*/
|
||||||
|
public function getReportPeers()
|
||||||
|
{
|
||||||
|
return [self::ADMIN];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle incoming updates from users, chats and channels.
|
||||||
|
*/
|
||||||
|
#[Handler]
|
||||||
|
public function handleMessage(Incoming&Message $message): void
|
||||||
|
{
|
||||||
|
// Code that uses $message...
|
||||||
|
// See the following pages for more examples and documentation:
|
||||||
|
// - https://github.com/danog/MadelineProto/blob/v8/examples/bot.php
|
||||||
|
// - https://docs.madelineproto.xyz/docs/UPDATES.html
|
||||||
|
// - https://docs.madelineproto.xyz/docs/FILTERS.html
|
||||||
|
// - https://docs.madelineproto.xyz/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MyEventHandler::startAndLoop('bot.madeline');
|
@ -232,7 +232,7 @@ final class DjLoop extends VoIPLoop
|
|||||||
}
|
}
|
||||||
$queue = $this->playingPrimary ? $this->packetQueuePrimary : $this->packetQueueSecondary;
|
$queue = $this->playingPrimary ? $this->packetQueuePrimary : $this->packetQueueSecondary;
|
||||||
if ($queue->isEmpty()) {
|
if ($queue->isEmpty()) {
|
||||||
if ($this->instance->getCallState() === CallState::ENDED) {
|
if ($this->instance->getCallState() === CallState::ENDED || !$this->isRunning()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if ($this->readingPrimary !== $this->playingPrimary) {
|
if ($this->readingPrimary !== $this->playingPrimary) {
|
||||||
|
@ -527,7 +527,7 @@ final class VoIPController
|
|||||||
|
|
||||||
public function log(string $message, int $level = Logger::NOTICE): void
|
public function log(string $message, int $level = Logger::NOTICE): void
|
||||||
{
|
{
|
||||||
EventLoop::queue($this->API->logger->logger(...), $message, $level);
|
$this->API->logger->logger($message, $level);
|
||||||
}
|
}
|
||||||
private bool $muted = true;
|
private bool $muted = true;
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user