· 6 years ago · Sep 15, 2019, 01:30 PM
1//INDEX
2
3<?php
4echo '<h1 align="center">SilBot v 1.1 </h1>';
5$token = $_GET['api'];
6$api = $token;
7$idadmin = $_GET['admin'];
8$adminID = $idadmin;
9$userbot = $_GET['userbot'];
10$admin = array( //lista admin
11$adminID
12);
13
14$content = file_get_contents("php://input");
15$update = json_decode($content, true);
16$config = array(
17"db" => true, // true per usare un database mysql, false per non usarlo
18"tipo_db" => "mysql", //"mysql" per un database mysql, "json" per un database attraverso file json
19"anti_post_bug" => true, //Questa é una misura di sicurezza per evitare che alcune persone creino delle richieste false danneggiando il database mysql cambiando il parametro userbot
20//MYSQL
21"altervista" => true, //true se usi altervista, false se non lo usi
22"antiflood" => false, //true per abilitare l'antiflood, false per disabilitarlo. Trovi il file in plugins/antiflood.php. Funziona solo con Mysql
23"ip" => "localhost", // se non usi altervista metti l'indirizzo del database, di norma localhost se è hostato sullo stesso server
24"user" => "root" , //se non usi altervista inserisci il nome utente del DB
25"password" => "psw", //se non usi altervista inserisci la password di mysql
26"database" => "db", //se non usi altervista inserisci il nome del database
27//Json
28"jsondbname" => "database.json", //Il nome del file che contiene il database json o il path
29//TELEGRAM
30"action" => false, //true per mandare azioni come typing... e false per non mandare nulla
31"parse_mode"=> "HTML" ,//Formattazione presefinita messaggio, HTML, Markdown o none
32"disabilitapreview" => false, //False per permettere il web preview, true per disabilitarla
33"tastiera" => "inline" ,//Tastiera preferita, inline per quella inline e reply per la replykeyboard
34"funziona_modificati" => true, //Scegli se far eseguire i messaggi modificati
35"funziona_inoltrati" => false, //Scegli se far eseguire i messaggi inoltrati
36"funziona_canali" => true, //Scegli se far eseguire i messaggi inviati dai canali
37);
38
39if ($config["anti_post_bug"] && $userbot && $config["tipo_db"] == "mysql") {
40 $info = json_decode(file_get_contents("http://api.telegram.org/$api/getMe"),true);
41 if ($info["result"]["username"] != $userbot) {
42 exit;
43 }
44}
45include ("vars.php");
46include("functions.php");
47if ($config['db']){
48include("database.php");
49}
50include("comandi.php");
51$plugins = scandir("plugins"); unset($plugins[0]); unset($plugins[1]);
52$disabled = array("pluginno.php"); //Qui và la lista dei plugin disabilitati
53foreach($plugins as $plug) {
54 if (!in_array($plug, $disabled)) {
55 include("plugins/$plug");
56 }
57}
58
59
60//FINE INDEX
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75//DATABASE
76
77<?php
78
79echo "<br />Database";
80
81
82if($_GET['install'] and $_GET['userbot'])
83{
84if ($config['tipo_db'] == "json") {
85 touch($config["jsondbname"]);
86} elseif ($config['tipo_db'] == "mysql") {
87if ($config['altervista']) {
88$url = explode(".",$_SERVER["HTTP_HOST"]);
89$dir = dirname($_SERVER["PHP_SELF"]);
90$dir = substr($dir,1);
91$dbh = new PDO("mysql:host=localhost;dbname=my_".$url[0], $url[0], "");
92$dbh->query("CREATE TABLE IF NOT EXISTS ".$_GET['userbot']." (
93id int(0) AUTO_INCREMENT,
94chat_id bigint(0),
95username varchar(200),
96page varchar(200),
97PRIMARY KEY (id))");
98echo "<br>HO INSTALLATO IL DATABASE";
99} else {
100$dbh = new PDO("mysql:host=" . $config["ip"] . ";dbname=".$config['database'], $config['user'], $config['password']);
101$dbh->query("CREATE TABLE IF NOT EXISTS ".$_GET['userbot']." (
102id int(0) AUTO_INCREMENT,
103chat_id bigint(0),
104username varchar(200),
105page varchar(200),
106PRIMARY KEY (id))");
107echo "<br>HO INSTALLATO IL DATABASE";
108}
109
110}
111}
112if ($config['tipo_db'] == "json"){
113 $dbcontent = json_decode(file_get_contents($config["jsondbname"]), true);
114 if (!in_array($chatID, $dbcontent)) {
115 if ($chatID == $userID) {
116 $dbcontent[$chatID] = array(
117 "chat_id" => $chatID,
118 "username" => "$username",
119 "page" => "",
120 );
121 } else {
122 $dbcontent[$chatID] = array(
123 "chat_id" => $chatID,
124 "username" => "$usernamechat",
125 "page" => "",
126 );
127 if (!in_array($userID, $dbcontent)) {
128 $dbcontent[$userID] = array(
129 "chat_id" => $userID,
130 "username" => "$username",
131 "page" => "group",
132 );
133 }
134 }
135 } else {
136 if ($dbcontent[$chatID]["page"] == "ban") {
137 sm($chatID, "Sei bannato dall'utilizzo del Bot.");
138exit;
139 }
140 }
141jsonsave();
142} elseif ($config['tipo_db'] == "mysql") {
143 if ($config['altervista']){
144 $url = explode(".",$_SERVER["HTTP_HOST"]);
145 $dir = dirname($_SERVER["PHP_SELF"]);
146 $dir = substr($dir,1);
147 $db = new PDO("mysql:host=localhost;dbname=my_".$url[0], $url[0], "");
148 } else {
149 $db = new PDO("mysql:host=" . $config["ip"] . ";dbname=".$config['database'], $config['user'], $config['password']);
150 }
151
152 $tabella = $userbot;
153 if ($chatID < 0) {
154 $q = $db->query("select * from $tabella where chat_id = $chatID");
155 if(!$q->rowCount()) {
156 $db->query("insert into `$tabella` (chat_id, page, username) values ($chatID, ''," . '"'. $usernamechat.'"'.")");
157 }
158 }
159 if($userID){
160 $q = $db->query("select * from $tabella where chat_id = $userID");
161 if(!$q->rowCount()){
162 if ($userID == $chatID) {
163 $db->query("insert into `$tabella` (chat_id, page, username) values ($chatID, ''," . '"'. $username.'"'.")");
164 } else {
165 $db->query("insert into `$tabella` (chat_id, page, username) values ($userID, 'group'," . '"'. $username.'"'.")");
166 }
167 }else{
168 $u = $q->fetch(PDO::FETCH_ASSOC);
169
170 if($u['page'] == "disable"){
171 $db->query("update $tabella set page = '' where chat_id = $chatID");
172 }
173 if($u['page'] == "ban")
174 {
175 sm($chatID, "Sei bannato dall'utilizzo del Bot.");
176 exit;
177 }
178 }
179 }
180}
181
182
183//FINE DATABASE
184
185
186
187
188
189
190
191
192
193
194
195
196
197//GRUPPI
198
199<?php
200
201/*
202PLUGIN GRUPPI
203Versione 3.5
204*/
205echo "<br>Plugin Gruppi: 3.5";
206
207if ($chatID < 0)
208$replyID = $update["message"]["reply_to_message"]["from"]["id"];
209$replyNome = $update["message"]["reply_to_message"]["from"]["first_name"];
210$rmsgID = $update["message"]["reply_to_message"][message_id];
211
212//lasciare questo codice immutato
213$args = array(
214'chat_id' => $chatID
215);
216$add = sr("getChatAdministrators", $args);
217$admins = json_decode($add, true);
218foreach($admins['result'] as $adminsa)
219{
220if($adminsa['user']['id'] == $userID)
221$isadmin = true;
222
223if($adminsa["user"]["id"] == $userID and $adminsa["status"]=="creator")
224$isfounder=true;
225}
226
227
228/*
229Nelle condizioni if sarà possibile mettere
230$isadmin per verificare che solo gli Admin
231possano usare tale comando.
232
233esempio
234
235if(strpos(....) and $isadmin)
236{
237sm();
238//altri comandi
239}
240*/
241//lista Admin
242if(strpos(" ".$msg, "/admins"))
243{
244$shish = "Admin:";
245foreach($admins[result] as $ala)
246{
247if($ala[status] == "creator")
248{
249$shish .= "
250@".$ala[user][username]." [FONDATORE]";
251}else{
252$shish .= "
253@".$ala[user][username];
254}
255}
256sm($chatID, $shish);
257}
258
259
260
261
262if($update["message"]["new_chat_member"])
263{
264$nome = $update["message"]["new_chat_member"]["first_name"];
265$username = $update["message"]["new_chat_member"]["username"];
266$id = $update["message"]["new_chat_member"]["id"];
267
268$text = "Ciao $nome @$username $id, benvenuto nel gruppo. Per vedere le regole premi /regole";
269sm($chatID, $text);
270}
271
272
273if($update["message"]["left_chat_member"])
274{
275$nome = $update["message"]["left_chat_member"]["first_name"];
276$username = $update["message"]["left_chat_member"]["username"];
277$id = $update["message"]["left_chat_member"]["id"];
278
279$text = "Arrivederci $nome @$username $id.";
280sm($chatID, $text);
281}
282
283if($update["message"]["new_chat_title"])
284{
285$nuovo_nome = $update["message"]["new_chat_title"];
286
287$text = "Nuovo nome gruppo: $nuovo_nome";
288sm($chatID, $text);
289}
290
291if ($msg == "/membri") {
292 sm($chatID, membri($chatID));
293 }
294if ($msg == "/link") {
295sm($chatID, getlink($chatID));
296}
297//Il tempo va espresso in format YYYY-MM-DD HH:mm:ss esempio: 2018-01-01 21:14:00
298if(strpos($msg, "/ban")===0 and $isadmin)
299{
300 $arg = explode(" ", $msg, 2);
301$unix = strtotime("$arg[1]");
302if($replyID)
303{
304if ($arg[1]) {
305 sm($chatID, "Ho bannato $replyNome fino al $arg[1]");
306 ban($chatID, $replyID, $unix);
307} else {
308sm($chatID, "Ho bannato $replyNome.");
309ban($chatID, $replyID);
310}
311} else {
312$id = id($arg[1]);
313$unix = strtotime("$arg[2]");
314sm($chatID, "Ho bannato $arg[1] $id per $arg[2]");
315ban($chatID, $id, $unix);
316}
317}
318//Il tempo va espresso in format YYYY-MM-DD HH:mm:ss esempio: 2018-01-01 21:14:00
319if(strpos($msg, "/muta")===0 and $isadmin)
320{
321 $arg = explode(" ", $msg, 2);
322$unix = strtotime("$arg[1]");
323if($replyID)
324{
325if ($arg[1]) {
326 sm($chatID, "Ho bannato $replyNome fino al $arg[1]");
327 limita($chatID, $replyID, $unix, false,false,false,false);
328} else {
329sm($chatID, "Ho bannato $replyNome.");
330limita($chatID, $replyID,0,false,false,false,false);
331}
332} else {
333$id = id($arg[1]);
334$unix = strtotime("$arg[2]");
335sm($chatID, "Ho bannato $arg[1] $id per $arg[2]");
336limita($chatID, $id, $unix,false,false,false,false);
337}
338}
339if ($msg == "/unmuta") {
340if($replyID)
341{
342sm($chatID, "Ho unmuta $replyNome.");
343limita($chatID, $replyID);
344}
345}
346
347if(strpos($msg, "/kick")===0 and $isadmin)
348{
349if($replyID)
350{
351sm($chatID, "Ho kickato $replyNome.");
352ban($chatID, $replyID);
353unban($chatID, $replyID);
354}
355}
356
357if(strpos($msg, "/unban")===0 and $isadmin)
358{
359if($replyID)
360{
361sm($chatID, "Ho sbannato $replyNome.");
362unban($chatID, $replyID);
363}
364}
365if (stripos($msg, "/fissa")===0) {
366fissa($chatID,$rmsgID);
367}
368
369?>
370
371//FINE GRUPPI
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386//UTENTI
387
388<?php
389echo "<br>Plugin Utenti 3.0";
390//iscritti
391if ($config["db"]) {
392 if ($config['tipo_db'] == "json"){
393if(strpos($msg, "/iscritti")===0 and $isadmin ){
394$private = 0;
395$gruppi = 0;
396$usr= 0;
397$tot = count($dbcontent);
398foreach ($dbcontent as $us) {
399if ($us["chat_id"] > 0 && $us["page"] !== "group") {
400 $private++;
401} elseif ($us["page"] == "group") {
402 $usr++;
403} elseif ($us["chat_id"] < 0) {
404 $gruppi++;
405}
406
407}
408
409$iscritti = "*?ISCRITTI AL BOT*";
410$iscritti .= "\n ?Chat Private: $private";
411$iscritti .= "\n ?Chat Gruppi: $gruppi";
412
413$iscritti.= "\n\n*?UTENTI SUI GRUPPI*";
414$iscritti .= "\n ?Utenti: $usr";
415$iscritti .= "\n ?Utenti totali: $tot";
416sm($chatID, $iscritti,false,false,"markdown");
417}
418if(strpos($msg, "/post")===0 and $isadmin)
419{
420$t = array(array(array(
421"text" => "? Utenti",
422"callback_data" => "/2post 1"
423),
424array(
425"text" => "Gruppi ?",
426"callback_data" => "/2post 2"
427)),
428array(array(
429"text" => "? Utenti e Gruppi ?",
430"callback_data" => "/2post 3"
431)));
432
433sm($chatID, "Ok, dove vuoi inviare il messaggio globale?
434
435_Se selezioni gruppi, invia anche nei canali conosciuti._", $t, "inline", 'Markdown');
436}
437
438if(strpos($msg, "/2post")===0 and $isadmin)
439{
440$campo = explode(" ", $msg);
441$dbcontent[$chatID]["page"] = "post $campo[1]";
442jsonsave();
443$t = array(array(array(
444"text" => " Annulla",
445"callback_data" => "/apostannulla"
446)));
447
448cb_reply($cbid, "Ok!", false, $cbmid, "Ok $nome, invia ora il post globale che vuoi inviare.
449Formattazione: ".$config['parse_mode'], $t);
450
451}
452
453if(strpos($msg, "/apostannulla")===0 and $isadmin)
454{
455cb_reply($cbid, "Ok!", false, $cbmid, "Invio Post annullato");
456$dbcontent[$chatID]["page"] = "";
457jsonsave();
458exit;
459}
460
461if(strpos($dbcontent[$chatID]['page'], "post")===0)
462{
463if($msg)
464{
465//eseguo
466$s = explode(" ",$dbcontent[$chatID]['page']);
467$achi = $s[1];
468sm($chatID, "Post in viaggio verso gli utenti.");
469
470//salvo post in file
471$file = "lastpost.json";
472$f2 = fopen($file, 'w');
473fwrite($f2, $msg);
474fclose($f2);
475
476
477//invio
478foreach ($dbcontent as $usr) {
479if($achi == 1) if($usr["chat_id"] > 0) sm($usr["chat_id"], $msg, false, false,$config['parse_mode']) ;
480if($achi == 2) if($usr["chat_id"] < 0) sm($usr["chat_id"], $msg, false, false,$config['parse_mode']) ;
481if($achi == 3) sm($usr["chat_id"], $msg, false, false,$config['parse_mode']) ;
482}
483
484
485
486}else{
487sm($chatID, "Solo messaggi testuali.");
488}
489}
490
491
492
493//ban unban dal bot
494
495if(strpos($msg, "/ban ")===0 and $isadmin)
496{
497$campo = explode(" ", $msg);
498if (stripos($campo[1], "@")===0) {
499$id = id($campo[1]);
500} else {
501$id = $campo[1];
502}
503$db->query("update $tabella set page = 'ban' where chat_id = $userid");
504sm($chatID, "Ho bannato $campo[1] dal bot");
505}
506if(strpos($msg, "/unban ")===0 and $isadmin)
507{
508$campo = explode(" ", $msg);
509if (stripos($campo[1], "@")===0) {
510
511$id = id($campo[1]);
512} else {
513$id = $campo[1];
514}
515$db->query("update $tabella set page = '' where chat_id = $userid");
516sm($chatID, "Ho sbannato $campo[1]");
517}
518
519
520} elseif ($config['tipo_db'] == "mysql") {
521if(strpos($msg, "/iscritti")===0 and $isadmin )
522{
523
524$qcp = $db->query("select * from $tabella where not page = 'disable' and not page='group' and chat_id>0");
525$qcg = $db->query("select * from $tabella where not page = 'disable' and chat_id<0");
526$cp = $qcp->rowCount();
527$cg = $qcg->rowCount();
528
529//morti
530$mqcp = $db->query("select * from $tabella where page = 'disable' and chat_id>0");
531$mqcg = $db->query("select * from $tabella where page = 'disable' and chat_id<0");
532$mcp = $mqcp->rowCount();
533$mcg = $mqcg->rowCount();
534
535//utenti
536
537$gr = $db->query("select * from $tabella where page = 'group' and chat_id>0");
538$gru = $gr -> rowCount();
539
540$iscritti = "*?ISCRITTI AL BOT*";
541$iscritti .= "\n ?Chat Private: $cp";
542$iscritti .= "\n ?Chat Gruppi: $cg";
543
544$iscritti .= "\n\n*?MORTI*";
545$iscritti .= "\n ?Chat Private: $mcp";
546$iscritti .= "\n ?Chat Gruppi: $mcg";
547
548$iscritti.= "\n\n*?UTENTI SUI GRUPPI*";
549$iscritti .= "\n ?Utenti: $gru
550";
551sm($chatID, $iscritti,false,false,"markdown");
552}
553//post globali
554
555
556if(strpos($msg, "/post")===0 and $isadmin)
557{
558$t = array(array(array(
559"text" => "? Utenti",
560"callback_data" => "/2post 1"
561),
562array(
563"text" => "Gruppi ?",
564"callback_data" => "/2post 2"
565)),
566array(array(
567"text" => "? Utenti e Gruppi ?",
568"callback_data" => "/2post 3"
569)));
570
571sm($chatID, "Ok, dove vuoi inviare il messaggio globale?
572
573_Se selezioni gruppi, invia anche nei canali conosciuti._", $t, "inline", 'Markdown');
574}
575
576if(strpos($msg, "/2post")===0 and $isadmin)
577{
578$campo = explode(" ", $msg);
579$db->query("update $tabella set page = 'post $campo[1]' where chat_id = $chatID");
580
581$t = array(array(array(
582"text" => " Annulla",
583"callback_data" => "/apostannulla"
584)));
585
586cb_reply($cbid, "Ok!", false, $cbmid, "Ok $nome, invia ora il post globale che vuoi inviare.
587Formattazione: ".$config['parse_mode'], $t);
588
589}
590
591if(strpos($msg, "/apostannulla")===0 and $isadmin)
592{
593cb_reply($cbid, "Ok!", false, $cbmid, "Invio Post annullato");
594$db->query("update $tabella set page = '' where chat_id = $chatID");
595exit;
596}
597if(strpos($u['page'], "post")===0)
598{
599if($msg)
600{
601//eseguo
602$s = explode(" ",$u['page']);
603$achi = $s[1];
604$db->query("update $tabella set page = '' where chat_id = $chatID");
605if($achi == 1) $q = "where chat_id>0 and not page='group'";
606if($achi == 2) $q = "where chat_id<0 and not page='group'";
607if($achi == 3) $q = " where 1 and not page='group'";
608$query = $db->query("SELECT * FROM $tabella $q");
609$c = $query->rowCount();
610sm($chatID, "Post in viaggio verso $c utenti.");
611$tot = 0;
612foreach ($query as $user) {
613 $tot++;
614 $id = $user["chat_id"];
615 sm($id, $msg);
616 if ($tot > $c) { //Misura di sicurezza, se vi dà problemi togliete questo if.
617 sm($chatID, "Invio completato, post inviato a $tot utenti.");
618 exit;
619 }
620}
621sm($chatID, "Invio completato, post inviato a $tot utenti.");
622
623}else{
624sm($chatID, "Solo messaggi testuali.");
625}
626}
627
628//ban unban dal bot
629
630if(strpos($msg, "/ban ")===0 and $isadmin)
631{
632$campo = explode(" ", $msg);
633if (stripos($campo[1], "@")===0) {
634$id = id($campo[1]);
635} else {
636$id = $campo[1];
637}
638$db->query("update $tabella set page = 'ban' where chat_id = $id");
639sm($chatID, "Ho bannato $campo[1] dal bot");
640}
641if(strpos($msg, "/unban ")===0 and $isadmin)
642{
643$campo = explode(" ", $msg);
644if (stripos($campo[1], "@")===0) {
645
646$id = id($campo[1]);
647} else {
648$id = $campo[1];
649}
650$db->query("update $tabella set page = '' where chat_id = $id");
651sm($chatID, "Ho sbannato $campo[1]");
652}
653}
654}
655
656//FINE UTENTI