mirror of
https://github.com/danog/MadelineProto.git
synced 2024-11-26 21:14:43 +01:00
83 lines
2.5 KiB
PHP
Executable File
83 lines
2.5 KiB
PHP
Executable File
#!/usr/bin/env php
|
|
<?php
|
|
/**
|
|
* Example combined event handler bot.
|
|
*
|
|
* Copyright 2016-2020 Daniil Gentili
|
|
* (https://daniil.it)
|
|
* This file is part of MadelineProto.
|
|
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
* See the GNU Affero General Public License for more details.
|
|
* You should have received a copy of the GNU General Public License along with MadelineProto.
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
* @author Daniil Gentili <daniil@daniil.it>
|
|
* @copyright 2016-2023 Daniil Gentili <daniil@daniil.it>
|
|
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
|
|
* @link https://docs.madelineproto.xyz MadelineProto documentation
|
|
*/
|
|
|
|
use danog\MadelineProto\API;
|
|
use danog\MadelineProto\EventHandler;
|
|
|
|
/*
|
|
* Various ways to load MadelineProto
|
|
*/
|
|
if (file_exists('vendor/autoload.php')) {
|
|
include 'vendor/autoload.php';
|
|
} else {
|
|
if (!file_exists('madeline.php')) {
|
|
copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
|
|
}
|
|
include 'madeline.php';
|
|
}
|
|
|
|
/**
|
|
* Event handler class.
|
|
*/
|
|
class MyEventHandler extends EventHandler
|
|
{
|
|
/**
|
|
* @var int|string Username or ID of bot admin
|
|
*/
|
|
const ADMIN = "danogentili"; // Change this
|
|
/**
|
|
* Get peer(s) where to report errors.
|
|
*
|
|
* @return int|string|array
|
|
*/
|
|
public function getReportPeers()
|
|
{
|
|
return [self::ADMIN];
|
|
}
|
|
/**
|
|
* Handle updates from supergroups and channels.
|
|
*
|
|
* @param array $update Update
|
|
*/
|
|
public function onUpdateNewChannelMessage(array $update)
|
|
{
|
|
return $this->onUpdateNewMessage($update);
|
|
}
|
|
/**
|
|
* Handle updates from users.
|
|
*
|
|
* @param array $update Update
|
|
*/
|
|
public function onUpdateNewMessage(array $update): void
|
|
{
|
|
if ($update['message']['_'] === 'messageEmpty' || $update['message']['out'] ?? false) {
|
|
return;
|
|
}
|
|
$this->logger($update);
|
|
}
|
|
}
|
|
|
|
$MadelineProtos = [];
|
|
foreach (['session1.madeline', 'session2.madeline', 'session3.madeline'] as $session => $message) {
|
|
$MadelineProtos []= new API($session);
|
|
}
|
|
|
|
API::startAndLoopMulti($MadelineProtos, MyEventHandler::class);
|