mirror of
https://github.com/danog/MadelineProto.git
synced 2024-11-30 06:39:01 +01:00
Cleanup examples
This commit is contained in:
parent
30890ae4e5
commit
9f4a1d5dc0
20
CHANGELOG.md
Normal file
20
CHANGELOG.md
Normal file
@ -0,0 +1,20 @@
|
||||
MadelineProto was updated (8.0.0-beta100)!
|
||||
|
||||
Features:
|
||||
- Thanks to the many translation contributors @ https://weblate.madelineproto.xyz/, MadelineProto is now fully localized in Hebrew, Persian, Kurdish, Uzbek and Italian, with WIP translations in Russian and French!
|
||||
- You can now use callFork to fork a new green thread!
|
||||
- The `waveform` attribute of `Voice` objects is now automatically encoded and decoded to an array of 100 integer values!
|
||||
- Added a custom PeerNotInDbException class for "This peer is not present in the internal peer database" errors
|
||||
- Added a `label` property to the Button class, directly indicating the button label (instead of manually fetching it as an array key).
|
||||
- Added `isForum` method to check whether a given supergroup is a forum
|
||||
- Added `entitiesToHtml` method to convert a message and a set of Telegram entities to an HTML string!
|
||||
- Added `wrapUpdate`, `wrapMessage`, `wrapMedia`
|
||||
- You can now use `reportMemoryProfile()` to generate and send a `pprof` memory profile to all report peers to debug the causes of high memory usage.
|
||||
|
||||
|
||||
Fixes:
|
||||
- Fixed file uploads with uv
|
||||
- Many performance improvements and bugfixes!
|
||||
- Improve background broadcasting with the broadcast API using a pre-defined list of `whitelist` IDs!
|
||||
- Broadcast IDs are now unique across multiple broadcasts, even if previous broadcasts already completed their ID will never be re-used.
|
||||
- Now uploadMedia, sendMedia and upload directly accept PHP memory stream resources, to upload files from buffers.
|
@ -1,56 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use danog\MadelineProto\API;
|
||||
use danog\MadelineProto\Settings;
|
||||
use danog\MadelineProto\Settings\Database\Memory;
|
||||
|
||||
/*
|
||||
* load MadelineProto in Your Project
|
||||
*/
|
||||
|
||||
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';
|
||||
}
|
||||
|
||||
/*
|
||||
* create default Memory object
|
||||
*/
|
||||
$database = new Memory;
|
||||
|
||||
/*
|
||||
config and set auth information
|
||||
*/
|
||||
|
||||
$database->setCleanup(true); // set clean up befor serialize session
|
||||
$database->setEnableFullPeerDb(false);// madeline proto could fetch peers full information ??
|
||||
$database->setEnablePeerInfoDb(true); // enable peer basic info option
|
||||
|
||||
/*
|
||||
create default settings object
|
||||
*/
|
||||
|
||||
$settings = new Settings;
|
||||
|
||||
/*
|
||||
set and merge database settings to main settings
|
||||
*/
|
||||
|
||||
$settings->setDb($database);
|
||||
|
||||
/*
|
||||
create madeline proto session
|
||||
*/
|
||||
|
||||
$MadelineProto = new API('madeline.session', $settings);
|
||||
|
||||
/*
|
||||
start madeline proto workers
|
||||
*/
|
||||
$MadelineProto->start();
|
@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use danog\MadelineProto\API;
|
||||
use danog\MadelineProto\Settings;
|
||||
use danog\MadelineProto\Settings\Database\Mysql;
|
||||
|
||||
/*
|
||||
* load MadelineProto in Your Project
|
||||
*/
|
||||
|
||||
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';
|
||||
}
|
||||
|
||||
/*
|
||||
* create default mysql object
|
||||
*/
|
||||
$database = new Mysql;
|
||||
|
||||
/*
|
||||
config and set auth information
|
||||
*/
|
||||
|
||||
$database->setUri('127.0.0.1:3306'); // local mysql service connection with default port
|
||||
$database->setUsername('Wsudo'); // mysql service username
|
||||
$database->setPassword('12345678'); // mysql service password
|
||||
$database->setDatabase('MyBotsData');// which database madeline proto will store datas in that
|
||||
|
||||
/*
|
||||
create default settings object
|
||||
*/
|
||||
|
||||
$settings = new Settings;
|
||||
|
||||
/*
|
||||
set and merge database settings to main settings
|
||||
*/
|
||||
|
||||
$settings->setDb($database);
|
||||
|
||||
/*
|
||||
create madeline proto session
|
||||
*/
|
||||
|
||||
$MadelineProto = new API('madeline.session', $settings);
|
||||
|
||||
/*
|
||||
start madeline proto workers
|
||||
*/
|
||||
$MadelineProto->start();
|
@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use danog\MadelineProto\API;
|
||||
use danog\MadelineProto\Settings;
|
||||
use danog\MadelineProto\Settings\Database\Postgres;
|
||||
|
||||
/*
|
||||
* load MadelineProto in Your Project
|
||||
*/
|
||||
|
||||
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';
|
||||
}
|
||||
|
||||
/*
|
||||
* create default Postgres object
|
||||
*/
|
||||
$database = new Postgres;
|
||||
|
||||
/*
|
||||
config and set auth information
|
||||
*/
|
||||
|
||||
$database->setUri('127.0.0.1:5432'); // postgres db default connection inforamtion
|
||||
$database->setUsername('wsudo'); // postgres db username
|
||||
$database->setPassword('12345678'); // postgres db password
|
||||
$database->setDatabase('MyBotsData');// which database madeline proto will store datas in that
|
||||
|
||||
/*
|
||||
create default settings object
|
||||
*/
|
||||
|
||||
$settings = new Settings;
|
||||
|
||||
/*
|
||||
set and merge database settings to main settings
|
||||
*/
|
||||
|
||||
$settings->setDb($database);
|
||||
|
||||
/*
|
||||
create madeline proto session
|
||||
*/
|
||||
|
||||
$MadelineProto = new API('madeline.session', $settings);
|
||||
|
||||
/*
|
||||
start madeline proto workers
|
||||
*/
|
||||
$MadelineProto->start();
|
@ -1,56 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use danog\MadelineProto\API;
|
||||
use danog\MadelineProto\Settings;
|
||||
use danog\MadelineProto\Settings\Database\Redis;
|
||||
|
||||
/*
|
||||
* load MadelineProto in Your Project
|
||||
*/
|
||||
|
||||
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';
|
||||
}
|
||||
|
||||
/*
|
||||
* create default redis object
|
||||
*/
|
||||
$database = new Redis;
|
||||
|
||||
/*
|
||||
config and set auth information
|
||||
*/
|
||||
|
||||
$database->setUri('127.0.0.1:6379');// redis service connection information with default port
|
||||
$database->setDatabase(0); // redis database number
|
||||
$database->setPassword('wsudo'); // redis service password
|
||||
|
||||
/*
|
||||
create default settings object
|
||||
*/
|
||||
|
||||
$settings = new Settings;
|
||||
|
||||
/*
|
||||
set and merge database settings to main settings
|
||||
*/
|
||||
|
||||
$settings->setDb($database);
|
||||
|
||||
/*
|
||||
create madeline proto session
|
||||
*/
|
||||
|
||||
$MadelineProto = new API('madeline.session', $settings);
|
||||
|
||||
/*
|
||||
start madeline proto workers
|
||||
*/
|
||||
$MadelineProto->start();
|
@ -79,35 +79,25 @@ class MyEventHandler extends EventHandler
|
||||
* @var array
|
||||
*/
|
||||
private $states = [];
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param ?API $API API
|
||||
*/
|
||||
public function __construct(?APIWrapper $API)
|
||||
{
|
||||
$this->UPLOAD = class_exists(HttpServer::class);
|
||||
parent::__construct($API);
|
||||
}
|
||||
public function onStart()
|
||||
{
|
||||
$this->adminId = yield $this->getInfo(self::ADMIN)['bot_api_id'];
|
||||
$this->adminId = $this->getInfo(self::ADMIN)['bot_api_id'];
|
||||
}
|
||||
/**
|
||||
* Handle updates from channels and supergroups.
|
||||
*
|
||||
* @param array $update Update
|
||||
*/
|
||||
public function onUpdateNewChannelMessage(array $update): Generator
|
||||
public function onUpdateNewChannelMessage(array $update)
|
||||
{
|
||||
//yield $this->onUpdateNewMessage($update);
|
||||
//$this->onUpdateNewMessage($update);
|
||||
}
|
||||
/**
|
||||
* Handle updates from users.
|
||||
*
|
||||
* @param array $update Update
|
||||
*/
|
||||
public function onUpdateNewMessage(array $update): Generator
|
||||
public function onUpdateNewMessage(array $update)
|
||||
{
|
||||
if ($update['message']['out'] ?? false) {
|
||||
return;
|
||||
@ -117,34 +107,19 @@ class MyEventHandler extends EventHandler
|
||||
}
|
||||
|
||||
try {
|
||||
$peer = yield $this->getInfo($update);
|
||||
$peer = $this->getInfo($update);
|
||||
$peerId = $peer['bot_api_id'];
|
||||
$messageId = $update['message']['id'];
|
||||
|
||||
if ($this->UPLOAD && $update['message']['message'] === '/getUrl') {
|
||||
yield $this->messages->sendMessage(['peer' => $peerId, 'message' => 'Give me a file: ', 'reply_to_msg_id' => $messageId]);
|
||||
$this->states[$peerId] = $this->UPLOAD;
|
||||
return;
|
||||
}
|
||||
if ($update['message']['message'] === '/start') {
|
||||
return $this->messages->sendMessage(['peer' => $peerId, 'message' => self::START, 'parse_mode' => 'Markdown', 'reply_to_msg_id' => $messageId]);
|
||||
}
|
||||
if ($update['message']['message'] === '/report' && $peerId === $this->adminId) {
|
||||
memprof_dump_callgrind($stm = fopen("php://memory", "w"));
|
||||
fseek($stm, 0);
|
||||
yield $this->messages->sendMedia(['peer' => $peerId, 'media' => ['_' => 'inputMediaUploadedDocument', 'file' => $stm, 'attributes' => [['_' => 'documentAttributeFilename', 'file_name' => 'callgrind.out']]]]);
|
||||
fclose($stm);
|
||||
$this->reportMemoryProfile();
|
||||
return;
|
||||
}
|
||||
if (isset($update['message']['media']['_']) && $update['message']['media']['_'] !== 'messageMediaWebPage') {
|
||||
if ($this->UPLOAD && ($this->states[$peerId] ?? false) === $this->UPLOAD) {
|
||||
unset($this->states[$peerId]);
|
||||
$update = Files::extractBotAPIFile(yield $this->MTProtoToBotAPI($update));
|
||||
$file = [$update['file_size'], $update['mime_type']];
|
||||
var_dump($update['file_id'].'.'.Tools::base64urlEncode(json_encode($file))."/".$update['file_name']);
|
||||
return;
|
||||
}
|
||||
yield $this->messages->sendMessage(['peer' => $peerId, 'message' => 'Give me a new name for this file: ', 'reply_to_msg_id' => $messageId]);
|
||||
$this->messages->sendMessage(['peer' => $peerId, 'message' => 'Give me a new name for this file: ', 'reply_to_msg_id' => $messageId]);
|
||||
$this->states[$peerId] = $update['message']['media'];
|
||||
|
||||
return;
|
||||
@ -164,7 +139,7 @@ class MyEventHandler extends EventHandler
|
||||
$url = "http://$url";
|
||||
}
|
||||
}
|
||||
$id = yield $this->messages->sendMessage(['peer' => $peerId, 'message' => 'Preparing...', 'reply_to_msg_id' => $messageId]);
|
||||
$id = $this->messages->sendMessage(['peer' => $peerId, 'message' => 'Preparing...', 'reply_to_msg_id' => $messageId]);
|
||||
if (!isset($id['id'])) {
|
||||
$this->report(json_encode($id));
|
||||
foreach ($id['updates'] as $updat) {
|
||||
@ -189,31 +164,29 @@ class MyEventHandler extends EventHandler
|
||||
}
|
||||
$prev = $now;
|
||||
try {
|
||||
yield $this->messages->editMessage(['peer' => $peerId, 'id' => $id, 'message' => "Upload progress: $progress%\nSpeed: $speed mbps\nTime elapsed since start: $time"], ['FloodWaitLimit' => 0]);
|
||||
$this->messages->editMessage(['peer' => $peerId, 'id' => $id, 'message' => "Upload progress: $progress%\nSpeed: $speed mbps\nTime elapsed since start: $time"], ['FloodWaitLimit' => 0]);
|
||||
} catch (RPCErrorException $e) {
|
||||
}
|
||||
},
|
||||
);
|
||||
yield $this->messages->sendMedia(
|
||||
[
|
||||
'peer' => $peerId,
|
||||
'reply_to_msg_id' => $messageId,
|
||||
'media' => [
|
||||
$this->messages->sendMedia(
|
||||
peer: $peerId,
|
||||
reply_to_msg_id: $messageId,
|
||||
media: [
|
||||
'_' => 'inputMediaUploadedDocument',
|
||||
'file' => $url,
|
||||
'attributes' => [
|
||||
['_' => 'documentAttributeFilename', 'file_name' => $name],
|
||||
],
|
||||
],
|
||||
'message' => 'Powered by @MadelineProto!',
|
||||
'parse_mode' => 'Markdown',
|
||||
],
|
||||
message: 'Powered by @MadelineProto!',
|
||||
parse_mode: 'Markdown',
|
||||
);
|
||||
|
||||
if (in_array($peer['type'], ['channel', 'supergroup'])) {
|
||||
yield $this->channels->deleteMessages(['channel' => $peerId, 'id' => [$id]]);
|
||||
$this->channels->deleteMessages(['channel' => $peerId, 'id' => [$id]]);
|
||||
} else {
|
||||
yield $this->messages->deleteMessages(['revoke' => true, 'id' => [$id]]);
|
||||
$this->messages->deleteMessages(['revoke' => true, 'id' => [$id]]);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
if (strpos($e->getMessage(), 'Could not connect to URI') === false && !($e instanceof UriException) && strpos($e->getMessage(), 'URI') === false) {
|
||||
@ -224,7 +197,7 @@ class MyEventHandler extends EventHandler
|
||||
$this->report(json_encode($url));
|
||||
}
|
||||
try {
|
||||
yield $this->messages->editMessage(['peer' => $peerId, 'id' => $id, 'message' => 'Error: '.$e->getMessage()]);
|
||||
$this->messages->editMessage(['peer' => $peerId, 'id' => $id, 'message' => 'Error: '.$e->getMessage()]);
|
||||
} catch (Throwable $e) {
|
||||
$this->logger((string) $e, Logger::FATAL_ERROR);
|
||||
}
|
||||
|
6082
extracted.json
Normal file
6082
extracted.json
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user