Skip to content

Commit cb7d5f6

Browse files
committed
Clean up
1 parent e81ecc8 commit cb7d5f6

30 files changed

Lines changed: 492 additions & 1075 deletions

‎.babelrc‎

Lines changed: 0 additions & 3 deletions
This file was deleted.

‎.gitmodules‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
[submodule "docs"]
22
path = docs
33
url = https://github.com/danog/MadelineProtoDocs
4-
[submodule "userbots/magnaluna"]
5-
path = userbots/magnaluna
6-
url = https://github.com/danog/magnaluna

‎CHANGELOG.md‎

Lines changed: 0 additions & 398 deletions
This file was deleted.

‎CODE_OF_CONDUCT.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This Code of Conduct applies both within project spaces and in public spaces whe
3434

3535
## Enforcement
3636

37-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at daniil@daniil.jt. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
37+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at daniil@daniil.it. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
3838

3939
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
4040

‎README.md‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -511,12 +511,10 @@ Tip: if you receive an error (or nothing), [send us](https://t.me/pwrtelegramgro
511511
## Very complex and complete examples
512512
513513
You can find examples for nearly every MadelineProto function in
514+
* [magnaluna webradio](https://magna.madelineproto.xyz) - Multifeatured Telegram VoIP webradio
514515
* [`tests/testing.php`](https://github.com/danog/MadelineProto/blob/master/tests/testing.php) - examples for making/receiving calls, making secret chats, sending secret chat messages, videos, audios, voice recordings, gifs, stickers, photos, sending normal messages, videos, audios, voice recordings, gifs, stickers, photos.
515-
* [`bot.php`](https://github.com/danog/MadelineProto/blob/master/bot.php) - examples for sending normal messages, downloading any media
516-
* [`secret_bot.php`](https://github.com/danog/MadelineProto/blob/master/secret_bot.php) - secret chat bot
517-
* [`magna.php`](https://github.com/danog/MadelineProto/blob/master/magna.php) - examples for receiving calls
518-
* [`userbots/pipesbot.php`](https://github.com/danog/MadelineProto/blob/master/userbots/pipesbot.php) - examples for creating inline bots and using other inline bots via a userbot
519-
* [`userbots/MadelineProto_bot.php`](https://github.com/danog/MadelineProto/blob/master/userbots/MadelineProto_bot.php) - Multi-function bot
520-
* [`userbots/pwrtelegram_debug_bot`](https://github.com/danog/MadelineProto/blob/master/userbots/pwrtelegram_debug_bot.php) - Multi-function bot
516+
* [`bot.php`](https://github.com/danog/MadelineProto/blob/master/examples/bot.php) - examples for sending normal messages, downloading any media
517+
* [`secret_bot.php`](https://github.com/danog/MadelineProto/blob/master/examples/secret_bot.php) - secret chat bot
518+
* [`pipesbot.php`](https://github.com/danog/MadelineProto/blob/master/examples/pipesbot.php) - examples for creating inline bots and using other inline bots via a userbot
521519
522520

‎bot.php‎

Lines changed: 0 additions & 85 deletions
This file was deleted.

‎bot.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
examples/bot.php

‎examples/bot.php‎

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/usr/bin/env php
2+
<?php
3+
/**
4+
* Example bot.
5+
*
6+
* Copyright 2016-2019 Daniil Gentili
7+
* (https://daniil.it)
8+
* This file is part of MadelineProto.
9+
* 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.
10+
* 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.
11+
* See the GNU Affero General Public License for more details.
12+
* You should have received a copy of the GNU General Public License along with MadelineProto.
13+
* If not, see <http://www.gnu.org/licenses/>.
14+
*
15+
* @author Daniil Gentili <daniil@daniil.it>
16+
* @copyright 2016-2019 Daniil Gentili <daniil@daniil.it>
17+
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
18+
*
19+
* @link https://docs.madelineproto.xyz MadelineProto documentation
20+
*/
21+
22+
/*
23+
* Various ways to load MadelineProto
24+
*/
25+
if (\file_exists(__DIR__.'/vendor/autoload.php')) {
26+
include 'vendor/autoload.php';
27+
} else {
28+
if (!\file_exists('madeline.php')) {
29+
\copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
30+
}
31+
include 'madeline.php';
32+
}
33+
34+
/**
35+
* Event handler class.
36+
*/
37+
class EventHandler extends \danog\MadelineProto\EventHandler
38+
{
39+
public function onUpdateNewChannelMessage($update)
40+
{
41+
yield $this->onUpdateNewMessage($update);
42+
}
43+
public function onUpdateNewMessage($update)
44+
{
45+
if (isset($update['message']['out']) && $update['message']['out']) {
46+
return;
47+
}
48+
if ($update['_'] === 'updateReadChannelOutbox') {
49+
return;
50+
}
51+
if (isset($update['message']['_']) && $update['message']['_'] === 'messageEmpty') {
52+
return;
53+
}
54+
$res = \json_encode($update, JSON_PRETTY_PRINT);
55+
56+
try {
57+
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']);
58+
if (isset($update['message']['media']) && $update['message']['media']['_'] !== 'messageMediaGame') {
59+
yield $this->messages->sendMedia(['peer' => $update, 'message' => $update['message']['message'], 'media' => $update]);
60+
/* '_' => 'inputMediaUploadedDocument',
61+
'file' => $update,
62+
'attributes' => [
63+
['_' => 'documentAttributeFilename', 'file_name' => 'document.txt']
64+
]
65+
],]);*/
66+
//yield $this->download_to_dir($update, '/tmp');
67+
}
68+
} catch (\danog\MadelineProto\RPCErrorException $e) {
69+
$this->logger((string) $e, \danog\MadelineProto\Logger::FATAL_ERROR);
70+
} catch (\danog\MadelineProto\Exception $e) {
71+
if (\stripos($e->getMessage(), 'invalid constructor given') === false) {
72+
$this->logger((string) $e, \danog\MadelineProto\Logger::FATAL_ERROR);
73+
}
74+
//$this->messages->sendMessage(['peer' => '@danogentili', 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]);
75+
}
76+
}
77+
}
78+
$settings = [
79+
'logger' => [
80+
'logger_level' => 5
81+
],
82+
'serialization' => [
83+
'serialization_interval' => 30,
84+
'cleanup_before_serialization' => true
85+
],
86+
];
87+
88+
$MadelineProto = new \danog\MadelineProto\API('bot.madeline', $settings);
89+
$MadelineProto->async(true);
90+
$MadelineProto->loop(function () use ($MadelineProto) {
91+
yield $MadelineProto->start();
92+
yield $MadelineProto->setEventHandler('\EventHandler');
93+
});
94+
95+
$MadelineProto->loop();
Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,48 @@
11
#!/usr/bin/env php
22
<?php
3-
/*
4-
Copyright 2016-2019 Daniil Gentili
5-
(https://daniil.it)
6-
This file is part of MadelineProto.
7-
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.
8-
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.
9-
See the GNU Affero General Public License for more details.
10-
You should have received a copy of the GNU General Public License along with MadelineProto.
11-
If not, see <http://www.gnu.org/licenses/>.
12-
*/
3+
/**
4+
* Example combined event handler bot.
5+
*
6+
* Copyright 2016-2019 Daniil Gentili
7+
* (https://daniil.it)
8+
* This file is part of MadelineProto.
9+
* 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.
10+
* 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.
11+
* See the GNU Affero General Public License for more details.
12+
* You should have received a copy of the GNU General Public License along with MadelineProto.
13+
* If not, see <http://www.gnu.org/licenses/>.
14+
*
15+
* @author Daniil Gentili <daniil@daniil.it>
16+
* @copyright 2016-2019 Daniil Gentili <daniil@daniil.it>
17+
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
18+
*
19+
* @link https://docs.madelineproto.xyz MadelineProto documentation
20+
*/
21+
1322
\set_include_path(\get_include_path().':'.\realpath(\dirname(__FILE__).'/MadelineProto/'));
1423

1524
/*
1625
* Various ways to load MadelineProto
1726
*/
18-
if (!\file_exists(__DIR__.'/vendor/autoload.php')) {
19-
echo 'You did not run composer update, using madeline.php'.PHP_EOL;
27+
if (\file_exists(__DIR__.'/vendor/autoload.php')) {
28+
include 'vendor/autoload.php';
29+
} else {
2030
if (!\file_exists('madeline.php')) {
2131
\copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
2232
}
2333
include 'madeline.php';
24-
} else {
25-
require_once 'vendor/autoload.php';
2634
}
2735

36+
/**
37+
* Combined event handler class.
38+
*/
2839
class EventHandler extends \danog\MadelineProto\CombinedEventHandler
2940
{
30-
public function onAny($update, $path)
41+
public function onUpdateNewChannelMessage($update, $path)
42+
{
43+
yield $this->onUpdateNewMessage($update, $path);
44+
}
45+
public function onUpdateNewMessage($update, $path)
3146
{
3247
if (isset($update['message']['out']) && $update['message']['out']) {
3348
return;

‎examples/index.php‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Example script.
4+
*
5+
* Copyright 2016-2019 Daniil Gentili
6+
* (https://daniil.it)
7+
* This file is part of MadelineProto.
8+
* 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.
9+
* 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.
10+
* See the GNU Affero General Public License for more details.
11+
* You should have received a copy of the GNU General Public License along with MadelineProto.
12+
* If not, see <http://www.gnu.org/licenses/>.
13+
*
14+
* @author Daniil Gentili <daniil@daniil.it>
15+
* @copyright 2016-2019 Daniil Gentili <daniil@daniil.it>
16+
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
17+
*
18+
* @link https://docs.madelineproto.xyz MadelineProto documentation
19+
*/
20+
21+
require 'vendor/autoload.php';
22+
23+
$MadelineProto = new \danog\MadelineProto\API('session.madeline');
24+
$me = $MadelineProto->start();
25+
26+
$me = $MadelineProto->get_self();
27+
28+
\danog\MadelineProto\Logger::log($me);
29+
30+
if (!$me['bot']) {
31+
$MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => "Hi!\nThanks for creating MadelineProto! <3"]);
32+
$MadelineProto->channels->joinChannel(['channel' => '@MadelineProto']);
33+
34+
try {
35+
$MadelineProto->messages->importChatInvite(['hash' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg']);
36+
} catch (\danog\MadelineProto\RPCErrorException $e) {
37+
}
38+
39+
$MadelineProto->messages->sendMessage(['peer' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg', 'message' => 'Testing MadelineProto!']);
40+
}
41+
echo 'OK, done!'.PHP_EOL;

0 commit comments

Comments
 (0)