Advertisement
GigilinE

Untitled

Jun 12th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 54.02 KB | None | 0 0
  1. <?php
  2. function processMessage($message)
  3. {
  4. $getchat = apiRequestJson("getChat", array(
  5. 'chat_id' => $message['chat']['id']
  6. ));
  7. $getchatadministrator = apiRequestJson("getChatAdministrators", array(
  8. 'chat_id' => $message['chat']['id']
  9. ));
  10. $getchatmember = apiRequestJson("getChatMember", array(
  11. 'chat_id' => $message['chat']['id'],
  12. 'user_id' => $message['from']['id']
  13. ));
  14. $getchatmemberscount = apiRequestJson("getChatMembersCount", array(
  15. 'chat_id' => $message['chat']['id']
  16. ));
  17.  
  18.  
  19. $keepcalm = "Stai calmo";
  20.  
  21. //assegno le variabili dalla lettura del json
  22. //CHAT
  23. $chat_type = $message['chat']['type'];
  24. $chat_title = $message["chat"]['title'];
  25. $chat_id = $message['chat']['id'];
  26. //GET CHAT MEMBER USER
  27. $getchatmember_id = $getchatmember['user']['id'];
  28. $getchatmember_firstname = $getchatmember['user']['first_name'];
  29. $getchatmember_lastname = $getchatmember['user']['last_name'];
  30. $getchatmember_username = $getchatmember['user']['username'];
  31. $getchatmember_status = $getchatmember['status'];
  32. //GET CHAT
  33. $getchat_id = $getchat['id'];
  34. $getchat_firstname = $getchat['first_name'];
  35. $getchat_lastname = $getchat['last_name'];
  36. $getchat_username = $getchat['username'];
  37. $getchat_type = $getchat['type'];
  38. //GET CHAT ADMINISTRATOR
  39. $getchatadministrator_id = $getchatadministrator['user']['id'];
  40. $getchatadministrator_firstname = $getchatadministrator['user']['first_name'];
  41. $getchatadministrator_username = $getchatadministrator['user']['username'];
  42. $getchatadministrator_status = $getchatadministrator['status'];
  43. //FROM
  44. $from_firstname = $message["from"]['first_name'];
  45. $from_lastname = $message['from']['last_name'];
  46. $from_username = $message["from"]['username'];
  47. $from_id = $message['from']['id'];
  48. //FORWARD
  49. $forward_id = $message['forward_from']['id'];
  50. $forward_firstname = $message['forward_from']['first_name'];
  51. $forward_lastname = $message['forward_from']['last_name'];
  52. $forward_username = $message['forward_from']['username'];
  53. //MESSAGE
  54. $message_id = $message['message_id'];
  55. $text = $message['text'];
  56. //NEW PARTECIPANT
  57. $newchatmember_id = $message['new_chat_member']['id'];
  58. $newchatmember_firstname = $message['new_chat_member']['first_name'];
  59. $newchatmember_username = $message['new_chat_member']['username'];
  60. //LEFT PARTECIPANT
  61. $leftchatmember_id = $message['left_chat_member']['id'];
  62. $leftchatmember_firstname = $message['left_chat_member']['first_name'];
  63. $leftchatmember_username = $message['left_chat_member']['username'];
  64.  
  65. // parametri per la connessione al DB
  66. include("core/config.php");
  67. // avvio la connessione al DB
  68. $conn = mysqli_connect($servernameDB, $usernameDB, $passwordDB, $nameDB);
  69. //controllo eventuali errori
  70. if (!$conn) {
  71. die("Connection failed: " . $conn->connect_error);
  72. }
  73. //richiamo le classi per gli RSS
  74. include("core/rssnews.php");
  75. //ricerca di user già inseriti o da inserire e notifico se c'è inserimento
  76. $sqlquery = "SELECT telegram_id FROM g1g1l1n3_users WHERE telegram_id =" . $from_id;
  77. $result = mysqli_query($conn, $sqlquery);
  78. if (mysqli_num_rows($result) == 0) {
  79. $sql = mysqli_query($conn, "INSERT INTO g1g1l1n3_users (firstname, lastname, username, telegram_id, gender, age, language_user, msg_count, state_bot, state_ban, state_bot_super, users_score) VALUES ('$from_firstname','$from_lastname','$from_username','$from_id', '', 0, 'notset', 0, 1, 0, 0, 3)") or die("Query inserimento: " . mysql_error());
  80. $sqlquerydue = "SELECT telegram_id FROM g1g1l1n3_users";
  81. $resultdue = mysqli_query($conn, $sqlquerydue);
  82. echo mysqli_num_rows($resultdue);
  83. apiRequestJson("sendMessage", array(
  84. 'chat_id' => "13699180",
  85. "text" => "L'user " . $from_firstname . " " . $from_lastname . " " . $from_username . " con ID: " . $from_id . " è stato aggiunto al database"
  86. ));
  87. }
  88. //ricerca gruppo inserito o da inserire e notifico se c'è inserimento
  89. if (strripos($chat_id, "-") !== false) {
  90. $sqlquery = "SELECT telegram_group_id FROM g1g1l1n3_group WHERE telegram_group_id =" . $chat_id;
  91. $result = mysqli_query($conn, $sqlquery);
  92. if (mysqli_num_rows($result) == 0) {
  93. $sql = mysqli_query($conn, "INSERT INTO g1g1l1n3_group (name_group, telegram_group_id, language_group, state_bot, state_welcome) VALUES ('$chat_title', '$chat_id', '', 1, 1)") or die("Query inserimento: " . mysql_error());
  94. $sqlquerydue = "SELECT telegram_group_id FROM g1g1l1n3_group";
  95. $resultdue = mysqli_query($conn, $sqlquerydue);
  96. echo mysqli_num_rows($resultdue);
  97. apiRequestJson("sendMessage", array(
  98. 'chat_id' => "13699180",
  99. "text" => "Il gruppo " . $chat_title . "con ID: " . $chat_id . " è stato aggiunto al database"
  100. ));
  101. } else {
  102. //non fare nulla
  103. echo "non ha fatto nulla";
  104. }
  105. }
  106. //seleziono stato del bot gruppo, stato ban gruppo, stato bot generale, stato benvenuto, id del gruppo, lingua gruppo
  107. $selectGroup = "SELECT * FROM g1g1l1n3_group WHERE $chat_id = telegram_group_id";
  108. $resultGroup = $conn->query($selectGroup);
  109. if ($resultGroup->num_rows > 0) {
  110. // output data of each row
  111. while ($row = $resultGroup->fetch_assoc()) {
  112. $printGroupStateBot = $row["state_bot"];
  113. $printGroupStateBan = $row["state_ban"];
  114. $printStateBotWelcome = $row["state_welcome"];
  115. $printTelegramGroupId = $row["telegram_group_id"];
  116. $printLanguageGroup = $row["language_group"];
  117. }
  118. }
  119. //seleziono stato bot, stato ban users, stato bot generale, lingua users
  120. $selectGroup = "SELECT * FROM g1g1l1n3_users WHERE $chat_id = telegram_id";
  121. $resultGroup = $conn->query($selectGroup);
  122. if ($resultGroup->num_rows > 0) {
  123. // output data of each row
  124. while ($row = $resultGroup->fetch_assoc()) {
  125. $printUsersStateBot = $row["state_bot"];
  126. $printUsersStateBan = $row["state_ban"];
  127. $printLanguageUsers = $row["language_user"];
  128. }
  129. }
  130.  
  131. //seleziono stato bot, stato ban users, stato bot generale, lingua users
  132. $selectUsernameDB = "SELECT * FROM g1g1l1n3_users WHERE $from_id = telegram_id";
  133. $resultUsernameDB = $conn->query($selectUsernameDB);
  134. if ($resultUsernameDB->num_rows > 0) {
  135. // output data of each row
  136. while ($row = $resultUsernameDB->fetch_assoc()) {
  137. $printUsersStateUsername = $row["username"];
  138. }
  139. }
  140.  
  141. //Carico i settings del bot
  142. $selectSettingsDB = "SELECT * FROM g1g1l1n3_settings";
  143. $resultSettingsDB = $conn->query($selectSettingsDB);
  144. if ($resultSettingsDB->num_rows > 0) {
  145. // output data of each row
  146. while ($row = $resultSettingsDB->fetch_assoc()) {
  147. $printSettingsStateBotSuper = $row["state_bot_super"];
  148. $printSettingsStateMsgTime = $row["state_msg_time"];
  149. $printSettingsStateMsgCount = $row["state_msg_count"];
  150. }
  151. }
  152.  
  153.  
  154. if ((("$printUsersStateUsername" == "") and ("$from_username" != "")) or ("$printUsersStateUsername" != "$from_username")) {
  155. $sql = mysqli_query($conn, "UPDATE g1g1l1n3_users SET firstname = '$from_firstname', lastname = '$from_lastname', username = '$from_username' WHERE telegram_id = $from_id");
  156. apiRequestJson("sendMessage", array(
  157. 'chat_id' => "13699180",
  158. "text" => "L'user " . $from_firstname . " " . $from_lastname . " " . $from_username . " con ID: " . $from_id . " è stato aggiornato"
  159. ));
  160. }
  161. //applico le icone a variabili
  162. if (($printLanguageGroup == "italian") or ($printLanguageUsers == "italian")) {
  163. $printIconLanguage = "🇮🇹";
  164. } else if (($printLanguageGroup == "english") or ($printLanguageUsers == "english")) {
  165. $printIconLanguage = "🇬🇧";
  166. }
  167. //controllo se nel json il testo è presente
  168. if (isset($message['text'])) {
  169. check_spam($chat_id, $from_id, $getchatmember_id, $message["date"], $printSettingsStateMsgTime, $printSettingsStateMsgCount);
  170. //controllo lo stato generale del sistema
  171. if (($text == "stato sistema") and ($from_id == "13699180")) {
  172. if ($chat_type == "private") {
  173. apiRequest("sendChatAction", array(
  174. 'chat_id' => $chat_id,
  175. 'action' => "typing"
  176. ));
  177. apiRequestJson("sendMessage", array(
  178. 'chat_id' => $chat_id,
  179. "text" => "💻 Impostazioni sistema ($chat_id) 💻\n\nlingua : $printIconLanguage\narmatura : $printSettingsStateBotSuper\nstato bot : $printUsersStateBot\n"
  180. ));
  181. } else if (($chat_type == "group") or ($chat_type == "supergroup")) {
  182. apiRequest("sendChatAction", array(
  183. 'chat_id' => $chat_id,
  184. 'action' => "typing"
  185. ));
  186. apiRequestJson("sendMessage", array(
  187. 'chat_id' => $chat_id,
  188. "text" => "💻 State System ($chat_id) 💻\n\nlang : $printIconLanguage\nwelcome : $printStateBotWelcome\narmor : $printSettingsStateBotSuper\nstate bot : $printGroupStateBot\nnum msg at second : $printSettingsStateMsgTime\nnum second msg : $printSettingsStateMsgCount"
  189. ));
  190. }
  191. //comando per l'avvio del bot
  192. } else if (strpos($text, "/start") === 0) {
  193. if ($chat_id == "-1001062287469") {
  194. apiRequest("sendChatAction", array(
  195. 'chat_id' => $chat_id,
  196. 'action' => "typing"
  197. ));
  198. apiRequest("sendMessage", array(
  199. 'chat_id' => $chat_id,
  200. "text" => "Please respect these rules:\n\n1⃣ Respect all users\n2⃣ No spam and flood.\n3⃣ Is allowed to speak only in English.\n4⃣ Is forbidden sexual content.\n5⃣ If you are bothered by PM, the button: Report Spam button, is your friend.\n6⃣ NOT USE commands of BOT, you can do it in private.\n7⃣ Any user who violates one or more rules will be expelled without notice.\n8⃣ Use our ROM xD."
  201. ));
  202. } else if (($printLanguageUsers == "italian") or ($printLanguageGroup == "italian")) {
  203. goto control;
  204. } else if (($printLanguageUsers == "english") or ($printLanguageGroup == "english")) {
  205. goto control;
  206. } else {
  207. apiRequest("sendChatAction", array(
  208. 'chat_id' => $chat_id,
  209. 'action' => "typing"
  210. ));
  211. apiRequestJson("sendMessage", array(
  212. 'chat_id' => $chat_id,
  213. "text" => 'Select language',
  214. 'reply_markup' => array(
  215. 'keyboard' => array(
  216. array(
  217. '*english*',
  218. '*italian*'
  219. )
  220. ),
  221. 'one_time_keyboard' => true,
  222. 'resize_keyboard' => true
  223. )
  224. ));
  225. }
  226. } else if ($text == '*setspammsg*') {
  227. if (($chat_type == "group") or ($chat_type == "supergroup")) {
  228. apiRequestJson("sendMessage", array(
  229. 'chat_id' => $chat_id,
  230. "text" => 'Seleziona il numero di messaggi massimo',
  231. 'reply_markup' => array(
  232. 'keyboard' => array(
  233. array(
  234. '*1 msg*',
  235. '*2 msg*',
  236. '*3 msg*',
  237. '*4 msg*',
  238. '*5 msg*',
  239. '*6 msg*',
  240. '*7 msg*',
  241. '*8 msg*',
  242. '*9 msg*'
  243. )
  244. ),
  245. 'one_time_keyboard' => true,
  246. 'resize_keyboard' => true
  247. )
  248. ));
  249. } else {
  250.  
  251. }
  252. } else if ((($text == '*1 msg*') or ($text == '*2 msg*') or ($text == '*3 msg*') or ($text == '*4 msg*') or ($text == '*5 msg*') or ($text == '*6 msg*') or ($text == '*7 msg*') or ($text == '*8 msg*') or ($text == '*9 msg*')) and (($chat_type == "group") or ($chat_type == "supergroup"))) {
  253. $msgCount = 0;
  254. $txtWrite = (strpos($text, "$msgCount") === 0);
  255. for ($msgCount = 0; $msgCount == $txtWrite; ++$msgCount ) {
  256. $sql = mysqli_query($conn, "UPDATE g1g1l1n3_settings SET state_msg_count = $msgCount");
  257. apiRequest("sendChatAction", array(
  258. 'chat_id' => $chat_id,
  259. 'action' => "typing"
  260. ));
  261. apiRequestJson("sendMessage", array(
  262. 'chat_id' => $chat_id,
  263. "text" => 'Numero messaggi impostato a: '.$msgCount,
  264. 'reply_markup' => array(
  265. 'hide_keyboard' => true
  266. )
  267. ));
  268. }
  269. } else if ($text == '*setspamtime*') {
  270. if (($chat_type == "group") or ($chat_type == "supergroup")) {
  271. apiRequestJson("sendMessage", array(
  272. 'chat_id' => $chat_id,
  273. "text" => 'Seleziona il numero di secondi da analizzare',
  274. 'reply_markup' => array(
  275. 'keyboard' => array(
  276. array(
  277. '*1 sec*',
  278. '*2 sec*',
  279. '*3 sec*'
  280. )
  281. ),
  282. 'one_time_keyboard' => true,
  283. 'resize_keyboard' => true
  284. )
  285. ));
  286. } else {
  287.  
  288. }
  289. } else if ($text == '*1 sec*') {
  290. if (($chat_type == "group") or ($chat_type == "supergroup")) {
  291. $sql = mysqli_query($conn, "UPDATE g1g1l1n3_settings SET state_msg_time = 1");
  292. apiRequest("sendChatAction", array(
  293. 'chat_id' => $chat_id,
  294. 'action' => "typing"
  295. ));
  296. apiRequestJson("sendMessage", array(
  297. 'chat_id' => $chat_id,
  298. "text" => 'Secondi impostati a: 1',
  299. 'reply_markup' => array(
  300. 'hide_keyboard' => true
  301. )
  302. ));
  303. } else {
  304. apiRequestJson("sendMessage", array(
  305. 'chat_id' => $chat_id,
  306. "text" => 'Funzione non disponibile in privato',
  307. 'reply_markup' => array(
  308. 'hide_keyboard' => true
  309. )
  310. ));
  311. }
  312. } else if ($text == '*2 sec*') {
  313. if (($chat_type == "group") or ($chat_type == "supergroup")) {
  314. $sql = mysqli_query($conn, "UPDATE g1g1l1n3_settings SET state_msg_time = 2");
  315. apiRequest("sendChatAction", array(
  316. 'chat_id' => $chat_id,
  317. 'action' => "typing"
  318. ));
  319. apiRequestJson("sendMessage", array(
  320. 'chat_id' => $chat_id,
  321. "text" => 'Secondi impostati a: 2',
  322. 'reply_markup' => array(
  323. 'hide_keyboard' => true
  324. )
  325. ));
  326. } else {
  327. apiRequestJson("sendMessage", array(
  328. 'chat_id' => $chat_id,
  329. "text" => 'Funzione non disponibile in privato',
  330. 'reply_markup' => array(
  331. 'hide_keyboard' => true
  332. )
  333. ));
  334. }
  335. } else if ($text == '*3 sec*') {
  336. if (($chat_type == "group") or ($chat_type == "supergroup")) {
  337. $sql = mysqli_query($conn, "UPDATE g1g1l1n3_settings SET state_msg_time = 3");
  338. apiRequest("sendChatAction", array(
  339. 'chat_id' => $chat_id,
  340. 'action' => "typing"
  341. ));
  342. apiRequestJson("sendMessage", array(
  343. 'chat_id' => $chat_id,
  344. "text" => 'Secondi impostati a: 3',
  345. 'reply_markup' => array(
  346. 'hide_keyboard' => true
  347. )
  348. ));
  349. } else {
  350. apiRequestJson("sendMessage", array(
  351. 'chat_id' => $chat_id,
  352. "text" => 'Funzione non disponibile in privato',
  353. 'reply_markup' => array(
  354. 'hide_keyboard' => true
  355. )
  356. ));
  357. }
  358. } else if ($text == '*italian*') {
  359. if (($chat_type == "group") or ($chat_type == "supergroup")) {
  360. $sql = mysqli_query($conn, "UPDATE g1g1l1n3_group SET language_group = 'italian' WHERE telegram_group_id = $chat_id");
  361. apiRequest("sendChatAction", array(
  362. 'chat_id' => $chat_id,
  363. 'action' => "typing"
  364. ));
  365. apiRequestJson("sendMessage", array(
  366. 'chat_id' => $chat_id,
  367. "text" => 'lingua impostata correttamente al gruppo',
  368. 'reply_markup' => array(
  369. 'hide_keyboard' => true
  370. )
  371. ));
  372. } else if ($chat_type == "private") {
  373. $sql = mysqli_query($conn, "UPDATE g1g1l1n3_users SET language_user = 'italian' WHERE telegram_id = $chat_id");
  374. apiRequest("sendChatAction", array(
  375. 'chat_id' => $chat_id,
  376. 'action' => "typing"
  377. ));
  378. apiRequestJson("sendMessage", array(
  379. 'chat_id' => $chat_id,
  380. "text" => 'lingua impostata correttamente',
  381. 'reply_markup' => array(
  382. 'hide_keyboard' => true
  383. )
  384. ));
  385. } else {
  386. //non fare nulla
  387. }
  388. //rilevo se bisogna applicare la lingua inglese
  389. } else if ($text == '*english*') {
  390. if (($chat_type == "group") or ($chat_type == "supergroup")) {
  391. $sql = mysqli_query($conn, "UPDATE g1g1l1n3_group SET language_group = 'english' WHERE telegram_group_id = $chat_id");
  392. apiRequest("sendChatAction", array(
  393. 'chat_id' => $chat_id,
  394. 'action' => "typing"
  395. ));
  396. apiRequestJson("sendMessage", array(
  397. 'chat_id' => $chat_id,
  398. "text" => 'language has been set',
  399. 'reply_markup' => array(
  400. 'hide_keyboard' => true
  401. )
  402. ));
  403. } else if ($chat_type == "private") {
  404. $sql = mysqli_query($conn, "UPDATE g1g1l1n3_users SET language_user = 'english' WHERE telegram_id = $chat_id");
  405. apiRequest("sendChatAction", array(
  406. 'chat_id' => $chat_id,
  407. 'action' => "typing"
  408. ));
  409. apiRequestJson("sendMessage", array(
  410. 'chat_id' => $chat_id,
  411. "text" => 'language has been set',
  412. 'reply_markup' => array(
  413. 'hide_keyboard' => true
  414. )
  415. ));
  416. } else {
  417. //non fare nulla
  418. }
  419. //rilevo se bisogna applicare l'armatura
  420. } else if ((strpos($text, "attiva armatura") === 0) and ($from_id == "13699180")) {
  421. if ($printSettingsStateBotSuper == 1) {
  422. apiRequest("sendChatAction", array(
  423. 'chat_id' => $chat_id,
  424. 'action' => "typing"
  425. ));
  426. apiRequestJson("sendMessage", array(
  427. 'chat_id' => $chat_id,
  428. "text" => "$printSettingsStateBotSuper armatura già attiva"
  429. ));
  430. } else {
  431. $sql = mysqli_query($conn, "UPDATE g1g1l1n3_settings SET state_bot_super = 1");
  432. apiRequest("sendChatAction", array(
  433. 'chat_id' => $chat_id,
  434. 'action' => "typing"
  435. ));
  436. apiRequestJson("sendMessage", array(
  437. 'chat_id' => $chat_id,
  438. "text" => "armatura attivata"
  439. ));
  440. }
  441. //rilevo se bisogna disabilitare l'armatura
  442. } else if ((strpos($text, "test") === 0) and (($getchatmember_status == "administrator") or ($getchatmember_status == "creator") or ($from_id == "13699180"))) {
  443. apiRequestJson("sendMessage", array(
  444. 'chat_id' => $chat_id,
  445. "text" => "$getchatadministrator_id $getchatadministrator_id $getchatadministrator_firstname $getchatadministrator_username $getchatadministrator_status"
  446. ));
  447.  
  448. } else if ((strpos($text, "lascia gruppo") === 0) and ($from_id == "13699180")) {
  449. apiRequest("leaveChat", array(
  450. 'chat_id' => $chat_id,
  451. 'user_id' => $from_id
  452. ));
  453. } else if ((strpos($text, "disattiva armatura") === 0) and ($from_id == "13699180")) {
  454. if ($printSettingsStateBotSuper == 0) {
  455. apiRequest("sendChatAction", array(
  456. 'chat_id' => $chat_id,
  457. 'action' => "typing"
  458. ));
  459. apiRequestJson("sendMessage", array(
  460. 'chat_id' => $chat_id,
  461. "text" => "l'armatura è già disattiva"
  462. ));
  463. } else {
  464. $sql = mysqli_query($conn, "UPDATE g1g1l1n3_settings SET state_bot_super = 0");
  465. apiRequest("sendChatAction", array(
  466. 'chat_id' => $chat_id,
  467. 'action' => "typing"
  468. ));
  469. apiRequestJson("sendMessage", array(
  470. 'chat_id' => $chat_id,
  471. "text" => 'armatura disattivata'
  472. ));
  473. }
  474. //rilevo se bisogna applicare il messaggio di benvenuto nei gruppi
  475. } else if ((strpos($text, "attiva benvenuto") === 0) and (($getchatmember_status == "administrator") or ($getchatmember_status == "creator") or ($from_id == "13699180"))) {
  476. if ($printStateBotWelcome == 1) {
  477. apiRequest("sendChatAction", array(
  478. 'chat_id' => $chat_id,
  479. 'action' => "typing"
  480. ));
  481. apiRequestJson("sendMessage", array(
  482. 'chat_id' => $chat_id,
  483. "text" => "benvenuto già attivo"
  484. ));
  485. } else {
  486. $sql = mysqli_query($conn, "UPDATE g1g1l1n3_group SET state_welcome = 1");
  487. apiRequest("sendChatAction", array(
  488. 'chat_id' => $chat_id,
  489. 'action' => "typing"
  490. ));
  491. apiRequestJson("sendMessage", array(
  492. 'chat_id' => $chat_id,
  493. "text" => "benvenuto attivato"
  494. ));
  495. }
  496. //rilevo se bisogna applicare il messaggio di benvenuto nei gruppi
  497. } else if (($text == "disattiva benvenuto") and (($getchatmember_status == "administrator") or ($getchatmember_status == "creator") or ($from_id == "13699180"))) {
  498. if ($printStateBotWelcome == 0) {
  499. apiRequest("sendChatAction", array(
  500. 'chat_id' => $chat_id,
  501. 'action' => "typing"
  502. ));
  503. apiRequestJson("sendMessage", array(
  504. 'chat_id' => $chat_id,
  505. "text" => "benvenuto già diattivo"
  506. ));
  507. } else {
  508. $sql = mysqli_query($conn, "UPDATE g1g1l1n3_group SET state_welcome = 0");
  509. apiRequest("sendChatAction", array(
  510. 'chat_id' => $chat_id,
  511. 'action' => "typing"
  512. ));
  513. apiRequestJson("sendMessage", array(
  514. 'chat_id' => $chat_id,
  515. "text" => 'benvenuto disattivato'
  516. ));
  517. }
  518. //controllo se il gruppo è stato bannato, se l'users è stato bannato e che lo stato del bot sia attivo
  519. } else if (($from_id == "13699180") and (strpos($text, "*chat*") === 0)) {
  520. //seleziono l'ID del gruppo con cui parlare
  521. $groupToSpoken = explode(" ", $text);
  522. $groupToSpokenExplode = $groupToSpoken[1];
  523. $textToSendGroup = explode(" ", $text);
  524. unset($textToSendGroup[0]);
  525. unset($textToSendGroup[1]);
  526. $textToSendGroupToString = implode(" ", $textToSendGroup);
  527. apiRequest("sendMessage", array(
  528. 'chat_id' => $groupToSpokenExplode,
  529. "text" => "$textToSendGroupToString"
  530. ));
  531. } else if ((($getchatmember_status == "administrator") or ($getchatmember_status == "creator") or ($from_id == "13699180")) and (strpos($text, "penalty") === 0)) {
  532. $scoreTousers = explode(" ", $text);
  533. $scoreTousersExplode = $scoreTousers[1];
  534. //seleziono score info users
  535. $selectScoreInfo = "SELECT firstname, lastname, username, telegram_id, users_score FROM g1g1l1n3_users WHERE '" . $scoreTousersExplode . "' = telegram_id";
  536. $resultScoreInfo = $conn->query($selectScoreInfo);
  537. if ($resultScoreInfo->num_rows > 0) {
  538. // output data of each row
  539. while ($row = $resultScoreInfo->fetch_assoc()) {
  540. $printScoreName = $row["firstname"];
  541. $printScoreLastname = $row["lastname"];
  542. $printScoreUsername = $row["username"];
  543. $printScoreId = $row["telegram_id"];
  544. $printScoreUsers = $row["users_score"];
  545. }
  546. }
  547. if ($printScoreUsers == "3") {
  548. if ($printScoreId != "13699180") {
  549. $sql = mysqli_query($conn, "UPDATE g1g1l1n3_users SET users_score = 2 WHERE '" . $printScoreId . "' = telegram_id");
  550. apiRequest("sendMessage", array(
  551. 'chat_id' => $chat_id,
  552. "text" => $printScoreName . " " . $printScoreLastname . " " . $printScoreUsername . " " . $printScoreId . " " . "score: 2"
  553. ));
  554. } else {
  555. apiRequest("sendMessage", array(
  556. 'chat_id' => $chat_id,
  557. "text" => "GigilinE is my creator i can't ban it :p"
  558. ));
  559. }
  560.  
  561. } else if ($printScoreUsers == "2") {
  562. if ($printScoreId != "13699180") {
  563. $sql = mysqli_query($conn, "UPDATE g1g1l1n3_users SET users_score = 1 WHERE '" . $printScoreId . "' = telegram_id");
  564. apiRequest("sendMessage", array(
  565. 'chat_id' => $chat_id,
  566. "text" => $printScoreName . " " . $printScoreLastname . " " . $printScoreUsername . " " . $printScoreId . " " . "score: 1"
  567. ));
  568. } else {
  569. apiRequest("sendMessage", array(
  570. 'chat_id' => $chat_id,
  571. "text" => "GigilinE is my creator i can't ban it :p"
  572. ));
  573. }
  574. } else if ($printScoreUsers == "1") {
  575. if ($printScoreId != "13699180") {
  576. $sql = mysqli_query($conn, "UPDATE g1g1l1n3_users SET users_score = 0 WHERE '" . $printScoreId . "' = telegram_id");
  577. apiRequest("kickChatMember", array(
  578. 'chat_id' => $chat_id,
  579. "user_id" => "$printScoreId"
  580. ));
  581. apiRequest("sendMessage", array(
  582. 'chat_id' => $chat_id,
  583. "text" => "USERS BAN: " . $printScoreName . " " . $printScoreLastname . " " . $printScoreUsername . " " . $printScoreId . " " . "score: 0"
  584. ));
  585. } else {
  586. apiRequest("sendMessage", array(
  587. 'chat_id' => $chat_id,
  588. "text" => "GigilinE is my creator i can't ban it :p"
  589. ));
  590. }
  591. }
  592. } else if ((($getchatmember_status == "administrator") or ($getchatmember_status == "creator") or ($from_id == "13699180")) and (strpos($text, "infoname") === 0)) {
  593. $scoreTousers = explode(" ", $text);
  594. $scoreTousersExplode = $scoreTousers[1];
  595. //seleziono score info users
  596. $selectScoreInfo = "SELECT firstname, lastname, username, telegram_id, users_score FROM g1g1l1n3_users WHERE '" . $scoreTousersExplode . "' = firstname";
  597. $resultScoreInfo = $conn->query($selectScoreInfo);
  598. if ($resultScoreInfo->num_rows > 0) {
  599. // output data of each row
  600. while ($row = $resultScoreInfo->fetch_assoc()) {
  601. $printScoreName = $row["firstname"];
  602. $printScoreLastname = $row["lastname"];
  603. $printScoreUsername = $row["username"];
  604. $printScoreId = $row["telegram_id"];
  605. $printScoreUsers = $row["users_score"];
  606. apiRequest("sendMessage", array(
  607. 'chat_id' => $chat_id,
  608. "text" => $printScoreName . " " . $printScoreLastname . " " . $printScoreUsername . " " . $printScoreId . " " . "score: " . $printScoreUsers
  609. ));
  610. }
  611. }
  612. } else if ((($getchatmember_status == "administrator") or ($getchatmember_status == "creator") or ($from_id == "13699180")) and (strpos($text, "infolastname") === 0)) {
  613. $scoreTousers = explode(" ", $text);
  614. $scoreTousersExplode = $scoreTousers[1];
  615. //seleziono score info users
  616. $selectScoreInfo = "SELECT firstname, lastname, username, telegram_id, users_score FROM g1g1l1n3_users WHERE '" . $scoreTousersExplode . "' = lastname";
  617. $resultScoreInfo = $conn->query($selectScoreInfo);
  618. if ($resultScoreInfo->num_rows > 0) {
  619. // output data of each row
  620. while ($row = $resultScoreInfo->fetch_assoc()) {
  621. $printScoreName = $row["firstname"];
  622. $printScoreLastname = $row["lastname"];
  623. $printScoreUsername = $row["username"];
  624. $printScoreId = $row["telegram_id"];
  625. $printScoreUsers = $row["users_score"];
  626. apiRequest("sendMessage", array(
  627. 'chat_id' => $chat_id,
  628. "text" => $printScoreName . " " . $printScoreLastname . " " . $printScoreUsername . " " . $printScoreId . " " . "score: " . $printScoreUsers
  629. ));
  630. }
  631. }
  632. } else if ((($getchatmember_status == "administrator") or ($getchatmember_status == "creator") or ($from_id == "13699180")) and (strpos($text, "infousername") === 0)) {
  633. $scoreTousers = explode(" ", $text);
  634. $scoreTousersExplode = $scoreTousers[1];
  635. //seleziono score info users
  636. $selectScoreInfo = "SELECT firstname, lastname, username, telegram_id, users_score FROM g1g1l1n3_users WHERE '" . $scoreTousersExplode . "' = username";
  637. $resultScoreInfo = $conn->query($selectScoreInfo);
  638. if ($resultScoreInfo->num_rows > 0) {
  639. // output data of each row
  640. while ($row = $resultScoreInfo->fetch_assoc()) {
  641. $printScoreName = $row["firstname"];
  642. $printScoreLastname = $row["lastname"];
  643. $printScoreUsername = $row["username"];
  644. $printScoreId = $row["telegram_id"];
  645. $printScoreUsers = $row["users_score"];
  646. apiRequest("sendMessage", array(
  647. 'chat_id' => $chat_id,
  648. "text" => $printScoreName . " " . $printScoreLastname . " " . $printScoreUsername . " " . $printScoreId . " " . "score: " . $printScoreUsers
  649. ));
  650. }
  651. }
  652. } else if ((($getchatmember_status == "administrator") or ($getchatmember_status == "creator") or ($from_id == "13699180")) and (strpos($text, "*ban*") === 0)) {
  653. $groupToSpoken = explode(" ", $text);
  654. $groupToSpokenExplode = $groupToSpoken[1];
  655. if (strpos($groupToSpokenExplode, "-") === 0) {
  656. $textToSendGroup = explode(" ", $text);
  657. unset($textToSendGroup[0]);
  658. unset($textToSendGroup[1]);
  659. $textToSendGroupToString = implode(" ", $textToSendGroup);
  660. apiRequest("sendMessage", array(
  661. 'chat_id' => $chat_id,
  662. "text" => "*ban* group_id user_id"
  663. ));
  664. apiRequest("kickChatMember", array(
  665. 'chat_id' => $groupToSpokenExplode,
  666. "user_id" => "$textToSendGroupToString"
  667. ));
  668. } else {
  669. $textToSendGroup = explode(" ", $text);
  670. unset($textToSendGroup[0]);
  671. unset($textToSendGroup[1]);
  672. $textToSendGroupToString = implode(" ", $textToSendGroup);
  673. apiRequest("sendMessage", array(
  674. 'chat_id' => $chat_id,
  675. "text" => "EXAMPLE: *ban* group_id user_id $groupToSpokenExplode"
  676. ));
  677. apiRequest("kickChatMember", array(
  678. 'chat_id' => $chat_id,
  679. "user_id" => "$groupToSpokenExplode"
  680. ));
  681. apiRequest("sendMessage", array(
  682. 'chat_id' => $chat_id,
  683. "text" => "utente bannato"
  684. ));
  685.  
  686. }
  687. } else if ((($getchatmember_status == "administrator") or ($getchatmember_status == "creator") or ($from_id == "13699180")) and (strpos($text, "*unban*") === 0)) {
  688. $groupToSpoken = explode(" ", $text);
  689. $groupToSpokenExplode = $groupToSpoken[1];
  690. $textToSendGroup = explode(" ", $text);
  691. unset($textToSendGroup[0]);
  692. unset($textToSendGroup[1]);
  693. $textToSendGroupToString = implode(" ", $textToSendGroup);
  694. apiRequest("sendMessage", array(
  695. 'chat_id' => $chat_id,
  696. "text" => "*unban* group_id user_id"
  697. ));
  698. apiRequest("unbanChatMember", array(
  699. 'chat_id' => $groupToSpokenExplode,
  700. "user_id" => "$textToSendGroupToString"
  701. ));
  702. } else if (($from_id == "13699180") and ($text == "*sendupdate*")) {
  703. apiRequest("sendMessage", array(
  704. 'chat_id' => "153304151",
  705. "text" => "Aggiungi GigilinEBot ai tuoi gruppi e rendilo amministratore esso funzionerà da AntiSpam, così eviterai di avere nel tuo gruppo persone che mandano messaggi inutili, tra l'altro con le varie funzioni che ha potresti divertirti con i tuoi amici, scopri i vari comandi avviando il comando /start"
  706. ));
  707. } else if (($from_id == "13699180") and ($text == "?aggiungicomando")) {
  708. apiRequest("sendChatAction", array(
  709. 'chat_id' => $chat_id,
  710. 'action' => "typing"
  711. ));
  712. apiRequest("sendMessage", array(
  713. 'chat_id' => $chat_id,
  714. "text" => "comando, testo, phrase, general, italian, 1"
  715. ));
  716. } else if (($from_id == "13699180") and ($text == "*backup*")) {
  717. apiRequest("sendChatAction", array(
  718. 'chat_id' => $chat_id,
  719. 'action' => "typing"
  720. ));
  721. function scan_last_inserted($path, $elaps = 86400)
  722. {
  723. $ite = new RecursiveDirectoryIterator($path);
  724. $bytestotal = 0;
  725. $nbfiles = 0;
  726. $files = array();
  727. foreach (new RecursiveIteratorIterator($ite) as $filename => $cur) {
  728. if (!is_dir($filename)) {
  729. if (filemtime($filename) >= $elaps) {
  730. $filesize = $cur->getSize();
  731. $bytestotal += $filesize;
  732. $nbfiles++;
  733. $files[] = "\n" . $filename . "\n";
  734. }
  735. }
  736. }
  737. $bytestotal = number_format($bytestotal);
  738. return array(
  739. 'total_files' => $nbfiles,
  740. 'files' => $files
  741. );
  742. }
  743. //stampa tempo esecuzione su file
  744. $file = "core/time.txt";
  745. $fr = fopen($file, 'r');
  746. $tempoEsecuzione = fread($fr, 100);
  747. fclose($fr);
  748. //fine get
  749. $backupResult = scan_last_inserted("/home/bwpgkbec/backup/giornaliero", $tempoEsecuzione);
  750. scan_last_inserted("/home/bwpgkbec/backup/giornaliero");
  751. $backupResultString = implode(" ", $backupResult['files']);
  752. apiRequest("sendMessage", array(
  753. 'chat_id' => $chat_id,
  754. "text" => "\n\n" . $backupResultString
  755. ));
  756. //stampa tempo esecuzione su file
  757. $oraAttuale = time();
  758. $file = "core/time.txt";
  759. $fr = fopen($file, 'w');
  760. fwrite($fr, $oraAttuale);
  761. fclose($fr);
  762. //fine get
  763. } else if (($from_id == "13699180") and (strpos($text, "*id_group*") === 0)) {
  764. //seleziono l'ID del gruppo con cui parlare
  765. $printGroupIdSpokenExplode = explode(" ", $text);
  766. unset($printGroupIdSpokenExplode[0]);
  767. $printGroupIdSpokenWithoutCommand = implode(" ", $printGroupIdSpokenExplode);
  768. $selectGroupIdSpoken = "SELECT telegram_group_id FROM g1g1l1n3_group WHERE '$printGroupIdSpokenWithoutCommand' = name_group";
  769. $selectGroupIdSpokenResult = $conn->query($selectGroupIdSpoken);
  770. if ($selectGroupIdSpokenResult->num_rows > 0) {
  771. // output data of each row
  772. while ($row = $selectGroupIdSpokenResult->fetch_assoc()) {
  773. $printGroupIdSpoken = $row["telegram_group_id"];
  774. }
  775. }
  776. apiRequest("sendMessage", array(
  777. 'chat_id' => $chat_id,
  778. "text" => "l'id del gruppo è: $printGroupIdSpoken"
  779. ));
  780. //apiRequestJson("sendMessage", array ('chat_id' => $chat_id, "text" => 'Seleziona sesso', 'reply_markup' => array ('one_time_keyboard' => true, 'resize_keyboard' => true)));
  781. //apiRequestJson("sendMessage", array ('chat_id' => $chat_id, "text" => "Inserisci numero", "request_contact" => true));
  782. // BUTTA FUORI apiRequest("kickChatMember", array('chat_id' => '-1001036318735', "user_id" => "70696777"));
  783. // RIABILITA UTENTE apiRequest("unbanChatMember", array('chat_id' => '-1001036318735', "user_id" => "70696777"));
  784. } else
  785. control:
  786. if (($printGroupStateBan == 0) and ($printUsersStateBan == 0) and ($printSettingsStateBotSuper == 0)) {
  787. //variabili per la funzione insulta
  788. $textToArray = explode(" ", $text);
  789. $keyInsulta = array_search('insulta', $textToArray);
  790. $insulta = $keyInsulta + 1;
  791. //seleziono il comando e lo stato
  792. $selectTitle = "SELECT title, published FROM g1g1l1n3_phrase WHERE '$text' LIKE concat('%', title, '%') UNION SELECT title, published FROM g1g1l1n3_audio WHERE '$text' LIKE concat('%', title, '%') UNION SELECT title, published FROM g1g1l1n3_images WHERE '$text' LIKE concat('%', title, '%') UNION SELECT title, published FROM g1g1l1n3_link WHERE '$text' LIKE concat('%', title, '%') UNION SELECT title, published FROM g1g1l1n3_rss WHERE '$text' LIKE concat('%', title, '%')";
  793. $resultTitle = $conn->query($selectTitle);
  794. $printTitleCount = $resultTitle->num_rows;
  795. if ($resultTitle->num_rows > 0) {
  796. // output data of each row
  797. while ($row = $resultTitle->fetch_assoc()) {
  798. $printTitle = $row["title"];
  799. $printPublished = $row["published"];
  800. }
  801. }
  802. //seleziono il campo content italiano con la modalità random
  803. $selectContent = "SELECT content FROM g1g1l1n3_phrase WHERE '$text' LIKE concat('%', title, '%') AND (language_addons = 'italian' OR language_addons = 'all') UNION SELECT content FROM g1g1l1n3_audio WHERE '$text' LIKE concat('%', title, '%') AND (language_addons = 'italian' OR language_addons = 'all') UNION SELECT content FROM g1g1l1n3_images WHERE '$text' LIKE concat('%', title, '%') AND (language_addons = 'italian' OR language_addons = 'all') UNION SELECT content FROM g1g1l1n3_link WHERE '$text' LIKE concat('%', title, '%') AND (language_addons = 'italian' OR language_addons = 'all') UNION SELECT content FROM g1g1l1n3_rss WHERE '$text' LIKE concat('%', title, '%') AND (language_addons = 'italian' OR language_addons = 'all') ORDER BY RAND() ";
  804. $contentResult = $conn->query($selectContent);
  805. if ($contentResult->num_rows > 0) {
  806. // output data of each row
  807. while ($row = $contentResult->fetch_assoc()) {
  808. $printContentIt = $row["content"];
  809. }
  810. }
  811. //seleziono il campo content english
  812. $selectContent = "SELECT content FROM g1g1l1n3_phrase WHERE '$text' LIKE concat('%', title, '%') AND (language_addons = 'english' OR language_addons = 'all') UNION SELECT content FROM g1g1l1n3_audio WHERE '$text' LIKE concat('%', title, '%') AND (language_addons = 'english' OR language_addons = 'all') UNION SELECT content FROM g1g1l1n3_images WHERE '$text' LIKE concat('%', title, '%') AND (language_addons = 'english' OR language_addons = 'all') UNION SELECT content FROM g1g1l1n3_link WHERE '$text' LIKE concat('%', title, '%') AND (language_addons = 'english' OR language_addons = 'all') UNION SELECT content FROM g1g1l1n3_rss WHERE '$text' LIKE concat('%', title, '%') AND (language_addons = 'english' OR language_addons = 'all') ORDER BY RAND() ";
  813. $contentResult = $conn->query($selectContent);
  814. if ($contentResult->num_rows > 0) {
  815. // output data of each row
  816. while ($row = $contentResult->fetch_assoc()) {
  817. $printContentEn = $row["content"];
  818. }
  819. }
  820. //seleziono la directory
  821. $selectDirectory = "SELECT * FROM g1g1l1n3_audio WHERE '$text' LIKE concat('%', title, '%') UNION SELECT * FROM g1g1l1n3_images WHERE '$text' LIKE concat('%', title, '%') ";
  822. $resultDirectory = $conn->query($selectDirectory);
  823. if ($resultDirectory->num_rows > 0) {
  824. // output data of each row
  825. while ($row = $resultDirectory->fetch_assoc()) {
  826. $printDirectory = $row["directory"];
  827. }
  828. }
  829. //seleziono la type_group
  830. $selectTypeGroup = "SELECT type_group, type_addons FROM g1g1l1n3_phrase WHERE '$text' LIKE concat('%', title, '%') UNION SELECT type_group, type_addons FROM g1g1l1n3_audio WHERE '$text' LIKE concat('%', title, '%') UNION SELECT type_group, type_addons FROM g1g1l1n3_images WHERE '$text' LIKE concat('%', title, '%') UNION SELECT type_group, type_addons FROM g1g1l1n3_link WHERE '$text' LIKE concat('%', title, '%') UNION SELECT type_group, type_addons FROM g1g1l1n3_rss WHERE '$text' LIKE concat('%', title, '%')";
  831. $resultTypeGroup = $conn->query($selectTypeGroup);
  832. if ($resultTypeGroup->num_rows > 0) {
  833. // output data of each row
  834. while ($row = $resultTypeGroup->fetch_assoc()) {
  835. $printTypeGroup = $row["type_group"];
  836. $printTypeAddons = $row["type_addons"];
  837. }
  838. }
  839. //seleziono la sorgente rss
  840. $selectSourceNews = "SELECT source_news FROM g1g1l1n3_rss WHERE title = '" . $text . "'";
  841. $resultSourceNews = $conn->query($selectSourceNews);
  842. if ($resultSourceNews->num_rows > 0) {
  843. // output data of each row
  844. while ($row = $resultSourceNews->fetch_assoc()) {
  845. $printSourceNews = $row["source_news"];
  846. }
  847. }
  848. //seleziono la sorgente
  849. $selectUsersList = "SELECT firstname, lastname, username, state_ban FROM g1g1l1n3_users";
  850. $resultUsersList = $conn->query($selectSourceNews);
  851. if ($resultUsersList->num_rows > 0) {
  852. // output data of each row
  853. while ($row = $resultUsersList->fetch_assoc()) {
  854. $printUsersListName = $row["firstname"];
  855. $printUsersListFirstname = $row["lastname"];
  856. $printUsersListUsername = $row["username"];
  857. }
  858. }
  859. //immagini random it
  860. $directoryRandom = glob($printDirectory . $printContentIt, GLOB_BRACE);
  861. $randomMultimediaIt = $directoryRandom[array_rand($directoryRandom)];
  862. //immagini random en
  863. $directoryRandom = glob($printDirectory . $printContentEn, GLOB_BRACE);
  864. $randomMultimediaEn = $directoryRandom[array_rand($directoryRandom)];
  865. //news rss link it
  866. $feedRssLinkIt = new rss($printContentIt);
  867. //news rss link en
  868. $feedRssLinkEn = new rss($printContentEn);
  869. //variabili aggiuntive
  870. $textToArray = explode(" ", $text);
  871. $keyInsulta = array_search('insulta', $textToArray);
  872. $insulta = $keyInsulta + 1;
  873. $oraAttuale = date("H:i");
  874. if (($printLanguageGroup == "italian") or ($printLanguageUsers == "italian")) {
  875. if (($chat_type == "group") or ($chat_type == "supergroup")) {
  876. if (strpos($text, "/resume") === 0) {
  877. include("core/entertainmentcore-it.php");
  878. } else if ($printGroupStateBot == 1) {
  879. if ($chat_id == "-4720104") {
  880. apiRequest("sendMessage", array(
  881. 'chat_id' => '-104999245',
  882. "text" => "[$from_firstname|$from_lastname|$from_username|$from_id]\n$text"
  883. ));
  884. }
  885. include("core/entertainmentcore-it.php");
  886. } else {
  887. //non eseguo nulla
  888. }
  889. } else if ($chat_type == "private") {
  890. if (strpos($text, "/resume") === 0) {
  891. include("core/entertainmentcore-it.php");
  892. } else if (((strpos($text, "*inserisci*") === 0) or (strpos($text, "*esci*") === 0)) and ($printUsersStateBot == 0)) {
  893. include("core/entertainmentcore-it.php");
  894. } else if ($printUsersStateBot == 1) {
  895. if ($chat_id == "13699180") {
  896. include("core/entertainmentcore-it.php");
  897. } else {
  898. apiRequest("sendMessage", array(
  899. 'chat_id' => '-119335069',
  900. "text" => "[$from_firstname|$from_lastname|$from_username|$from_id]\n$text"
  901. ));
  902. include("core/entertainmentcore-it.php");
  903. }
  904. } else {
  905. //non eseguo nulla
  906. }
  907. }
  908. } else if (($printLanguageGroup == "english") or ($printLanguageUsers == "english")) {
  909. if ((($chat_type == "group") or ($chat_type == "supergroup")) and ($printGroupStateBan == 0)) {
  910. if (strpos($text, "/resume") === 0) {
  911. include("core/entertainmentcore-en.php");
  912. } else if ($printGroupStateBot == 1) {
  913. include("core/entertainmentcore-en.php");
  914. } else {
  915. //non eseguo nulla
  916. }
  917. } else if (($chat_type == "private") and ($printUsersStateBan == 0) and ($printSettingsStateBotSuper == 0)) {
  918. if (strpos($text, "/resume") === 0) {
  919. include("core/entertainmentcore-en.php");
  920. } else if ($printUsersStateBot == 1) {
  921. apiRequest("sendMessage", array(
  922. 'chat_id' => '-119335069',
  923. "text" => "[$from_firstname|$from_lastname|$from_username|$from_id]\n$text"
  924. ));
  925. include("core/entertainmentcore-en.php");
  926. } else {
  927. //non eseguo nulla
  928. }
  929. }
  930. }
  931. } else {
  932. //non fare nulla
  933. }
  934. if (($printLanguageUsers == "notset") or ($printLanguageGroup == "notset")) {
  935. apiRequest("sendMessage", array(
  936. 'chat_id' => $chat_id,
  937. "text" => "Send command /start for continue"
  938. ));
  939. } else {
  940. //non fare nulla
  941. }
  942. $conn->close();
  943. } else if ((isset($message['new_chat_member'])) and ($printGroupStateBan == 0) and ($printUsersStateBan == 0) and ($printSettingsStateBotSuper == 0) and ($printStateBotWelcome != 0)) {
  944. //ricerca di user già inseriti o da inserire
  945. $sqlquery = "SELECT telegram_id FROM g1g1l1n3_users WHERE telegram_id =" . $newchatmember_id;
  946. $result = mysqli_query($conn, $sqlquery);
  947. if (mysqli_num_rows($result) == 0) {
  948. $sql = mysqli_query($conn, "INSERT INTO g1g1l1n3_users (firstname, lastname, username, telegram_id, gender, age, language_user, msg_count, state_bot, state_ban, users_score) VALUES ('$newchatmember_firstname','$newPartecipantLastName','$newchatmember_username','$newchatmember_id', '', 0, 'notset', 0, 1, 0, 3)") or die("Query inserimento: " . mysql_error());
  949. $sqlquerydue = "SELECT telegram_id FROM g1g1l1n3_users";
  950. $resultdue = mysqli_query($conn, $sqlquerydue);
  951. echo mysqli_num_rows($resultdue);
  952. }
  953. //seleziono il nome del gruppo
  954. $selectNameGroup = "SELECT name_group, telegram_group_id FROM g1g1l1n3_group WHERE $chat_id = telegram_group_id";
  955. $resultNameGroup = $conn->query($selectNameGroup);
  956. if ($resultNameGroup->num_rows > 0) {
  957. // output data of each row
  958. while ($row = $resultNameGroup->fetch_assoc()) {
  959. $printNameGroupWelcome = $row["name_group"];
  960. $printIdGroupWelcome = $row["telegram_group_id"];
  961. }
  962. }
  963. //seleziono il content in base al name
  964. $selectContentGroup = "SELECT type_group, content FROM g1g1l1n3_phrase WHERE '$printNameGroupWelcome' = type_group";
  965. $resultContentGroup = $conn->query($selectContentGroup);
  966. if ($resultContentGroup->num_rows > 0) {
  967. // output data of each row
  968. while ($row = $resultContentGroup->fetch_assoc()) {
  969. $printWelcomeMessage = $row["content"];
  970. }
  971. }
  972.  
  973. if (($newchatmember_id == "223817217") or ($message['new_chat_participant']['id'] == "223817217")) {
  974. apiRequest("sendMessage", array(
  975. 'chat_id' => $chat_id,
  976. "text" => "Launch command /start if you want spoken with me :)"
  977. ));
  978. } else if ($chat_id == $printIdGroupWelcome) {
  979. apiRequest("sendChatAction", array(
  980. 'chat_id' => $chat_id,
  981. 'action' => "typing"
  982. ));
  983. apiRequest("sendMessage", array(
  984. 'chat_id' => $chat_id,
  985. "text" => $newchatmember_firstname . " |" . $newchatmember_id . "| " . $printWelcomeMessage
  986. ));
  987. } else {
  988. apiRequest("sendChatAction", array(
  989. 'chat_id' => $chat_id,
  990. 'action' => "typing"
  991. ));
  992. apiRequest("sendMessage", array(
  993. 'chat_id' => $chat_id,
  994. "text" => $newchatmember_firstname . " |" . $newchatmember_id . "| " . " welcome to the group, contact @GigilinEBot for other info"
  995. ));
  996. }
  997. $conn->close();
  998. } else if ((isset($message['left_chat_member'])) and ($printGroupStateBan == 0) and ($printUsersStateBan == 0) and ($printSettingsStateBotSuper == 0) and ($printStateBotWelcome != 0)) {
  999. apiRequest("sendChatAction", array(
  1000. 'chat_id' => $chat_id,
  1001. 'action' => "typing"
  1002. ));
  1003. apiRequest("sendMessage", array(
  1004. 'chat_id' => $chat_id,
  1005. "text" => $leftchatmember_firstname . " we hope to see you again soon"
  1006. ));
  1007. } else {
  1008. //non fare nulla
  1009. }
  1010. }
  1011.  
  1012.  
  1013. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement