mirror of
https://github.com/danog/MadelineProto.git
synced 2024-11-30 06:59:01 +01:00
Minor improvements
This commit is contained in:
parent
f4ad90197e
commit
fd7df5bf3c
@ -78,7 +78,7 @@ class MyEventHandler extends EventHandler
|
||||
*
|
||||
* @return \Generator
|
||||
*/
|
||||
public function onUpdateNewMessage(array $update)
|
||||
public function onUpdateNewMessage(array $update): \Generator
|
||||
{
|
||||
if ($update['message']['_'] === 'messageEmpty' || $update['message']['out'] ?? false) {
|
||||
return;
|
||||
@ -86,7 +86,7 @@ class MyEventHandler extends EventHandler
|
||||
|
||||
$res = \json_encode($update, JSON_PRETTY_PRINT);
|
||||
yield $this->messages->sendMessage(['peer' => $update, 'message' => "<code>$res</code>", 'reply_to_msg_id' => isset($update['message']['id']) ? $update['message']['id'] : null, 'parse_mode' => 'HTML']);
|
||||
if (isset($update['message']['media']) && $update['message']['media']['_'] !== 'messageMediaGame') {
|
||||
if (isset($update['message']['media']) && $update['message']['media']['_'] !== 'messageMediaGame' && $update['message']['media']['_'] !== 'messageMediaWebPage') {
|
||||
yield $this->messages->sendMedia(['peer' => $update, 'message' => $update['message']['message'], 'media' => $update]);
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ trait Templates
|
||||
$title = \htmlentities(Lang::$current_lang['apiManualWeb']);
|
||||
$title .= "<br><b>$message</b>";
|
||||
$title .= "<ol>";
|
||||
$title .= "<li>".\htmlentities(Lang::$current_lang['apiManualInstructions0'])."</li>";
|
||||
$title .= "<li>".\str_replace('https://my.telegram.org', '<a href="https://my.telegram.org" target="_blank">https://my.telegram.org</a>', \htmlentities(Lang::$current_lang['apiManualInstructions0']))."</li>";
|
||||
$title .= "<li>".\htmlentities(Lang::$current_lang['apiManualInstructions1'])."</li>";
|
||||
$title .= "<li><ul>";
|
||||
foreach (['App title', 'Short name', 'URL', 'Platform', 'Description'] as $k => $key) {
|
||||
|
@ -131,7 +131,7 @@ class Lang
|
||||
'apiChooseManualAutoTip' => 'Nota che puoi anche fornire i parametri API direttamente nelle impostazioni: %s',
|
||||
'apiChoosePrompt' => 'La tua scelta (m/a): ',
|
||||
'apiError' => 'ERRORE: %s. Prova ancora.',
|
||||
'apiManualInstructions0' => 'Effettua il login su my.telegram.org',
|
||||
'apiManualInstructions0' => 'Effettua il login su https://my.telegram.org',
|
||||
'apiManualInstructions1' => 'Vai su API development tools',
|
||||
'apiManualInstructions2' => 'Clicca su create application',
|
||||
'apiManualPrompt0' => 'Inserisci il tuo API ID: ',
|
||||
@ -179,7 +179,7 @@ class Lang
|
||||
'apiChoosePrompt' => 'Your choice (m/a): ',
|
||||
'apiChooseAutomaticallyWeb' => 'Automatically',
|
||||
'apiChooseManuallyWeb' => 'Manually',
|
||||
'apiManualInstructions0' => 'Login to my.telegram.org',
|
||||
'apiManualInstructions0' => 'Login to https://my.telegram.org',
|
||||
'apiManualInstructions1' => 'Go to API development tools',
|
||||
'apiManualInstructions2' => 'Click on create application',
|
||||
'apiAppInstructionsManual0' => 'your app\'s name, can be anything',
|
||||
@ -330,7 +330,7 @@ class Lang
|
||||
'apiChoosePrompt' => 'Your choice (m/a): ',
|
||||
'apiChooseAutomaticallyWeb' => 'Automatically',
|
||||
'apiChooseManuallyWeb' => 'Manually',
|
||||
'apiManualInstructions0' => 'Login to my.telegram.org',
|
||||
'apiManualInstructions0' => 'Login to https://my.telegram.org',
|
||||
'apiManualInstructions1' => 'Go to API development tools',
|
||||
'apiManualInstructions2' => 'Click on create application',
|
||||
'apiAppInstructionsManual0' => 'your app\'s name, can be anything',
|
||||
|
@ -110,7 +110,7 @@ trait UpdateHandler
|
||||
if ($this->update_deferred) {
|
||||
$deferred = $this->update_deferred;
|
||||
$this->update_deferred = null;
|
||||
$deferred->resolve();
|
||||
Loop::defer(fn () => $deferred->resolve());
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
namespace danog\MadelineProto\Wrappers;
|
||||
|
||||
use Amp\Loop as AmpLoop;
|
||||
use Amp\Promise;
|
||||
use danog\MadelineProto\Logger;
|
||||
use danog\MadelineProto\Magic;
|
||||
@ -122,6 +123,9 @@ trait Loop
|
||||
$this->startUpdateSystem();
|
||||
$this->logger->logger('Started update loop', \danog\MadelineProto\Logger::NOTICE);
|
||||
$this->stopLoop = false;
|
||||
if ($this->loop_callback !== null) {
|
||||
$repeat = AmpLoop::repeat(1000, fn () => Tools::callFork(($this->loop_callback)()));
|
||||
}
|
||||
do {
|
||||
if (!$this->updateHandler) {
|
||||
yield $this->waitUpdate();
|
||||
@ -140,13 +144,12 @@ trait Loop
|
||||
}
|
||||
$updates = [];
|
||||
}
|
||||
if ($this->loop_callback !== null) {
|
||||
$callback = $this->loop_callback;
|
||||
Tools::callForkDefer($callback());
|
||||
}
|
||||
yield $this->waitUpdate();
|
||||
} while (!$this->stopLoop);
|
||||
$this->stopLoop = false;
|
||||
if (isset($repeat)) {
|
||||
AmpLoop::cancel($repeat);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Stop update loop.
|
||||
|
@ -260,7 +260,7 @@ $MadelineProto->loop(function () use ($MadelineProto) {
|
||||
$message = 'yay '.\PHP_VERSION_ID;
|
||||
$mention = yield $MadelineProto->getInfo(\getenv('TEST_USERNAME')); // Returns an array with all of the constructors that can be extracted from a username or an id
|
||||
$mention = $mention['user_id']; // Selects only the numeric user id
|
||||
|
||||
|
||||
foreach (\json_decode(\getenv('TEST_DESTINATION_GROUPS'), true) as $peer) {
|
||||
$sentMessage = yield $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => $message, 'entities' => [['_' => 'inputMessageEntityMentionName', 'offset' => 0, 'length' => \mb_strlen($message), 'user_id' => $mention]]]);
|
||||
$MadelineProto->logger($sentMessage, \danog\MadelineProto\Logger::NOTICE);
|
||||
|
Loading…
Reference in New Issue
Block a user