-
-
Notifications
You must be signed in to change notification settings - Fork 644
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
492 additions
and
1,075 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
[submodule "docs"] | ||
path = docs | ||
url = https://github.com/danog/MadelineProtoDocs | ||
[submodule "userbots/magnaluna"] | ||
path = userbots/magnaluna | ||
url = https://github.com/danog/magnaluna |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
examples/bot.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
/** | ||
* Example bot. | ||
* | ||
* Copyright 2016-2019 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-2019 Daniil Gentili <daniil@daniil.it> | ||
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3 | ||
* | ||
* @link https://docs.madelineproto.xyz MadelineProto documentation | ||
*/ | ||
|
||
/* | ||
* Various ways to load MadelineProto | ||
*/ | ||
if (\file_exists(__DIR__.'/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 EventHandler extends \danog\MadelineProto\EventHandler | ||
{ | ||
public function onUpdateNewChannelMessage($update) | ||
{ | ||
yield $this->onUpdateNewMessage($update); | ||
} | ||
public function onUpdateNewMessage($update) | ||
{ | ||
if (isset($update['message']['out']) && $update['message']['out']) { | ||
return; | ||
} | ||
if ($update['_'] === 'updateReadChannelOutbox') { | ||
return; | ||
} | ||
if (isset($update['message']['_']) && $update['message']['_'] === 'messageEmpty') { | ||
return; | ||
} | ||
$res = \json_encode($update, JSON_PRETTY_PRINT); | ||
|
||
try { | ||
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') { | ||
yield $this->messages->sendMedia(['peer' => $update, 'message' => $update['message']['message'], 'media' => $update]); | ||
/* '_' => 'inputMediaUploadedDocument', | ||
'file' => $update, | ||
'attributes' => [ | ||
['_' => 'documentAttributeFilename', 'file_name' => 'document.txt'] | ||
] | ||
],]);*/ | ||
//yield $this->download_to_dir($update, '/tmp'); | ||
} | ||
} catch (\danog\MadelineProto\RPCErrorException $e) { | ||
$this->logger((string) $e, \danog\MadelineProto\Logger::FATAL_ERROR); | ||
} catch (\danog\MadelineProto\Exception $e) { | ||
if (\stripos($e->getMessage(), 'invalid constructor given') === false) { | ||
$this->logger((string) $e, \danog\MadelineProto\Logger::FATAL_ERROR); | ||
} | ||
//$this->messages->sendMessage(['peer' => '@danogentili', 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]); | ||
} | ||
} | ||
} | ||
$settings = [ | ||
'logger' => [ | ||
'logger_level' => 5 | ||
], | ||
'serialization' => [ | ||
'serialization_interval' => 30, | ||
'cleanup_before_serialization' => true | ||
], | ||
]; | ||
|
||
$MadelineProto = new \danog\MadelineProto\API('bot.madeline', $settings); | ||
$MadelineProto->async(true); | ||
$MadelineProto->loop(function () use ($MadelineProto) { | ||
yield $MadelineProto->start(); | ||
yield $MadelineProto->setEventHandler('\EventHandler'); | ||
}); | ||
|
||
$MadelineProto->loop(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/** | ||
* Example script. | ||
* | ||
* Copyright 2016-2019 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-2019 Daniil Gentili <daniil@daniil.it> | ||
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3 | ||
* | ||
* @link https://docs.madelineproto.xyz MadelineProto documentation | ||
*/ | ||
|
||
require 'vendor/autoload.php'; | ||
|
||
$MadelineProto = new \danog\MadelineProto\API('session.madeline'); | ||
$me = $MadelineProto->start(); | ||
|
||
$me = $MadelineProto->get_self(); | ||
|
||
\danog\MadelineProto\Logger::log($me); | ||
|
||
if (!$me['bot']) { | ||
$MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => "Hi!\nThanks for creating MadelineProto! <3"]); | ||
$MadelineProto->channels->joinChannel(['channel' => '@MadelineProto']); | ||
|
||
try { | ||
$MadelineProto->messages->importChatInvite(['hash' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg']); | ||
} catch (\danog\MadelineProto\RPCErrorException $e) { | ||
} | ||
|
||
$MadelineProto->messages->sendMessage(['peer' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg', 'message' => 'Testing MadelineProto!']); | ||
} | ||
echo 'OK, done!'.PHP_EOL; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
$debug = false; // Set this to true to avoid automatic updates of this script | ||
/** | ||
* MTProxy. | ||
* | ||
* Copyright 2016-2019 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-2019 Daniil Gentili <daniil@daniil.it> | ||
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3 | ||
* | ||
* @link https://docs.madelineproto.xyz MadelineProto documentation | ||
*/ | ||
|
||
|
||
|
||
|
||
echo "mtproxyd - Copyright by Daniil Gentili, licensed under AGPLv3\n\n"; | ||
if (!isset($argv[2])) { | ||
echo "Usage: ".$argv[0]." seed port\n\nseed is any string or word that will be used as seed to generate the proxy secret\nport is the port where to start listening for connections\n"; | ||
exit(1); | ||
} | ||
|
||
if (!\file_exists('madeline.php')) { | ||
\copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php'); | ||
} | ||
|
||
if (!$debug) { | ||
$mtproxyd = \file_get_contents('https://phar.madelineproto.xyz/mtproxyd?v=new'); | ||
if ($mtproxyd) { | ||
\file_put_contents($argv[0], $mtproxyd); | ||
} | ||
} | ||
|
||
\define('MADELINE_BRANCH', 'deprecated'); | ||
require_once 'madeline.php'; | ||
|
||
$secret = \md5($argv[1]); | ||
echo "Secret is $secret\n"; | ||
|
||
$MadelineProto = new \danog\MadelineProto\API('proxy.madeline'); | ||
$MadelineProto->parse_dc_options($MadelineProto->help->getConfig()['dc_options']); | ||
$handler = new \danog\MadelineProto\Server(['type' => AF_INET, 'protocol' => 0, 'address' => '0.0.0.0', 'port' => $argv[2], 'handler' => '\danog\MadelineProto\Server\Proxy', 'extra' => ['madeline' => $MadelineProto->API->datacenter->sockets, 'secret' => \hex2bin($secret), 'timeout' => 10]]); | ||
$handler->start(); |
Oops, something went wrong.
Codeêeeeeeeeeeeeeee