· 6 years ago · Jan 02, 2020, 07:44 PM
1 <?php
2
3if ($chatID>0) {
4//connessione al db
5 $conn = mysqli_connect("localhost", "debian", "Z4nZ3go", "techerssbot");
6 $result = mysqli_query($conn, "select * from techbot_tag where chat=$chatID");
7 //controllo se l'utente è nel db dei canali (techbot_tag)
8
9 if (empty(mysqli_fetch_assoc($result)) === false) {
10 mysqli_query($conn, "CREATE TABLE IF NOT EXISTS db$chatID ( nome varchar(15) NOT NULL PRIMARY KEY, font text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin, modd int(2) NOT NULL)");
11
12 if ($msg == "/annulla" or $msg == "N" or $msg == "ANNULLA") {
13 mysqli_query($conn, "delete from techerssbot where chat=$chatID");
14 mysqli_query($conn, "update techprog set prog=1 where prog=2 and chat=$chatID");
15 $query=mysqli_query($conn, "select * from db$chatID where modd=1");
16 $query=mysqli_fetch_assoc($query);
17 if($query['font']==null and $query['modd']==1){
18 mysqli_query($conn, "delete from db$chatID where modd=1");
19 }else{
20 mysqli_query($conn, "update db$chatID set modd=0 where modd=1");
21 }
22 $keyb=array(array(array('text' => 'POST'),array('text' => 'FORMAT')),array(array("text"=>"CAMBIA FONT"),array('text' => 'ELIMINA FONT')),array(array('text' => "CAMBIA MARKUP"),array('text'=> 'ELIMINA PROG. POST')));
23 tastiera($chatID, "operazione annullata",$keyb);
24 exit();
25 }
26//-------------------------------------------
27 if ($msg=="/test"){
28 date_default_timezone_set('Europe/Rome');
29 $query = mysqli_query("select * from techprog where prog=1 and chat=$chatID order by ora limit 10");
30 $i=0;
31 $keyb= array();
32 while($row = mysqli_fetch_assoc($query))
33 {
34 $mess=$mess.$i++." -> ".$row['ind']." alle ore ".gmdate("H:i", $row['ora'])." del ".gmdate("Y-m-d",$row['ora'])."\n";
35 if($i<5){
36 $keyb[0][$i]['text']=$i+1;
37 }else{
38 $keyb[1][$i-5]['text']=$i+1;
39 }
40
41 $i++;
42 }
43 sendMessage($chatID, "ehi\n".implode(",",$keyb));
44 tastiera($chatID, $mess,$keyb);
45 exit();
46 }
47
48 if($msg=="ELIMINA PROG. POST"){
49 mysqli_query($conn, "update techprog set prog=1 where prog=2 and chat=$chatID");
50 mysqli_query($conn, "delete from techerssbot where chat=$chatID");
51
52 mysqli_query($conn, "update db$chatID set modd=0 where modd=1");
53 mysqli_query($conn, "insert into techerssbot (chat, step) values ($chatID, 43)");
54 $totalteams = mysqli_query($conn, "select post from techprog where chat=$chatID");
55$row2=array();
56while ($row = mysqli_fetch_assoc( $totalteams )) {
57 //if($row['tag']=='tag'){
58 if($row['parse_mode']=="HTML"){
59 $nnn=strpos($row['post'],"</a>");
60
61 }elseif($row['parse_mode']=="Markdown"){
62 $nnn=strpos($row['post'],"</a>");
63 }
64 sendMessage($chatID,$row['post']);
65 $row['text']=substr($row['post'],$nnn+4,$nnn+34);
66 unset ($row['post']);
67 array_push($row2,$row);
68 //}
69}
70$fff=array("text"=>"ANNULLA");
71array_push($row2,$fff);
72 $keyb = array_chunk($row2, 2);
73 tastiera($chatID, 'scegli quale post eliminare',$keyb);
74 exit();
75 }
76
77 if($msg == "/cambia" or $msg=="CAMBIA FONT" or $msg== "/del" or $msg=="ELIMINA FONT"){
78 mysqli_query($conn, "delete from techerssbot where chat=$chatID");
79 mysqli_query($conn, "update techprog set prog=1 where prog=2 and chat=$chatID");
80 mysqli_query($conn, "update db$chatID set modd=0 where modd=1");
81 //$keyb=array(array(array('text' => 'ANNULLA')));
82 $totalteams = mysqli_query($conn, "select nome from db$chatID");
83$row2=array();
84while ($row = mysqli_fetch_assoc( $totalteams )) {
85 //if($row['tag']=='tag'){
86 $row['text']=$row['nome'];
87 unset ($row['nome']);
88 array_push($row2,$row);
89 //}
90}
91$fff=array("text"=>"ANNULLA");
92array_push($row2,$fff);
93 $keyb = array_chunk($row2, 2);
94 if($msg == "/cambia" or $msg=="CAMBIA FONT"){
95 mysqli_query($conn, "insert into techerssbot (chat,step) values ($chatID,19)");
96 tastiera($chatID, "Scegli il font che vuoi utilizzare",$keyb);
97 }elseif($msg== "/del" or $msg=="ELIMINA FONT"){
98 mysqli_query($conn, "insert into techerssbot (chat,step) values ($chatID,21)");
99 tastiera($chatID, "Scegli il font che vuoi eliminare",$keyb);
100 }
101
102 exit();
103 }
104
105
106 if($msg == "/format" or $msg=="FORMAT"){
107 mysqli_query($conn, "update techprog set prog=1 where prog=2 and chat=$chatID");
108 mysqli_query($conn, "insert into techerssbot (chat,step) values ($chatID,9)");
109 mysqli_query($conn, "update db$chatID set modd=0 where modd=1");
110 $keyb=array(array(array('text' => 'ANNULLA')));
111 tastiera($chatID, "Scrivi il nome che vuoi assegnare al format",$keyb);
112 exit();
113 }
114
115 if($msg == "/markup" or $msg == "CAMBIA MARKUP"){
116 mysqli_query($conn, "update techprog set prog=1 where prog=2 and chat=$chatID");
117 mysqli_query($conn, "insert into techerssbot (chat,step) values ($chatID,30)");
118 mysqli_query($conn, "update db$chatID set modd=0 where modd=1");
119 $keyb=array(array(array('text' => "HTML"),array ('text' => "Markdown")),array(array('text' => 'ANNULLA')));
120 tastiera($chatID, "Seleziona il linguaggio di markup che vorresti utilizzare, esso non sarà applicato se userai un format con markup prefissato",$keyb);
121 exit();
122 }
123
124 if($msg=="/start"){
125 mysqli_query($conn, "update techprog set prog=1 where prog=2 and chat=$chatID");
126 mysqli_query($conn, "update db$chatID set modd=0 where modd=1");
127 mysqli_query($conn, "delete from techerssbot where chat=$chatID");
128 $keyb=array(array(array('text' => 'POST'),array('text' => 'FORMAT')),array(array("text"=>"CAMBIA FONT"),array('text' => 'ELIMINA FONT')),array(array('text' => "CAMBIA MARKUP"),array('text'=> 'ELIMINA PROG. POST')));
129 tastiera($chatID, "Benvenuto, clicca su POST per scriverne uno",$keyb);
130 exit();
131 }
132
133 //aggiungo l'utente nel db degli annunci (techerssbot)
134 if ($msg == "/post" or $msg == "POST") {
135 mysqli_query($conn, "update techprog set prog=1 where prog=2 and chat=$chatID");
136 mysqli_query($conn, "update db$chatID set modd=0 where modd=1");
137 mysqli_query($conn, "insert into techerssbot (chat,step) values ($chatID,0)");
138 if(empty(mysqli_error($conn))){
139 $keyb=array(array(array('text' => 'ANNULLA')));
140 tastiera($chatID, "Perfetto, cominciamo. Scrivi qui il tuo link!",$keyb);
141 }else{
142 sendMessage($chatID, "stai già creando un post");
143 }
144 exit();
145 }
146
147 if (empty($msg) === false) {
148 $query = mysqli_query($conn, "select * from techerssbot where chat=$chatID");
149 $query = mysqli_fetch_assoc($query);
150 //controllo se l'utente è presente nel db degli annunci (techerssbot)
151 if(empty($query) === false){
152 if($msg=="INDIETRO"){
153 if($query['step']>1){
154 $canale=mysqli_query($conn,"select canale from techbot_tag where chat=$chatID");
155 $canale=mysqli_fetch_assoc($canale);
156 mysqli_query($conn, "delete from techprog where prog=0 and canale='".$canale['canale']."'");
157 //$query['step']=0;
158 mysqli_query($conn, "update techerssbot set step=1 where chat=$chatID");
159 $keyb=array(array(array('text' => 'INVIA SUBITO'),array( 'text' => 'NO')),array(array('text' => 'DESCRIZIONE'),array('text'=> 'TITOLO')),array(array('text' => 'MODIFICA PREZZO'),array('text' => 'FOTO')),array(array('text' => 'MOSTRA / NASCONDI RISPARMIO'),array('text'=> 'CAMBIA VENDITORE')),array(array('text' => 'PROGRAMMA POST')));
160 tastiera($chatID, "Confermi?",$keyb);
161 format($chatID, $conn, false);
162
163 exit();
164 }
165 }
166 switch ($query['step']) {
167 //step 0, quello che accade quando si manda un mess dopo POST
168 case 0:
169 if (stripos($msg, "amzn.to")) {
170 $asin = expand($msg);
171 } else {
172 $asin = $msg;
173 }
174 $asun = getasin($asin);
175 //cose tue ma in sql
176 if ($asun != 'fail') {
177 $query2 = mysqli_query($conn, "select tag from techbot_tag where chat=$chatID");
178 $ref = mysqli_fetch_assoc($query2);
179 $ref = $ref['tag'];
180 if ((stripos($asin, "offer-listing") or stripos($asin, "/ol")) and (stripos($asin, "condition=used") or stripos($asin, "f_usedVeryGood=true") or stripos($asin, "f_usedGood=true") or stripos($msg, "f_usedAcceptable=true") or stripos($asin, "f_usedLikeNew=true"))) {
181 $link = short("https://amazon.it/gp/offer-listing/" . $asun . "/?tag=" . $ref . "&condition=used", $ref);
182 $condizione = "usato";
183 } else if (stripos($asin, "offer-listing") or stripos($asin, "/ol")) {
184 $link = short("https://amazon.it/gp/offer-listing/" . $asun . "/?tag=" . $ref, $ref);
185 $condizione = "nuovo";
186 } else if ((stripos($asin, "offer-listing") or stripos($asin, "offer-listing")) and (stripos($asin, "condition=new") or stripos($asin, "f_new=true"))) {
187 $link = short("https://amazon.it/gp/offer-listing/" . $asun . "/?tag=" . $ref . "&condition=new", $ref);
188 $condizione = "nuovot";
189 } else {
190 $link = short("https://amazon.it/dp/" . $asun . "/?tag=" . $ref, $ref);
191 $condizione = "nuovo";
192 }
193 if ($condizione == "usato") {
194 $url = amazonit($asun, $ref, "Used");
195 } else {
196 $url = amazonit($asun, $ref);
197 }
198
199 $xml = simplexml_load_string(file_get_contents($url), "SimpleXMLElement", LIBXML_NOCDATA);
200 $json = json_encode($xml);
201 $a = json_decode($json, TRUE);
202
203 $titolo = $a["Items"]["Item"]["ItemAttributes"]["Title"];
204 $titolo=mysqli_real_escape_string($conn,$titolo);
205 $foto = $a["Items"]["Item"]["LargeImage"]["URL"];
206
207 if (empty($foto)) {
208 $foto = $a["Items"]["Item"]["ImageSets"]["ImageSet"]["LargeImage"]["URL"];
209 }
210
211 if (empty($foto)) {
212 $foto = $a["Items"]["Item"]["ImageSets"]["ImageSet"][1]["LargeImage"]["URL"];
213 }
214
215 if (stripos($asin, ".it")) {
216 $emoji = "\xF0\x9F\x87\xAE\xF0\x9F\x87\xB9";
217
218 } else if (stripos($asin, ".fr")) {
219 $emoji = "\xF0\x9F\x87\xAB\xF0\x9F\x87\xB7";
220 } else if (stripos($asin, ".de")) {
221 $emoji = "\xF0\x9F\x87\xA9\xF0\x9F\x87\xAA ";
222 } else {
223 $emoji = "error";
224 }
225
226 $vend = $a["Items"]["Item"]["Offers"]["Offer"]["Merchant"]["Name"];
227
228 if ($condizione == "usato") {
229 $prezzo = number_format($a["Items"]["Item"]["OfferSummary"]["LowestUsedPrice"]["Amount"] / 100, 2, ',', '') . "€";
230
231 if ($prezzo == "0,00€") {
232 sendMessage($chatID, "Mi dispiace ma il prodotto non è disponibile");
233 exit();
234 } else {
235
236
237
238 //mysqli_query($conn, "update techerssbot set price = '$prezzo', step=1, titolo='$titolo', descrizione='$vend $emoji', cond='usato', link='$link', foto='$foto' where chat=$chatID");
239
240 }
241 } else {
242 if ($condizione == "nuovo") {
243 $prezzo = number_format($a["Items"]["Item"]["Offers"]["Offer"]["OfferListing"]["Price"]["Amount"] / 100, 2, ',', '') . "€";
244 $sale = number_format($a["Items"]["Item"]["Offers"]["Offer"]["OfferListing"]["SalePrice"]["Amount"] / 100, 2, ',', '') . "€";
245 // andlea
246 $listino = number_format($a["Items"]["Item"]["ItemAttributes"]["ListPrice"]["Amount"] / 100, 2, ',', '') . "€";
247 $risparmio = number_format($a["Items"]["Item"]["Offers"]["Offer"]["OfferListing"]["AmountSaved"]["Amount"] / 100, 2, ',', '') . "€";
248 } elseif ($condizione == "nuovot") {
249 $condizione = "nuovo";
250 $prezzo = number_format($a["Items"]["Item"]["OfferSummary"]["LowestNewPrice"]["Amount"] / 100, 2, ',', '') . "€";
251 $sale = "0,00€";
252 }
253 if ($sale != "0,00€") {
254 $prezzo = $sale;
255 }
256
257 if ($prezzo == "0,00€") {
258 sendMessage($chatID, "Mi dispiace ma il prodotto non è disponibile");
259 exit();
260 }
261
262 }
263 //$emoji = "ciao";
264 $qqq="update techerssbot set price = '$prezzo', step=1, titolo='$titolo', cond='$condizione', link='$link', foto='$foto', emoji='".utf8_encode($emoji)."', venditore='$vend', prezzo_ori='$listino', risparmio='$risparmio', show_ris=1, show_ven=1 where chat=$chatID";
265 mysqli_query($conn, $qqq);
266 //----------------------------
267 //sendMessage($chatID, "errore: ".mysqli_error($conn));
268 //sendMessage($chatID, "$qqq");
269
270 format($chatID, $conn, false);
271
272 $keyb=array(array(array('text' => 'INVIA SUBITO'),array( 'text' => 'NO')),array(array('text' => 'DESCRIZIONE'),array('text'=> 'TITOLO')),array(array('text' => 'MODIFICA PREZZO'),array('text' => 'FOTO')),array(array('text' => 'MOSTRA / NASCONDI RISPARMIO'),array('text'=> 'CAMBIA VENDITORE')),array(array('text' => 'PROGRAMMA POST')));
273 tastiera($chatID, "Confermi?",$keyb);
274 }
275
276
277 else {
278 tastiera($chatID, "Il link non è valido. Riscrivilo correttamente oppure annulla.", array(array(array('text'=>'ANNULLA'))));
279 }
280
281 break;
282 case 1:
283 //questi sono i comandi eseguiti quando INVIA SUBITO clicca sulla tastiera
284 if ($msg == "N" or $msg == "n" or $msg == "no" or $msg == "NO") {
285 mysqli_query($conn, "delete from techerssbot where chat=$chatID");
286 $keyb=array(array(array('text' => 'POST'),array('text' => 'FORMAT')),array(array("text"=>"CAMBIA FONT"),array('text' => 'ELIMINA FONT')),array(array('text' => "CAMBIA MARKUP"),array('text'=> 'ELIMINA PROG. POST')));
287 tastiera($chatID, "Post annullato.",$keyb);
288
289 } else if ($msg == "S" or $msg == "s" or $msg == "Si" or $msg == "INVIA SUBITO" or $msg == "Si") {
290 $canale=mysqli_query($conn, "select * from techbot_tag where chat=$chatID");
291 $canale=mysqli_fetch_assoc($canale);
292 format($chatID, $conn,$canale['canale'] );
293 //sendMessage("@gaetanobrutto", $newmsg); // da modificare----------------------------------------------------------
294 $keyb=array(array(array('text' => 'POST'),array('text' => 'FORMAT')),array(array("text"=>"CAMBIA FONT"),array('text' => 'ELIMINA FONT')),array(array('text' => "CAMBIA MARKUP"),array('text'=> 'ELIMINA PROG. POST')));
295 tastiera($chatID, "Il post è stato postato correttamente nel canale!",$keyb);
296 mysqli_query($conn, "delete from techerssbot where chat=$chatID");
297 } else if ($msg == "MODIFICA PREZZO") {
298 $prezzo = mysqli_query($conn, "select * from techerssbot where chat=$chatID");
299 $prezzo = mysqli_fetch_assoc($prezzo);
300 //sendMessage($chatID, "Prezzo attuale: " . $prezzo['price'] . "!\nScrivi il nuovo prezzo!\nP.S. Per rendere il tutto più veloce scrivi solo i numeri\n139.54 = 13954");
301 $keyb=array(array(array('text' => 'INDIETRO'),array('text'=>'ANNULLA')));
302 tastiera($chatID, "Prezzo attuale: " . str_replace("€","€",$prezzo['price']) . "!\nScrivi il nuovo prezzo!\nP.S. Per rendere il tutto più veloce scrivi solo i numeri\n139.54 = 13954",$keyb);
303
304 mysqli_query($conn, "update techerssbot set step=2 where chat=$chatID");
305 } else if ($msg == "DESCRIZIONE") {
306
307 $modde = mysqli_query($conn, "select * from techerssbot where chat = $chatID");
308 $modde = mysqli_fetch_assoc($modde);
309
310 if (empty($modde['descrizione'])) {
311 $modde['descrizione'] = 'nessuna';
312 }
313
314 $keyb=array(array(array('text'=>'VUOTO')),array(array('text'=>'ANNULLA')));
315 tastiera($chatID, "Descrizione attuale: " . $modde['descrizione'] . "\nScrivi quella nuova!\nPuoi usare la formattazione HTML.",$keyb);
316 mysqli_query($conn, "update techerssbot set step=3 where chat=$chatID");
317 /* qui no
318 * $fr=fopen($nome."desc.txt","w");
319 * fwrite($fr, $a[1]);
320 * fclose($fr);
321 qui no*/
322
323 exit();
324 } elseif($msg=="TITOLO") {
325 $modde = mysqli_query($conn, "select * from techerssbot where chat = $chatID");
326 $modde = mysqli_fetch_assoc($modde);
327
328 $keyb=array(array(array('text' => 'INDIETRO'),array('text'=>'ANNULLA')));
329 tastiera($chatID, "Titolo attuale: " . $modde['titolo'] . "\nScrivi quello nuovo!",$keyb);
330 mysqli_query($conn, "update techerssbot set step=4 where chat=$chatID");
331 }elseif($msg=="FOTO"){
332 $keyb=array(array(array('text' => 'INDIETRO'),array('text'=>'ANNULLA')));
333 tastiera($chatID, "Inviami il link di una foto",$keyb);
334 mysqli_query($conn, "update techerssbot set step=5 where chat=$chatID");
335 }elseif($msg=="PROGRAMMA"){
336 $keyb=array(array(array('text' => 'INDIETRO'),array('text'=>'ANNULLA')));
337 tastiera($chatID, "Se vuoi postarlo nello stesso giorno scrivi ora:min:sec\n\nSe vuoi pubblicarlo in un altro giorno scrivi anno-mese-giorno ora:min:sec ",$keyb);
338 mysqli_query($conn, "update techerssbot set step=40 where chat=chatID");
339 }elseif($msg=="MOSTRA / NASCONDI RISPARMIO"){
340 $show=mysqli_query($conn, "select show_ris from techerssbot where chat=$chatID");
341 $show=mysqli_fetch_assoc($show);
342 if($show['show_ris']==0){
343 $val=1;
344 $newmsg="Mostra risparmio: ON";
345 }elseif($show['show_ris']==1){
346 $val=0;
347 $newmsg="Mostra risparmio: OFF";
348 }
349 mysqli_query($conn, "update techerssbot set show_ris=$val where chat=$chatID");
350 sendMessage($chatID,$newmsg);
351 format($chatID, $conn, false);
352 $keyb=array(array(array('text' => 'INVIA SUBITO'),array( 'text' => 'NO')),array(array('text' => 'DESCRIZIONE'),array('text'=> 'TITOLO')),array(array('text' => 'MODIFICA PREZZO'),array('text' => 'FOTO')),array(array('text' => 'MOSTRA / NASCONDI RISPARMIO'),array('text'=> 'CAMBIA VENDITORE')),array(array('text' => 'PROGRAMMA POST')));
353 tastiera($chatID, "Confermi?",$keyb);
354 }elseif($msg=="PROGRAMMA POST"){
355 mysqli_query($conn, "update techerssbot set step=40 where chat=$chatID");
356 $keyb=array(array(array('text'=>'INDIETRO')));
357 tastiera($chatID,"scrivi un orario in questo modo\nanno-mese-giorno ora:minuto\n se scriverai solo l'orario verrà impostato al giorno stesso della programmazzione",$keyb);
358 exit();
359 }elseif($msg=="CAMBIA VENDITORE"){
360 mysqli_query($conn, "update techerssbot set step=35 where chat=$chatID");
361 $keyb=array(array(array('text' => 'INDIETRO'),array('text'=> 'VUOTO')),array(array('text'=>'ANNULLA')));
362 tastiera($chatID, "Scrivi il nome del venditore",$keyb);
363 }else{
364 sendMessage($chatID, "Mi spiace ma non capisco. Clicca sul bottone giusto!");
365 }
366exit();
367 break;
368
369 case 2:
370 //controllo che l'msg contenga solo numeri
371 if(ctype_digit($msg)){
372 //transformo numeri con meno di 3 cifre in numeri a 3 cifre (esempio 2 => 002 che poi diventerà 0,002)
373 if(strlen($msg) < 3 ){
374 for($i = 0; $i < 4-strlen($msg); $i++){
375 $msg="0".$msg;
376 }
377 }
378 //metto la virgola e l'€ al prezzo
379 $price = substr($msg, 0, -2).",".substr($msg,-2)."€";
380 mysqli_query($conn, "update techerssbot set price='$price', step=1 where chat= $chatID");
381 sendMessage($chatID, "prezzo modificato");
382 format($chatID, $conn,false);
383 $keyb=array(array(array('text' => 'INVIA SUBITO'),array( 'text' => 'NO')),array(array('text' => 'DESCRIZIONE'),array('text'=> 'TITOLO')),array(array('text' => 'MODIFICA PREZZO'),array('text' => 'FOTO')),array(array('text' => 'MOSTRA / NASCONDI RISPARMIO'),array('text'=> 'CAMBIA VENDITORE')),array(array('text' => 'PROGRAMMA POST')));
384 tastiera($chatID, "Confermi?",$keyb);
385 }elseif($msg!=="INDIETRO"){
386 sendMessage($chatID, "perfavore inseririsci solo le cifre senza lettere, punti e virgole");
387 }else{
388 tastiera($chatID, "Confermi?",$keyb);
389 }
390 break;
391
392 case 3:
393 //salvo il messaggio come descrizione
394 if($msg=="VUOTO"){
395 mysqli_query($conn, "update techerssbot set descrizione=null, step=1 where chat= $chatID");
396 sendMessage($chatID, "Descrizione impostata come vuota");
397 }else{
398 $descri=mysqli_real_escape_string($conn,$msg);
399 mysqli_query($conn, "update techerssbot set descrizione='$descri', step=1 where chat= $chatID");
400 sendMessage($chatID, "La nuova descrizione è: $msg");
401 }
402 format($chatID, $conn, false);
403 $keyb=array(array(array('text' => 'INVIA SUBITO'),array( 'text' => 'NO')),array(array('text' => 'DESCRIZIONE'),array('text'=> 'TITOLO')),array(array('text' => 'MODIFICA PREZZO'),array('text' => 'FOTO')),array(array('text' => 'MOSTRA / NASCONDI RISPARMIO'),array('text'=> 'CAMBIA VENDITORE')),array(array('text' => 'PROGRAMMA POST')));
404 tastiera($chatID, "Confermi?",$keyb);
405 break;
406
407 case 4:
408 //salvo il messaggio come titolo
409 $titolo=mysqli_real_escape_string($conn,$msg);
410 mysqli_query($conn, "update techerssbot set titolo='$titolo', step=1 where chat= $chatID");
411 sendMessage($chatID, "Il nuovo titolo è: $msg\n".mysqli_error($conn));
412 format($chatID, $conn, false);
413 $keyb=array(array(array('text' => 'INVIA SUBITO'),array( 'text' => 'NO')),array(array('text' => 'DESCRIZIONE'),array('text'=> 'TITOLO')),array(array('text' => 'MODIFICA PREZZO'),array('text' => 'FOTO')),array(array('text' => 'MOSTRA / NASCONDI RISPARMIO'),array('text'=> 'CAMBIA VENDITORE')),array(array('text' => 'PROGRAMMA POST')));
414 tastiera($chatID, "Confermi?",$keyb);
415 break;
416
417 case 5:
418 if(is_array(getimagesize($msg))){
419 mysqli_query($conn, "update techerssbot set foto='$msg', step=1 where chat= $chatID");
420 sendMessage($chatID, "Nuova foto impostata");
421 format($chatID, $conn, false);
422 $keyb=array(array(array('text' => 'INVIA SUBITO'),array( 'text' => 'NO')),array(array('text' => 'DESCRIZIONE'),array('text'=> 'TITOLO')),array(array('text' => 'MODIFICA PREZZO'),array('text' => 'FOTO')),array(array('text' => 'MOSTRA / NASCONDI RISPARMIO'),array('text'=> 'CAMBIA VENDITORE')),array(array('text' => 'PROGRAMMA POST')));
423 tastiera($chatID, "Confermi?",$keyb);
424 }else{
425 $keyb=array(array(array('text' => 'INDIETRO'),array('text'=>'ANNULLA')));
426 tastiera($chatID, "Perfavore, invia il link di una foto",$keyb);
427 }
428 break;
429
430 case 9:
431 $query=mysqli_query($conn, "select * from db$chatID where nome='$msg'");
432 $query=mysqli_fetch_assoc($query);
433 if(empty($query)){
434 mysqli_query($conn, "insert into db$chatID (nome, modd) values ('$msg',1)");
435
436 }else{
437 mysqli_query($conn, "update db$chatID set modd=1 where nome='$msg'");
438 }
439
440 if(empty(mysqli_error($conn))){
441 $keyb=array(array(array('text' => 'HTML'),array('text' => 'Markdown')),array(array('text' => 'Nessuno'),array('text' => 'ANNULLA')));
442 tastiera($chatID, "Perfetto, ora decidi quale linguaggio di markup usare, esso sarà usato indifferentemente nel post dal linguagio di markup selezionato, solo con ".'"'."Nessuno".'"'." sarà possibile poter scegliere succesivamente il linguaggio markup (almeno che non ricrei il format), ma ovviamente non potrai mettere di default alcune parti di testo in grassetto, corsivo ecc",$keyb);
443 mysqli_query($conn, "update techerssbot set step=10 where chat= $chatID");
444 }else{
445 $keyb=array(array(array('text' => 'ANNULLA')));
446 tastiera($chatID, "perfavore, inseririsci un nome più corto",$keyb);
447 }
448 break;
449
450 case 10:
451 if($msg=="HTML" or $msg=="Markdown" or $msg=="Nessuno"){
452 mysqli_query($conn, "update techerssbot set step=11 where chat= $chatID");
453 if($msg!="Nessuno"){
454 mysqli_query($conn, "update db$chatID set parse_mode='$msg' where modd= 1");
455 }
456 $keyb=array(array(array('text' => "ANNULLA")));
457 tastiera($chatID, "Perfetto, ora scrivi il format che vuoi usare, ci sono le variabili \n{titolo}\n{descrizione}\n{prezzo}\n{link}\n{venditore}\n{bandiera}\n{prezzo originale}\n{risparmio}",$keyb);
458
459 }else{
460 sendMessage($chatID, 'perfavore scegli tra le opzioni qui sotto');
461 }
462
463
464
465 break;
466
467
468 case 11:
469 if(strpos($msg,"{link}")!==false and strpos($msg,"{titolo}")!==false){
470 mysqli_query($conn, "update db$chatID set font='$msg', modd=0 where modd= 1");
471 mysqli_query($conn, "delete from techerssbot where chat= $chatID");
472 $keyb=array(array(array('text' => 'POST'),array('text' => 'FORMAT')),array(array("text"=>"CAMBIA FONT"),array('text' => 'ELIMINA FONT')),array(array('text' => "CAMBIA MARKUP"),array('text'=> 'ELIMINA PROG. POST')));
473 tastiera($chatID, "format aggiornato",$keyb);
474 }else{
475 $keyb=array(array(array('text' => 'ANNULLA')));
476 tastiera($chatID, "perfavore inserisci almeno {titolo} e {link}",$keyb);
477 }
478 break;
479
480
481
482
483 case 19:
484 $controllo=mysqli_query($conn, "select * from db$chatID where nome='$msg'");
485 $controllo = mysqli_fetch_assoc($controllo);
486 if(in_array($msg,$controllo)){
487 mysqli_query($conn, "update db$chatID set modd=1 where nome='$msg'");
488 mysqli_query($conn, "update techerssbot set step=20 where chat=$chatID");
489 $keyb=array(array(array('text' => 'NUOVO'),array('text' => 'USATO')),array(array('text' => 'ANNULLA')));
490 tastiera($chatID, "ora seleziona se questo font vuoi usarlo per i post di prodotti nuovi o usati",$keyb);
491 }else{
492 sendMessage($chatID, 'scegli tra i font qui sotto per piacere');
493 }
494 break;
495
496
497 case 20:
498 if($msg=='NUOVO' or $msg=='USATO'){
499 $format=mysqli_query($conn, "select * from db$chatID where modd=1");
500 $format= mysqli_fetch_assoc($format);
501 $newfor=$format['nome'];
502 if($msg=='NUOVO'){
503 mysqli_query($conn, "update techbot_tag set format_n='$newfor' where chat=$chatID");
504 }elseif($msg=='USATO'){
505 mysqli_query($conn, "update techbot_tag set format_u='$newfor' where chat=$chatID");
506 }
507 mysqli_query($conn, "delete from techerssbot where chat=$chatID");
508 $keyb=array(array(array('text' => 'POST'),array('text' => 'FORMAT')),array(array("text"=>"CAMBIA FONT"),array('text' => 'ELIMINA FONT')),array(array('text' => "CAMBIA MARKUP"),array('text'=> 'ELIMINA PROG. POST')));
509 tastiera($chatID, "font selezionato",$keyb);
510
511 }else{
512 sendMessage($chatID, 'scegli tra le 2 opzioni');
513 }
514 break;
515
516 case 21:
517 $font = mysqli_query($conn, "select * from db$chatID where nome='$msg'");
518 $font= mysqli_fetch_assoc($font);
519 mysqli_query($conn, "update techerssbot set step=22 where chat=$chatID");
520 mysqli_query($conn, "update db$chatID set modd=1 where nome='$msg'");
521 sendMessage($chatID, $font['font']);
522 $keyb=array(array(array('text' => 'SI'),array('text' => 'NO')));
523 tastiera($chatID, "vuoi eliminare il font?",$keyb);
524
525 break;
526
527 case 22:
528
529 mysqli_query($conn, "delete from techerssbot where chat=$chatID");
530 $keyb=array(array(array('text' => 'POST'),array('text' => 'FORMAT')),array(array("text"=>"CAMBIA FONT"),array('text' => 'ELIMINA FONT')),array(array('text' => "CAMBIA MARKUP"),array('text'=> 'ELIMINA PROG. POST')));
531 if($msg=="SI"){
532 mysqli_query($conn, "delete from db$chatID where modd=1");
533 tastiera($chatID, "Font eliminato",$keyb);
534 }elseif($msg=="NO"){
535 mysqli_query($conn, "update db$chatID set modd=0 where modd=1");
536 tastiera($chatID, "Operazione annullata",$keyb);
537 }else{
538 sendMessage($chatID, 'sceglie una delle 2 opzioni');
539 }
540 break;
541
542 case 30:
543 if($msg=="HTML" or $msg=="Markdown"){
544 mysqli_query($conn, "delete from techerssbot where chat=$chatID");
545 mysqli_query($conn, "update techbot_tag set parse_mode='$msg' where chat=$chatID");
546 $keyb=array(array(array('text' => 'POST'),array('text' => 'FORMAT')),array(array("text"=>"CAMBIA FONT"),array('text' => 'ELIMINA FONT')),array(array('text' => "CAMBIA MARKUP"),array('text'=> 'ELIMINA PROG. POST')));
547 tastiera($chatID, "linguaggio di markup aggiornato",$keyb);
548 }else{
549 $keyb=array(array(array('text' => 'ANNULLA')));
550 tastiera($chatID, "perfavore inserisci almeno {titolo} e {link}",$keyb);
551 }
552 break;
553
554 case 35:
555 if($msg=="VUOTO"){
556 mysqli_query($conn,"update techerssbot set step=1, show_ven=0 where chat= $chatID");
557 sendMessage($chatID, 'nome venditore eliminato');
558 }else{
559 mysqli_query($conn,"update techerssbot set step=1, venditore='$msg', emoji=null, show_ven=1 where chat= $chatID");
560 sendMessage($chatID, 'nome venditore aggiornato');
561 }
562
563
564 format($chatID, $conn, false);
565 $keyb=array(array(array('text' => 'INVIA SUBITO'),array( 'text' => 'NO')),array(array('text' => 'DESCRIZIONE'),array('text'=> 'TITOLO')),array(array('text' => 'MODIFICA PREZZO'),array('text' => 'FOTO')),array(array('text' => 'MOSTRA / NASCONDI RISPARMIO'),array('text'=> 'CAMBIA VENDITORE')),array(array('text' => 'PROGRAMMA POST')));
566 tastiera($chatID, "Confermi?",$keyb);
567 break;
568
569 case 40:
570
571 date_default_timezone_set('Europe/Rome');
572 $tempo = time();
573 if(strpos($msg,"-")===false){
574
575 $unixtime2 = date("Y-m-d", $tempo);
576 $msg=$unixtime2." $msg";
577 }
578 $msg=$msg.":00";
579 $unixtime=strtotime($msg);
580 if($tempo-15>$unixtime){
581 $keyb=array(array(array('text'=>'INDIETRO')));
582 tastiera($chatID,"perfavore metti un orario valido",$keyb);
583 }else{
584 $unixtime3=$unixtime;
585 prog_post($chatID, $conn, $unixtime3,$updateID);
586 sendMessage($chatID,$updateID);
587 $keyb=array(array(array('text' => 'SI'),array('text' => 'INDIETRO')));
588 tastiera($chatID, "vuoi mandare il post alle ".date("H:i", $unixtime)." del ".date("Y-m-d",$unixtime)." ?",$keyb);
589 mysqli_query($conn, "update techerssbot set step=41 where chat=$chatID");
590 }
591 exit();
592 break;
593
594
595 case 41:
596 $canale=mysqli_query($conn, "select canale from techbot_tag where chat=$chatID");
597 $canale=mysqli_fetch_assoc($canale);
598 if($msg=="SI"){
599 $canale=mysqli_query($conn,"select canale from techbot_tag where chat=$chatID");
600 $canale=mysqli_fetch_assoc($canale);
601 mysqli_query($conn, "delete from techerssbot where chat=$chatID");
602 mysqli_query($conn, "update techprog set prog=1 where prog=0 and canale='".$canale['canale']."'");
603
604 $keyb=array(array(array('text' => 'POST'),array('text' => 'FORMAT')),array(array("text"=>"CAMBIA FONT"),array('text' => 'ELIMINA FONT')),array(array('text' => "CAMBIA MARKUP"),array('text'=> 'ELIMINA PROG. POST')));
605 tastiera($chatID, "Post programmato",$keyb);
606 exit();
607 /*qui no}elseif($msg=="NO"){
608 mysqli_query($conn, "delete from techprog where prog=0 and canale='".$canale['canale']."'");
609 mysqli_query($conn, "update techerssbot set step=1 where chat=$chatID");
610 $keyb=array(array(array('text' => 'SI'),array( 'text' => 'NO')),array(array('text' => 'DESCRIZIONE'),array('text'=> 'TITOLO')),array(array('text' => 'MODIFICA PREZZO'),array('text' => 'FOTO')),array(array('text' => 'MOSTRA / NASCONDI RISPARMIO'),array('text' => 'PROGRAMMA POST')));
611 tastiera($chatID, "Programmazione annullata",$keyb);
612 format($chatID, $conn, false);
613 qui no*/
614 }elseif($msg!="INDIETRO"){
615 sendMessage($chatID, "clicca su uno dei pulsanti");
616 }
617
618 break;
619
620 case 43:
621 $annunci = mysqli_query($conn, "select * from techprog where post like '%$msg%' and prog=1 and chat=$chatID order by ind limit 1");
622 $annunci= mysqli_fetch_assoc($annunci);
623 mysqli_query($conn, "update techprog set prog=2 where post like '%$msg%' and prog=1 and chat=$chatID order by ind limit 1");
624 //$url = "https://api.telegram.org/bot745675458:AAETKSLYYVhNLn-Hge7kdBz4r98omG5ALOg/sendMessage?chat_id=".$annunci['canale']."&parse_mode=".$annunci['parse_mode']."&text=".urlencode($annunci['post']);
625 $url = "https://api.telegram.org/$api/sendMessage?chat_id=".$annunci['canale']."&parse_mode=".$annunci['parse_mode']."&text=".urlencode($annunci['post']);
626 $get = file_get_contents($url);
627 $keyb=array(array(array('text'=>'SI'),array('text'=>'ANNULLA')));
628 tastiera($chatID,"vuoi eliminare questo post?",$keyb);
629 mysqli_query($conn, "update techerssbot set step=44 where chat=$chatID");
630 break;
631
632 case 44:
633 if($msg=="SI"){
634 mysqli_query($conn, "delete from techprog where prog=1 and chat=$chatID");
635 $keyb=array(array(array('text' => 'POST'),array('text' => 'FORMAT')),array(array("text"=>"CAMBIA FONT"),array('text' => 'ELIMINA FONT')),array(array('text' => "CAMBIA MARKUP"),array('text'=> 'ELIMINA PROG. POST')));
636 tastiera($chatID, "Post eliminato",$keyb);
637 }else{
638 sendMessage($chatID, 'perfavore scegli una delle 2 opzioni');
639 }
640 break;
641
642 /* case 45:
643 date_default_timezone_set('Europe/Rome');
644 $query = mysqli_query("select * from techprog where prog=1 and chat=$chatID order by ora limit 10");
645 $i=0;
646 $keyb= array();
647 while($row = mysqli_fetch_array($query))
648 {
649 $mess=$mess.$i++." -> ".$row['ind']." alle ore ".gmdate("H:i", $row['ora'])." del ".gmdate("Y-m-d",$row['ora'])."\n";
650 if($i<5){
651 $keyb[0][$i]['text']=$i++;
652 }else{
653 $keyb[1][$i-5]['text']=$i++;
654 }
655
656 $i++;
657 }
658 break;*/
659 }
660 }elseif(strpos($msg,"/del")===false and strpos($msg,"/add")===false){
661sendMessage($chatID, "clicca su POST per cominciare");
662}
663}
664 // ---------------------------
665 } else {
666 sendMessage($chatID, 'Mi spiace ma non sei autorizzato ad usare questo bot.');
667 }
668 mysqli_close($conn);
669}