· 6 years ago · Jan 01, 2020, 07:36 PM
1<?php
2/*
3 _____ _ _ _ _ _ _ _ _ _
4 ____ / ____| | | | | | | (_) (_) | | | (_) V5.0.0
5 / __ \| (___ | |_ __ _ _ __ __| | __ _ _ __ __| | | _ _ __ ___ _| |_ __ _| |_ _
6 / / _` |\___ \| __/ _` | '_ \ / _` |/ _` | '__/ _` | | | | '_ ` _ \| | __/ _` | __| |
7 | | (_| |____) | || (_| | | | | (_| | (_| | | | (_| | |____| | | | | | | | || (_| | |_| |
8 \ \__,_|_____/ \__\__,_|_| |_|\__,_|\__,_|_| \__,_|______|_|_| |_| |_|_|\__\__,_|\__|_|
9 \____/
10 Base per creare LimitatiBot in PHP 7. Creata da @cianoscatolo.
11 __ ___ ___ __ __ __
12 | |\ | | \ |__ \_/ |__ / ` / \ |\/| /\ |\ | | \ |
13 | | \| |__/ |___ / \ |___ \__, \__/ | | /~~\ | \| |__/ |
14Modifica questo file solo se sai quello che fai. Leggi le docs.
15This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
16*/
17ini_set('display_errors', 1);
18ini_set('display_startup_errors', 1);
19error_reporting(E_ERROR | E_PARSE);
20echo '<br><b>StandardLimitati</b> by <a href=\'htpps://t.me/NetworkCiano\'>NetworkCiano</a> - Versione 5.0.0';
21$api = $_GET['apikey'];
22$update = json_decode(file_get_contents('php://input'), true);
23include 'settings.php';
24require_once 'functions.php';
25//Connessione al Database
26$db = new PDO('mysql:host=' . $host . ';dbname='.$wdb, $dbuser, $dbpass);
27$db->exec('SET NAMES utf8mb4');
28//Creazione tabella al primo avvio
29if($INSTALLAZIONE == true) {
30 $db->query('CREATE TABLE IF NOT EXISTS '.$tabella.' (
31 id int(0) AUTO_INCREMENT,
32 chat_id bigint(0),
33 username varchar(200),
34 page varchar(200),
35 admin int(1),
36 PRIMARY KEY (id))');
37 $errorInfo = $db->errorInfo();
38 if($errorInfo[0] == 00000 and !$errorInfo[1] and !$errorInfo[2]) {
39 sm($chatID, 'La tabella 1 è stata creata con successo.');
40 }else{
41 sm($chatID, 'La creazione della tabella 1 è fallita.');
42 }
43 $db->query('CREATE TABLE IF NOT EXISTS '.'msg'.$tabella.' (
44 id int(0) AUTO_INCREMENT,
45 msgid int(0),
46 sender int(0),
47 reciever int(0),
48 txt text(0),
49 PRIMARY KEY (id))');
50 $errorInfo = $db->errorInfo();
51 if($errorInfo[0] == 00000 and !$errorInfo[1] and !$errorInfo[2]) {
52 sm($chatID, 'La tabella 2 è stata creata con successo.');
53 }else{
54 sm($chatID, 'La creazione della tabella 2 è fallita.');
55 }
56}
57$uquery = $db->prepare("SELECT * FROM $tabella WHERE chat_id = :id LIMIT 1");
58$uquery->execute(array('id' => $userID));
59$u = $uquery->fetch(PDO::FETCH_ASSOC);
60if($u['page'] == 'ban' or $chatID < 0) exit; //ban + non usare nei gruppi
61if(!$u['id'] and $chatID > 0) $db->query("INSERT into `$tabella` (chat_id, page, username) VALUES ($chatID, ''," . '"'. $username.'"'.")"); //Se non sei nel DB, vieni inserito
62if($u['username'] != $username) $db->query("UPDATE $tabella SET username = '$username' WHERE chat_id = '$userID'"); //Aggiorna l'username nel DB se viene cambiato
63//Menu del bot
64if(!$directChat) {
65 $menustart = [
66 [
67 [
68 'text' => '? Live Chat',
69 'callback_data' => '/chat'
70 ],
71 ],
72 [
73 [
74 'text' => $btnComando,
75 'callback_data' => '/demo'
76 ],
77 [
78 'text' => '?️ Gruppo',
79 'url' => 'https://t.me/Hwgrouptech'
80 ],
81 ],
82 ];
83 if ($msg === '/start') {
84 sm($chatID, $startmsg, $menustart);
85 }
86 if ($msg === '/stop') {
87 if(strpos($u['page'], 'chat-') === 0) sm($chatID, '<b>Chat chiusa.</b>');
88 $db->query("UPDATE $tabella SET page = '' WHERE chat_id = '$userID'");
89 }
90 if ($msg === '/back') {
91 if($cbid) cb_reply($cbid, '', true, $cbmid, $startmsg, $menustart);
92 if(!$cbid) sm($chatID, $startmsg, $menustart);
93 $db->query("UPDATE $tabella SET page = '' WHERE chat_id = '$userID'");
94 }
95}
96if($msg === '/demo') {
97 $menu = [
98 [
99 [
100 'text' => '? Indietro',
101 'callback_data' => '/back'
102 ],
103 ],
104 ];
105 cb_reply($cbid, false, true, $cbmid, $msgextra, $menu);
106}
107//Funzione chat - Utente
108if(strpos($msg, '/chat') === 0 or $msg === '/start' and $directChat == true) {
109 $adminsquery = $db->query("SELECT * FROM $tabella WHERE admin = 1");
110 $admins = $adminsquery->fetchAll(PDO::FETCH_ASSOC);
111 $adminscount = $adminsquery->rowCount();
112 $num = array_rand($admins);
113 if($btnCambiaOperatore) {
114 $campo = explode(' ', $msg)[1];
115 if($campo === '') $campo = 666;
116 if($num == $campo) {
117 $original = $num;
118 $tries = 0;
119 while($num == explode(' ', $msg)[1]) {
120 $num = rand(0, $adminscount-1);
121 $tries = $tries+1;
122 if($tries == 100) {
123 $num = 666;
124 }
125 }
126 if($num == 666) {
127 cb_reply($cbid, false, true, $cbmid, 'Errore. Il creatore del bot deve disabilitare $btnCambiaOperatore, in quanto esiste solo un operatore. Sei stato disconnesso.');
128 exit;
129 }
130 }
131 $menu[] = [
132 [
133 'text' => '? Cambia operatore',
134 'callback_data' => '/chat '.$num
135 ]
136 ];
137 }
138 if(!$directChat) {
139 $menu[] = [
140 [
141 'text' => '? Indietro',
142 'callback_data' => '/back'
143 ],
144 ];
145 }
146 if($adminsAnonymous) {
147 $t = 'l\'admin '.$num+1; //nb: il +1 è per evitare che dica "admin 0"
148 }else{
149 $numb = $num+1;
150 $t = '@'.$admins[$num]['username'].' (N° '.$numb.')';
151 }
152 $testo = "<b>Sono in ascolto!</b>\nScrivi pure quello che vuoi, tra poco risponderò!\nPer uscire dalla Live Chat clicca su /stop.";
153 if($cbid) cb_reply($cbid, false, true, $cbmid, $testo, $menu);
154 if(!$cbid) sm($chatID, $testo, $menu);
155 $db->query("UPDATE $tabella SET page = 'chat-".$admins[$num]['chat_id']."' WHERE chat_id = '$userID'");
156}
157if('bot'.$msg === $api and $acceptToken) {
158 $db->query("UPDATE $tabella SET admin = '1' WHERE chat_id = '".$userID."'");
159 sm($chatID, 'Ok! Sei stato reso admin. Ora sarebbe meglio disattivare $acceptToken da settings.php, per evitare intrusioni.');
160}
161if(strpos($u['page'], 'chat-') === 0 and strpos($msg, '/') !== 0) {
162 if(!$msg and !$acceptMedia) {
163 sm($chatID, '?⃠ Gli admins del bot hanno <b>disabilitato la ricezione di media.</b>');
164 exit;
165 }
166 if($everyAdminRecieves) {
167 $adminsquery = $db->query("SELECT * FROM $tabella WHERE admin = 1");
168 $admins = $adminsquery->fetchAll(PDO::FETCH_ASSOC);
169 foreach($admins as $singleAdmin) {
170 $msgid = json_decode(forward($singleAdmin['chat_id'], $chatID, $messageid), true)['result']['message_id'];
171 $insert = $db->prepare("INSERT into `msg$tabella` (msgid, sender, reciever, txt) VALUES ('$msgid', '$chatID', '".$singleAdmin['chat_id']."', :msg)");
172 $insert = $db->execute([':msg' => $msg]);
173 }
174 if($notifySentUser) sm($chatID, 'Messaggio inviato.');
175 exit;
176 }
177 $idadmin = explode('-', $u['page'])[1];
178 if($notifySentUser) sm($chatID, 'Messaggio inviato.');
179 $msgid = json_decode(forward($idadmin, $chatID, $messageid), true)['result']['message_id'];
180 $db->query("INSERT into `msg$tabella` (msgid, sender, reciever) VALUES ('$msgid', '$chatID', '$idadmin')");
181}
182if($u['admin'] == 1) {
183 if($msg === '/commands') {
184 sm($chatID, "??♂️ <b>Comandi Admin:</b>\n*: in reply\n\n/admin & /unadmin *\n/ban & /unban *\n/transfer *\n/usinfo *\n/post\n/users");
185 }
186 if($msg === '/post') {
187 $db->query("UPDATE $tabella SET page = 'post' WHERE chat_id = '".$userID."'");
188 $menu = [
189 [
190 [
191 'text' => '? Annulla',
192 'callback_data' => '/back'
193 ]
194 ]
195 ];
196 sm($chatID, '? <b>Invia ora</b> il messaggio da mandare. <a href=\'https://cutt.ly/0e1qFiL\'>[!]</a>', $menu);
197 }
198 if($u['page'] === 'post' and strpos($msg, '/') !== 0) {
199 $everyuquery = $db->query("SELECT chat_id FROM `$tabella`");
200 $everyu = $everyuquery->fetchAll(PDO::FETCH_ASSOC);
201 $users = $everyuquery->rowCount();
202 sm($chatID, '↪️ Inizio a <b>inviare il post</b> a '.$users.' utenti.');
203 foreach($everyu as $singleu) {
204 sm($singleu['chat_id'], $msg);
205 }
206 sm($chatID, '✅ Fatto, <b>post inviato.</b>');
207 $db->query("UPDATE $tabella SET page = '' WHERE chat_id = '".$userID."'");
208 }
209 if($msg === '/users') {
210 $everyuquery = $db->query("SELECT chat_id FROM `$tabella`");
211 $users = $everyuquery->rowCount();
212 sm($chatID, '? <b>Il bot conta '.$users.' utenti.</b>');
213 }
214 if(strpos($msg, '/connect') === 0) {
215 $campo = explode(' ', $msg);
216 $persona = $campo[1];
217 $admin = $campo[2];
218 $db->query("UPDATE $tabella SET page = 'chat-$admin' WHERE chat_id = '".$persona."'");
219 if($adminsAnonymous) {
220 $txt = 'un altro admin';
221 }else{
222 $txt = $admin;
223 }
224 sm($persona, '? <b>Sei stato messo in contatto con</b> '.$txt.'. Perchè possa risponderti, scrivi un messaggio.');
225 sm($admin, $username.' ti ha messo in contatto con '.$persona);
226 sm($chatID, 'Fatto.');
227 }
228 if($replyto) {
229 $replyquery = $db->prepare("SELECT * FROM `msg$tabella` WHERE msgid = :id LIMIT 1");
230 $replyquery->execute(array('id' => $replyto));
231 $reply = $replyquery->fetch(PDO::FETCH_ASSOC);
232 if(strpos($msg, '/usinfo') === 0) {
233 $infoquery = $db->prepare("SELECT * FROM `$tabella` WHERE chat_id = :id LIMIT 1");
234 $infoquery->execute(array('id' => $reply['sender']));
235 $info = $infoquery->fetch(PDO::FETCH_ASSOC);
236 if(!$info['id']) {
237 sm($chatID, 'Errore, l\'utente non è nel database. Potresti averlo eliminato, forse Marte era allineata con Plutone e l\'utente non è stato registrato correttamente nel db, che ne so. O più semplicemente stai rispondendo a un messaggio del bot, cretino.');
238 exit;
239 }
240 sm($chatID, '? <b>Informazioni sull\' utente</b> @'.$info['username']."\nUserID: <code>".$info['chat_id']."</code>\nN° iscritto: <code>".$info['id']."</code>\nStatus: <code>".$info['page'].'</code>');
241 exit;
242 }
243 if(strpos($msg, '/transfer') === 0) {
244 $adminsquery = $db->query("SELECT * FROM $tabella WHERE admin = 1");
245 $admins = $adminsquery->fetchAll(PDO::FETCH_ASSOC);
246 foreach($admins as $singleAdmin) {
247 $menu[][] = ['text' => $singleAdmin['username'], 'callback_data' => '/connect '.$reply['sender'].' '.$singleAdmin['chat_id']];
248 }
249 sm($chatID, '? <b>Seleziona l\'admin</b> a cui vuoi inoltrare l\'utente', $menu);
250 exit;
251 }
252 if(strpos($msg, '/admin') === 0) {
253 $db->query("UPDATE $tabella SET admin = '1' WHERE chat_id = '".$reply['sender']."'");
254 sm($chatID, 'Utente reso Admin.');
255 sm($reply['sender'], '??♂️ <b>Sei stato reso Admin</b>');
256 exit;
257 }
258 if(strpos($msg, '/unadmin') === 0) {
259 $db->query("UPDATE $tabella SET admin = '0' WHERE chat_id = '".$reply['sender']."'");
260 sm($chatID, 'Utente tolto dagli Admins.');
261 sm($reply['sender'], '? <b>Sei stato tolto dagli Admins</b>');
262 exit;
263 }
264 if(strpos($msg, '/ban') === 0) {
265 $db->query("UPDATE $tabella SET page = 'ban' WHERE chat_id = '".$reply['sender']."'");
266 sm($chatID, 'Utente bannato.');
267 sm($reply['sender'], '? <b>Sei stato bannato!</b> Non potrai più utilizzare il bot.');
268 exit;
269 }
270 if(strpos($msg, '/unban') === 0) {
271 $db->query("UPDATE $tabella SET page = 'chat-$userID' WHERE chat_id = '".$reply['sender']."'");
272 sm($chatID, 'Utente sbannato.');
273 sm($reply['sender'], '✅ <b>Sei stato sbannato!</b> Ora puoi utilizzare il bot.');
274 exit;
275 }
276 if($adminsAnonymous) {
277 if(!$msg) {
278 sm($chatID, 'Visto che $adminsAnonymous è impostato su true, non puoi inviare media.');
279 exit;
280 }
281 sm($reply['sender'], ''.$msg);
282 }else{
283 forward($reply['sender'], $chatID, $messageid);
284 }
285 if($notifySentAdmin) sm($chatID, 'Risposta inviata.');
286 }
287}