-
-
Notifications
You must be signed in to change notification settings - Fork 871
Expand file tree
/
Copy pathsecret_bot.php
More file actions
executable file
·184 lines (166 loc) · 5.83 KB
/
Copy pathsecret_bot.php
File metadata and controls
executable file
·184 lines (166 loc) · 5.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php declare(strict_types=1);
/**
* Secret chat 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-2025 Daniil Gentili <daniil@daniil.it>
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
use danog\MadelineProto\EventHandler\Attributes\Handler;
use danog\MadelineProto\EventHandler\Message;
use danog\MadelineProto\EventHandler\Message\PrivateMessage;
use danog\MadelineProto\EventHandler\Message\SecretMessage;
use danog\MadelineProto\EventHandler\SimpleFilter\Incoming;
use danog\MadelineProto\LocalFile;
use danog\MadelineProto\Logger;
use danog\MadelineProto\Settings;
use danog\MadelineProto\SimpleEventHandler;
/*
* 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';
}
class SecretHandler extends SimpleEventHandler
{
private array $sent = [];
/**
* @var int|string Username or ID of bot admin
*/
public const ADMIN = "danogentili"; // Change this
/**
* Get peer(s) where to report errors.
*
* @return int|string|array
*/
public function getReportPeers()
{
return [self::ADMIN];
}
public function onStart(): void
{
}
/**
* Join the group call of a group or channel, and stream a video file into it.
*
* Send /joinGroupCall in a group that has an active video chat. The media is read from a.mkv,
* a WebM/Matroska file holding VP8 video and OPUS audio: MadelineProto demuxes it in pure PHP
* and sends the frames as-is, so neither ffmpeg nor the FFI extension is required.
*/
#[Handler]
public function joinGroupCall(Incoming&Message $update): void
{
if ($update->message !== '/joinGroupCall') {
return;
}
$call = $this->getGroupCall($update->chatId);
if ($call === null) {
$update->reply('There is no active group call in this chat!');
return;
}
$file = new LocalFile(__DIR__.'/a.mkv');
if (!file_exists($file->file)) {
$update->reply('a.mkv is missing, cannot stream anything.');
return;
}
$call->join();
$call->playVideo($file);
$update->reply("Joined {$call} and started streaming a.mkv!");
}
/**
* Handle updates from users.
*/
#[Handler]
public function handleNormalMessage(Incoming&PrivateMessage $update): void
{
if ($update->message === 'request') {
$this->requestSecretChat($update->senderId);
}
if ($update->message === 'ping') {
$update->reply('pong');
}
}
/**
* Handle secret chat messages.
*/
#[Handler]
public function handle(Incoming&SecretMessage $update): void
{
if ($update->media) {
$path = $update->media->downloadToDir('/tmp');
$update->reply($path);
}
if (isset($this->sent[$update->chatId])) {
return;
}
// Photo, secret chat
$this->sendPhoto(
peer: $update->chatId,
file: new LocalFile('tests/faust.jpg'),
caption: 'This file was uploaded using MadelineProto',
);
// Photo as document, secret chat
$this->sendDocumentPhoto(
peer: $update->chatId,
file: new LocalFile('tests/faust.jpg'),
caption: 'This file was uploaded using MadelineProto',
);
// GIF, secret chat
$this->sendGif(
peer: $update->chatId,
file: new LocalFile('tests/pony.mp4'),
caption: 'This file was uploaded using MadelineProto',
);
// Sticker, secret chat
$this->sendSticker(
peer: $update->chatId,
file: new LocalFile('tests/lel.webp'),
mimeType: "image/webp"
);
// Document, secret chat
$this->sendDocument(
peer: $update->chatId,
file: new LocalFile('tests/60'),
fileName: 'fairy'
);
// Video, secret chat
$this->sendVideo(
peer: $update->chatId,
file: new LocalFile('tests/swing.mp4'),
);
// audio, secret chat
$this->sendAudio(
peer: $update->chatId,
file: new LocalFile('tests/mosconi.mp3'),
);
$this->sendVoice(
peer: $update->chatId,
file: new LocalFile('tests/mosconi.mp3'),
);
$i = 0;
while ($i < 10) {
$this->logger("SENDING MESSAGE $i TO ".$update->chatId);
// You can also use the sendEncrypted parameter for more options in secret chats
$this->sendMessage(peer: $update->chatId, message: (string) ($i++));
}
$this->sent[$update->chatId] = true;
}
}
$settings = new Settings;
$settings->getLogger()->setLevel(Logger::ULTRA_VERBOSE);
SecretHandler::startAndLoop('user.madeline', $settings);