-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalecasa.rb
1469 lines (1469 loc) · 88 KB
/
valecasa.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
$token = nil
if File.exists?($token_file)
$token = File.read($token_file)
$token.chomp!
end
begin
Telegram::Bot::Client.run($token) do |bot|
bot.listen do |message|
if $array_authorized.include?(message.from.id)
puts "Ricevuto messaggio da ID #{message.from.id}, autorizzato!"
puts "Nome: #{message.from.first_name}"
puts "Cognome: #{message.from.last_name}"
puts "Username: #{message.from.username}"
case message.text
when '/dimmichisono'
puts "Ricevuto messaggio /dimmichisono \n"
bot.api.send_message(chat_id: message.chat.id, text: "Ciao #{message.from.first_name}, il tuo ID è #{message.from.id}, la chat ID è #{message.chat.id}")
when '/lista_1'
puts "Ricevuto messaggio /lista_1 \n"
$log.info("Eseguo comando #{$cmd_lista_1}")
errors = false
stdout,stderr,status = Open3.capture3($cmd_lista_1)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
if stdout.chomp.length > 4090
bot.api.send_message(chat_id: message.chat.id, text: "OK!\n#{stdout.chomp.slice(0,4090).scrub}")
bot.api.send_message(chat_id: message.chat.id, text: "#{stdout.chomp.slice(4090,stdout.chomp.length-4090).scrub}")
else
bot.api.send_message(chat_id: message.chat.id, text: "OK!\n#{stdout.chomp.scrub}")
end
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp.scrub}")
end
when '/lista_1_s'
puts "Ricevuto messaggio /lista_1_s \n"
$log.info("Eseguo comando #{$cmd_lista_1_s}")
errors = false
stdout,stderr,status = Open3.capture3($cmd_lista_1_s)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
if stdout.chomp.length > 4090
bot.api.send_message(chat_id: message.chat.id, text: "OK!\n#{stdout.chomp.slice(0,4090).scrub}")
bot.api.send_message(chat_id: message.chat.id, text: "#{stdout.chomp.slice(4090,stdout.chomp.length-4090).scrub}")
else
bot.api.send_message(chat_id: message.chat.id, text: "OK!\n#{stdout.chomp.scrub}")
end
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp.scrub}")
end
when '/lista_2'
puts "Ricevuto messaggio /lista_2 \n"
$log.info("Eseguo comando #{$cmd_lista_2}")
errors = false
stdout,stderr,status = Open3.capture3($cmd_lista_2)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
bot.api.send_message(chat_id: message.chat.id, text: "OK!\n#{stdout.chomp}")
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
end
when '/aggiungi_1'
puts "Ricevuto messaggio /aggiungi_1 \n"
$bol_aggiungi_1 = true
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nInviami il link ed2k da aggiungere!")
when '/aggiungi_2'
puts "Ricevuto messaggio /aggiungi_2 \n"
$bol_aggiungi_2 = true
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nInviami il link torrent o magnet da aggiungere!")
when '/finiti_1'
puts "Ricevuto messaggio /finiti_1 \n"
$log.info("Eseguo comando #{$cmd_finiti_1}")
errors = false
stdout,stderr,status = Open3.capture3($cmd_finiti_1)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
bot.api.send_message(chat_id: message.chat.id, text: "OK!\n#{stdout.chomp}")
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
end
when '/finiti_2'
puts "Ricevuto messaggio /finiti_2 \n"
$log.info("Eseguo comando #{$cmd_finiti_2}")
errors = false
stdout,stderr,status = Open3.capture3($cmd_finiti_2)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
bot.api.send_message(chat_id: message.chat.id, text: "OK!\n#{stdout.chomp}")
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
end
when '/stato_1'
puts "Ricevuto messaggio /stato_1 \n"
$log.info("Eseguo comando #{$cmd_stato_1}")
errors = false
stdout,stderr,status = Open3.capture3($cmd_stato_1)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
bot.api.send_message(chat_id: message.chat.id, text: "OK!\n#{stdout.chomp}")
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
end
when '/stato_2'
puts "Ricevuto messaggio /stato_2 \n"
$log.info("Eseguo comando #{$cmd_stato_2}")
errors = false
stdout,stderr,status = Open3.capture3($cmd_stato_2)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
bot.api.send_message(chat_id: message.chat.id, text: "OK!\n#{stdout.chomp}")
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
end
when '/muovi_1'
puts "Ricevuto messaggio /muovi_1 \n"
$log.info("Eseguo comando #{$cmd_muovilist_1}")
errors = false
stdout,stderr,status = Open3.capture3($cmd_muovilist_1)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
unless stdout == ""
messaggio = ""
array_e_choose = Array.new
array_e_choose = stdout.split(/\n/)
conta = 1
array_e_choose.each do |riga|
messaggio += "#{conta.to_s}) #{riga}\n"
conta += 1
end
$bol_muovi_1 = true
$conta_muovi_e = conta - 1
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nQuale file vuoi muovere?")
bot.api.send_message(chat_id: message.chat.id, text: "#{messaggio}")
else
bot.api.send_message(chat_id: message.chat.id, text: "Non ci sono file da muovere!")
end
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
end
when '/muovi_2'
puts "Ricevuto messaggio /muovi_2 \n"
$log.info("Eseguo comando #{$cmd_muovilist_2}")
errors = false
stdout,stderr,status = Open3.capture3($cmd_muovilist_2)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
unless stdout == ""
messaggio = ""
array_t_choose = Array.new
array_t_choose = stdout.split(/\n/)
conta = 1
array_t_choose.each do |riga|
messaggio += "#{conta.to_s}) #{riga}\n"
conta += 1
end
$bol_muovi_2 = true
$conta_muovi_t = conta - 1
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nQuale file vuoi muovere?")
bot.api.send_message(chat_id: message.chat.id, text: "#{messaggio}")
else
bot.api.send_message(chat_id: message.chat.id, text: "Non ci sono file da muovere!")
end
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
end
when '/salva_1'
puts "Ricevuto messaggio /salva_1 \n"
$log.info("Eseguo comando #{$cmd_salva_1}")
errors = false
stdout,stderr,status = Open3.capture3($cmd_ferma_e)
stdout,stderr,status = Open3.capture3($cmd_salva_1) if status.success?
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
bot.api.send_message(chat_id: message.chat.id, text: "OK!\n#{stdout.chomp}")
bot.api.send_message(chat_id: $notify, text: "Eseguito salvataggio temporaneo files video ed2k da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stdout.chomp}") if message.from.id != $notify
stdout,stderr,status = Open3.capture3($cmd_kodi_update_video)
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
bot.api.send_message(chat_id: $notify, text: "Errore in salvataggio temporaneo files video ed2k da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stderr.chomp}") if message.from.id != $notify
end
stdout,stderr,status = Open3.capture3($cmd_avvia_e)
when '/salva_2'
puts "Ricevuto messaggio /salva_2 \n"
$log.info("Eseguo comando #{$cmd_salva_2}")
errors = false
stdout,stderr,status = Open3.capture3($cmd_ferma_t)
stdout,stderr,status = Open3.capture3($cmd_salva_2) if status.success?
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
bot.api.send_message(chat_id: message.chat.id, text: "OK!\n#{stdout.chomp}")
bot.api.send_message(chat_id: $notify, text: "Eseguito salvataggio temporaneo files video torrent da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stdout.chomp}") if message.from.id != $notify
stdout,stderr,status = Open3.capture3($cmd_kodi_update_video)
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
bot.api.send_message(chat_id: $notify, text: "Errore in salvataggio temporaneo files video torrent da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stderr.chomp}") if message.from.id != $notify
end
stdout,stderr,status = Open3.capture3($cmd_avvia_t)
sleep 2
stdout,stderr,status = Open3.capture3($cmd_remove_t)
when '/kodi_msg'
puts "Ricevuto messaggio /kodi_msg \n"
$bol_kodi_msg = true
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nInviami il messaggio da visalizzare!")
bot.api.send_message(chat_id: message.chat.id, text: "Mandami prima il titolo del messaggio:")
when '/kodi_upd'
puts "Ricevuto messaggio /kodi_upd \n"
$log.info("Eseguo comando #{$cmd_kodi_update_video}")
errors = false
stdout,stderr,status = Open3.capture3($cmd_kodi_update_video)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
bot.api.send_message(chat_id: message.chat.id, text: "OK!\n#{stdout.chomp}")
bot.api.send_message(chat_id: $notify, text: "Eseguito reload libreria video kodi da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stdout.chomp}") if message.from.id != $notify
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
bot.api.send_message(chat_id: $notify, text: "Errore in reload libreria video kodi da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stderr.chomp}") if message.from.id != $notify
end
when '/salva_all_1'
puts "Ricevuto messaggio /salva_all_1 \n"
$log.info("Eseguo comando #{$cmd_salva_all_1}")
errors = false
stdout,stderr,status = Open3.capture3($cmd_ferma_e)
stdout,stderr,status = Open3.capture3($cmd_salva_all_1) if status.success?
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
bot.api.send_message(chat_id: message.chat.id, text: "OK!\n#{stdout.chomp}")
bot.api.send_message(chat_id: $notify, text: "Eseguito salvataggio temporaneo files generici ed2k da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stdout.chomp}") if message.from.id != $notify
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
bot.api.send_message(chat_id: $notify, text: "Errore in salvataggio temporaneo files generici ed2k da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stderr.chomp}") if message.from.id != $notify
end
stdout,stderr,status = Open3.capture3($cmd_avvia_e)
when '/salva_all_2'
puts "Ricevuto messaggio /salva_all_2 \n"
$log.info("Eseguo comando #{$cmd_salva_all_2}")
errors = false
stdout,stderr,status = Open3.capture3($cmd_ferma_t)
stdout,stderr,status = Open3.capture3($cmd_salva_all_2) if status.success?
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
bot.api.send_message(chat_id: message.chat.id, text: "OK!\n#{stdout.chomp}")
bot.api.send_message(chat_id: $notify, text: "Eseguito salvataggio temporaneo files generici torrent da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stdout.chomp}") if message.from.id != $notify
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
bot.api.send_message(chat_id: $notify, text: "Errore in salvataggio temporaneo files generici torrent da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stderr.chomp}") if message.from.id != $notify
end
stdout,stderr,status = Open3.capture3($cmd_avvia_t)
sleep 2
stdout,stderr,status = Open3.capture3($cmd_remove_t)
when '/rimuovi_1'
puts "Ricevuto messaggio /rimuovi_1 \n"
$log.info("Eseguo comando #{$cmd_e_choose_1}")
errors = false
stdout,stderr,status = Open3.capture3($cmd_e_choose_1)
errors = true if !stderr.empty?
if errors == false
unless stdout == ""
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
messaggio = ""
array_e_choose = Array.new
array_e_choose = stdout.split(/\n/)
conta = 1
array_e_choose.each do |riga|
messaggio += "#{conta.to_s}) #{riga}\n"
conta += 1
end
$bol_rimuovi_1 = true
$conta_down_e = conta - 1
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nQuale download vuoi eliminare?")
bot.api.send_message(chat_id: message.chat.id, text: "#{messaggio}")
else
bot.api.send_message(chat_id: message.chat.id, text: "Non ci sono download da eliminare!")
end
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
end
when '/rimuovi_2'
puts "Ricevuto messaggio /rimuovi_2 \n"
$log.info("Eseguo comando #{$cmd_t_choose_1}")
errors = false
stdout,stderr,status = Open3.capture3($cmd_t_choose_1)
errors = true if !stderr.empty?
if errors == false
unless stdout == ""
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
messaggio = ""
array_t_choose = Array.new
array_t_choose = stdout.split(/\n/)
conta = 1
array_t_choose.each do |riga|
messaggio += "#{conta.to_s}) #{riga}\n"
conta += 1
end
$bol_rimuovi_2 = true
$conta_down_t = conta - 1
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nQuale download vuoi eliminare?")
bot.api.send_message(chat_id: message.chat.id, text: "#{messaggio}")
else
bot.api.send_message(chat_id: message.chat.id, text: "Non ci sono download da eliminare!")
end
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
end
when '/temperatura_e_umidita'
puts "Ricevuto messaggio /temperatura_e_umidita \n"
$log.info("Eseguo comando #{$cmd_read_hum_temp_sensor}")
errors = false
stdout,stderr,status = Open3.capture3($cmd_read_hum_temp_sensor)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nRisultato:\n#{stdout.chomp}")
bot.api.send_message(chat_id: $notify, text: "Eseguita lettura di temperatura e umidita da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stdout.chomp}") if message.from.id != $notify
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
bot.api.send_message(chat_id: $notify, text: "Errore in lettura di temperatura e umidita da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stderr.chomp}") if message.from.id != $notify
end
when '/bandwidth'
puts "Ricevuto messaggio /bandwidth \n"
$log.info("Eseguo comando #{$cisco_bandwidth_cmd}")
errors = false
stdout,stderr,status = Open3.capture3($cisco_bandwidth_cmd)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
bot.api.send_message(chat_id: message.chat.id, text: "OK!")
bot.api.send_photo(chat_id: message.chat.id, photo: Faraday::UploadIO.new('/home/kodi/.kodi/dev/ruby/telegram_bot/graphs/cisco.png', 'image/png'))
bot.api.send_message(chat_id: $notify, text: "Eseguito controllo bandwidth usage da #{message.from.id} - #{message.from.first_name}") if message.from.id != $notify
bot.api.send_photo(chat_id: $notify, photo: Faraday::UploadIO.new('/home/kodi/.kodi/dev/ruby/telegram_bot/graphs/cisco.png', 'image/png')) if message.from.id != $notify
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
bot.api.send_message(chat_id: $notify, text: "Errore in controllo bandwidth usage da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stderr.chomp}") if message.from.id != $notify
end
when '/poke_start'
puts "Ricevuto messaggio /poke_start \n"
$log.info("Eseguo comando #{$pokebot_utenti}")
errors = false
stdout,stderr,status = Open3.capture3($pokebot_utenti)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
messaggio = ""
array_p_choose = Array.new
array_p_choose = stdout.split(/\n/)
conta = 1
array_p_choose.each do |riga|
messaggio += "#{conta.to_s}) #{riga}\n"
conta += 1
end
$bol_avvia_pokebot = true
$conta_utenti_pokebot = conta - 1
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nQuale utente vuoi avviare?")
bot.api.send_message(chat_id: message.chat.id, text: "#{messaggio}")
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
bot.api.send_message(chat_id: message.chat.id, text: "Comando /poke_start completato!")
end
when '/poke_stop'
puts "Ricevuto messaggio /poke_stop \n"
$log.info("Eseguo comando #{$pokebot_checkrun}")
errors = false
stdout,stderr,status = Open3.capture3($pokebot_checkrun)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
if stdout.chomp == ""
bot.api.send_message(chat_id: message.chat.id, text: "Nessun PokeBot avviato!")
bot.api.send_message(chat_id: message.chat.id, text: "Comando /poke_stop completato!")
else
$log.info("Eseguo comando #{$pokebot_checkrun2}")
errors = false
stdout,stderr,status = Open3.capture3($pokebot_checkrun2)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
messaggio = ""
array_p_choose = Array.new
array_p_choose = stdout.split(/\n/)
conta = 1
array_p_choose.each do |riga|
messaggio += "#{conta.to_s}) #{riga}\n"
conta += 1
end
$bol_ferma_pokebot = true
$conta_ferma_pokebot = conta - 1
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nQuale PokeBot vuoi fermare?")
bot.api.send_message(chat_id: message.chat.id, text: "#{messaggio}")
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
bot.api.send_message(chat_id: message.chat.id, text: "Comando /poke_stop completato!")
end
end
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
bot.api.send_message(chat_id: message.chat.id, text: "Comando /poke_stop completato!")
end
when '/poke_status'
puts "Ricevuto messaggio /poke_status \n"
$log.info("Eseguo comando #{$pokebot_checkrun}")
errors = false
stdout,stderr,status = Open3.capture3($pokebot_checkrun)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
if stdout.chomp == ""
bot.api.send_message(chat_id: message.chat.id, text: "Nessun PokeBot avviato!")
else
$log.info("Eseguo comando #{$pokebot_checkrun2}")
errors = false
stdout,stderr,status = Open3.capture3($pokebot_checkrun2)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
messaggio = ""
array_p_choose = Array.new
array_p_choose = stdout.chomp.split(/\n/)
conta = 1
array_p_choose.each do |riga|
messaggio += "#{conta.to_s}) #{riga}\n"
conta += 1
end
bot.api.send_message(chat_id: message.chat.id, text: "PokeBot avviati:")
bot.api.send_message(chat_id: message.chat.id, text: "#{messaggio}")
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
end
end
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
end
bot.api.send_message(chat_id: message.chat.id, text: "Comando /poke_status completato!")
when '/poke_log'
puts "Ricevuto messaggio /poke_log \n"
$log.info("Eseguo comando #{$pokebot_logcheck}")
errors = false
stdout,stderr,status = Open3.capture3($pokebot_logcheck)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
if stdout == ""
bot.api.send_message(chat_id: message.chat.id, text: "Nessun Log di PokeBot presente!")
bot.api.send_message(chat_id: message.chat.id, text: "Comando /poke_log completato!")
else
messaggio = ""
array_p_choose = Array.new
array_p_choose = stdout.split(/\n/)
conta = 1
array_p_choose.each do |riga|
messaggio += "#{conta.to_s}) #{riga}\n"
conta += 1
end
$bol_log_pokebot = true
$conta_log_pokebot = conta - 1
bot.api.send_message(chat_id: message.chat.id, text: "Quale log di PokeBot vuoi consultare?")
bot.api.send_message(chat_id: message.chat.id, text: "#{messaggio}")
end
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
bot.api.send_message(chat_id: message.chat.id, text: "Comando /poke_log completato!")
end
when '/poke_nomi'
puts "Ricevuto messaggio /poke_nomi \n"
$log.info("Eseguo comando #{$pokebot_pokemon_inventari}")
errors = false
stdout,stderr,status = Open3.capture3($pokebot_pokemon_inventari)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
messaggio = ""
array_p_choose = Array.new
array_p_choose = stdout.split(/\n/)
conta = 1
array_p_choose.each do |riga|
messaggio += "#{conta.to_s}) #{riga}\n"
conta += 1
end
$bol_nomi_pokebot = true
$conta_nomi_pokebot = conta - 1
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nQuale utente vuoi consultare?")
bot.api.send_message(chat_id: message.chat.id, text: "#{messaggio}")
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
bot.api.send_message(chat_id: message.chat.id, text: "Comando /poke_nomi completato!")
end
when '/poke_conta'
puts "Ricevuto messaggio /poke_conta \n"
$log.info("Eseguo comando #{$pokebot_pokemon_inventari}")
errors = false
stdout,stderr,status = Open3.capture3($pokebot_pokemon_inventari)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
messaggio = ""
array_p_choose = Array.new
array_p_choose = stdout.split(/\n/)
conta = 1
array_p_choose.each do |riga|
messaggio += "#{conta.to_s}) #{riga}\n"
conta += 1
end
$bol_conta_pokebot = true
$conta_conta_pokebot = conta - 1
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nQuale utente vuoi consultare?")
bot.api.send_message(chat_id: message.chat.id, text: "#{messaggio}")
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
bot.api.send_message(chat_id: message.chat.id, text: "Comando /poke_conta completato!")
end
when '/pokemap_start'
puts "Ricevuto messaggio /pokemap_start \n"
$log.info("Eseguo comando #{$pokemap_checkrun}")
errors = false
stdout,stderr,status = Open3.capture3($pokemap_checkrun)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
if stdout.chomp == ""
$log.info("Eseguo comando #{$pokebot_citta}")
errors = false
stdout,stderr,status = Open3.capture3($pokebot_citta)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
messaggio = ""
array_p_choose = Array.new
array_p_choose = stdout.split(/\n/)
conta = 1
array_p_choose.each do |riga|
messaggio += "#{conta.to_s}) #{riga}\n"
conta += 1
end
$bol_avvia_pokemap = true
$conta_citta_pokemap = conta - 1
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nQuale mappa della città vuoi avviare?")
bot.api.send_message(chat_id: message.chat.id, text: "#{messaggio}")
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
bot.api.send_message(chat_id: message.chat.id, text: "Comando /pokemap_start completato!")
end
else
$log.info("Eseguo comando #{$pokemap_getcoord}")
stdout,stderr,status = Open3.capture3($pokemap_getcoord)
coordinate = stdout.chomp
citta = Dir.entries("/opt/PokemonGo-Bot/configs/citta").select {|f| next if File.directory?(f); !File.foreach("/opt/PokemonGo-Bot/configs/citta/#{f}").grep(/#{coordinate}/).empty?}[0]
bot.api.send_message(chat_id: message.chat.id, text: "PokeMap già avviata nella città: #{citta.chomp}!")
bot.api.send_message(chat_id: message.chat.id, text: "Comando /pokemap_start completato!")
end
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
bot.api.send_message(chat_id: message.chat.id, text: "Comando /pokemap_start completato!")
end
when '/pokemap_stop'
puts "Ricevuto messaggio /pokemap_stop \n"
$log.info("Eseguo comando #{$pokemap_checkrun}")
errors = false
stdout,stderr,status = Open3.capture3($pokemap_checkrun)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
if stdout.chomp == ""
bot.api.send_message(chat_id: message.chat.id, text: "Nessuna PokeMap avviata!")
bot.api.send_message(chat_id: message.chat.id, text: "Comando /pokemap_stop completato!")
else
$log.info("Eseguo comando #{$pokemap_getcoord}")
stdout,stderr,status = Open3.capture3($pokemap_getcoord)
coordinate = stdout.chomp
citta = Dir.entries("/opt/PokemonGo-Bot/configs/citta").select {|f| next if File.directory?(f); !File.foreach("/opt/PokemonGo-Bot/configs/citta/#{f}").grep(/#{coordinate}/).empty?}[0]
$log.info("Eseguo comando #{$pokemap_stop}")
errors = false
stdout,stderr,status = Open3.capture3($pokemap_stop)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
if stdout.empty?
$log.info("Eseguo comando #{$pokemap_stop_coord}")
errors = false
stdout,stderr,status = Open3.capture3($pokemap_stop_coord)
errors = true if !stderr.empty?
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
end
processo = stdout.chomp
stdout,stderr,status = Open3.capture3($pokemap_stop1.gsub("<process>",processo))
stdout,stderr,status = Open3.capture3($pokemap_stop2.gsub("<process>",processo))
unless citta.nil?
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nPokeMap città #{citta} stoppata!")
bot.api.send_message(chat_id: $notify, text: "PokeMap città #{citta} stoppata da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stderr.chomp}") if message.from.id != $notify
else
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nPokeMap coordinate #{coordinate} stoppata!")
bot.api.send_message(chat_id: $notify, text: "PokeMap coordinate #{coordinate} stoppata da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stderr.chomp}") if message.from.id != $notify
end
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
end
end
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
end
bot.api.send_message(chat_id: message.chat.id, text: "Comando /pokemap_stop completato!")
when '/pokemap_status'
puts "Ricevuto messaggio /pokemap_status \n"
$log.info("Eseguo comando #{$pokemap_checkrun}")
errors = false
stdout,stderr,status = Open3.capture3($pokemap_checkrun)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
if stdout.chomp == ""
bot.api.send_message(chat_id: message.chat.id, text: "Nessuna PokeMap avviata!")
else
$log.info("Eseguo comando #{$pokemap_getcoord}")
stdout,stderr,status = Open3.capture3($pokemap_getcoord)
coordinate = stdout.chomp
citta = Dir.entries("/opt/PokemonGo-Bot/configs/citta").select {|f| next if File.directory?(f); !File.foreach("/opt/PokemonGo-Bot/configs/citta/#{f}").grep(/#{coordinate}/).empty?}[0]
unless citta.nil?
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nPokeMap città #{citta} attiva!")
bot.api.send_message(chat_id: message.chat.id, text: "Mappa visibile su: https://pegasus78.ddns.net/map/")
else
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nPokeMap coordinate #{coordinate} attiva!")
bot.api.send_message(chat_id: message.chat.id, text: "Mappa visibile su: https://pegasus78.ddns.net/map/")
end
end
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
end
bot.api.send_message(chat_id: message.chat.id, text: "Comando /pokemap_status completato!")
when '/pokemap_show'
puts "Ricevuto messaggio /pokemap_show \n"
$log.info("Eseguo comando #{$pokemap_checkrun}")
errors = false
stdout,stderr,status = Open3.capture3($pokemap_checkrun)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
if stdout.chomp == ""
$bol_mostra_mappa = true
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nMandami le coordinate di cui vuoi visualizzare la mappa! (Esempio: 43.7126865,10.9467945)")
else
$log.info("Eseguo comando #{$pokemap_getcoord}")
stdout,stderr,status = Open3.capture3($pokemap_getcoord)
coordinate = stdout.chomp
citta = Dir.entries("/opt/PokemonGo-Bot/configs/citta").select {|f| next if File.directory?(f); !File.foreach("/opt/PokemonGo-Bot/configs/citta/#{f}").grep(/#{coordinate}/).empty?}[0]
unless citta.nil?
bot.api.send_message(chat_id: message.chat.id, text: "Non posso visualizzare una mappa custom perché la PokeMap è già avviata nella città: #{citta.chomp}!")
else
bot.api.send_message(chat_id: message.chat.id, text: "Non posso visualizzare una mappa custom perché la PokeMap è già avviata alle coordinate: #{coordinate}!")
end
bot.api.send_message(chat_id: message.chat.id, text: "Mappa visibile su: https://pegasus78.ddns.net/map/")
#bot.api.send_message(chat_id: message.chat.id, text: "Vuoi visualizzare la mappa di questa città alle coordinate attuali #{coordinate}? (S/N)")
#$bol_mostra_mappa_attiva = true
end
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
bot.api.send_message(chat_id: message.chat.id, text: "Comando /pokemap_show completato!")
end
when '/poke_start_path'
puts "Ricevuto messaggio /poke_start_path \n"
$log.info("Eseguo comando #{$pokebot_utenti}")
errors = false
stdout,stderr,status = Open3.capture3($pokebot_utenti)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
messaggio = ""
array_p_choose = Array.new
array_p_choose = stdout.split(/\n/)
conta = 1
array_p_choose.each do |riga|
messaggio += "#{conta.to_s}) #{riga}\n"
conta += 1
end
$bol_avvia_pokebot_path = true
$conta_utenti_pokebot = conta - 1
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nQuale utente vuoi avviare?")
bot.api.send_message(chat_id: message.chat.id, text: "#{messaggio}")
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
bot.api.send_message(chat_id: message.chat.id, text: "Comando /poke_start_path completato!")
end
when '/aggiungi_1_multi'
puts "Ricevuto messaggio /aggiungi_1_multi \n"
$bol_aggiungi_1_multi = true
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nInviami il link dropbox del sorgente html da parsare!")
else
if $bol_aggiungi_1
if (message.text =~ URI::regexp("ed2k"))
puts "Ricevuto ed2k link da aggiungere! \n"
$log.info("Eseguo comando #{$cmd_aggiungi_1}")
errors = false
stdout,stderr,status = Open3.capture3($cmd_aggiungi_1.gsub("<ed2klink>",message.text))
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
bot.api.send_message(chat_id: message.chat.id, text: "OK!\n#{stdout.chomp}")
bot.api.send_message(chat_id: $notify, text: "Aggiunto file ed2k #{message.text} da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stdout.chomp}") if message.from.id != $notify
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
bot.api.send_message(chat_id: $notify, text: "Errore in aggiunta file ed2k #{message.text} da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stderr.chomp}") if message.from.id != $notify
end
else
puts "Ricevuto ed2k link in formato errato! \n"
puts "URL ricevuto: #{message.text}"
bot.api.send_message(chat_id: message.chat.id, text: "ed2k link errato!")
end
$bol_aggiungi_1 = false
bot.api.send_message(chat_id: message.chat.id, text: "Comando /aggiungi_1 completato!")
elsif $bol_aggiungi_2
if ((message.text =~ URI::regexp("magnet")) or ((message.text =~ URI::regexp(["http", "https"])) and (message.text.end_with?(".torrent"))))
puts "Ricevuto magnet o torrent link da aggiungere! \n"
$log.info("Eseguo comando #{$cmd_aggiungi_2}")
errors = false
stdout,stderr,status = Open3.capture3($cmd_aggiungi_2.gsub("<torrent>",message.text))
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
bot.api.send_message(chat_id: message.chat.id, text: "OK!\n#{stdout.chomp}")
bot.api.send_message(chat_id: $notify, text: "Aggiunto file magnet o torrent #{message.text} da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stdout.chomp}") if message.from.id != $notify
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
bot.api.send_message(chat_id: $notify, text: "Errore in aggiunta file magnet o torrent #{message.text} da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stderr.chomp}") if message.from.id != $notify
end
else
puts "Ricevuto magnet o torrent link in formato errato! \n"
puts "URL ricevuto: #{message.text}"
bot.api.send_message(chat_id: message.chat.id, text: "magnet o torrent link errato!")
end
$bol_aggiungi_2 = false
bot.api.send_message(chat_id: message.chat.id, text: "Comando /aggiungi_2 completato!")
elsif $bol_kodi_msg
unless $bol_kodi_msg_t
if message.text.length > 30
messaggio = message.text[0, 30]
else
messaggio = message.text
end
$kodi_msg_t = messaggio
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nOra mandami il testo del messaggio:")
$bol_kodi_msg_t = true
else
if message.text.length > 100
messaggio = message.text[0, 100]
else
messaggio = message.text
end
puts "Visualizzo messaggio a video su Kodi: titolo: #{$kodi_msg_t}, messaggio: #{messaggio} \n"
$log.info("Eseguo comando #{$cmd_kodi_notifica}")
errors = false
stdout,stderr,status = Open3.capture3($cmd_kodi_notifica.gsub("<titolo>",$kodi_msg_t).gsub("<messaggio>",messaggio))
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
bot.api.send_message(chat_id: message.chat.id, text: "OK!\n#{stdout.chomp}")
bot.api.send_message(chat_id: $notify, text: "Eseguito invio messaggio a video su Kodi da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stdout.chomp}") if message.from.id != $notify
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
bot.api.send_message(chat_id: $notify, text: "Errore in invio messaggio a video su Kodi da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stderr.chomp}") if message.from.id != $notify
end
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nMessaggio visualizzato!")
$bol_kodi_msg_t = false
$bol_kodi_msg = false
end
elsif $bol_rimuovi_1
if message.text.to_i > 0 and message.text.to_i <= $conta_down_e
puts "Cancello il download numero #{message.text} da aMule \n"
$log.info("Eseguo comando #{$cmd_e_choose_2}")
errors = false
stdout,stderr,status = Open3.capture3($cmd_e_choose_2)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
array_e_choose = Array.new
array_e_choose = stdout.split(/\n/)
elimina = array_e_choose[message.text.to_i-1]
$log.info("Eseguo comando #{$cmd_remove_e.gsub("<hash>",elimina)}")
stdout,stderr,status = Open3.capture3($cmd_remove_e.gsub("<hash>",elimina))
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nEliminato il download numero #{message.text}!")
bot.api.send_message(chat_id: $notify, text: "Eseguita cancellazione del download numero #{message.text} da aMule da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stdout.chomp}") if message.from.id != $notify
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
bot.api.send_message(chat_id: $notify, text: "Errore in cancellazione del download numero #{message.text} da aMule da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stderr.chomp}") if message.from.id != $notify
end
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
bot.api.send_message(chat_id: $notify, text: "Errore in selezione hash download numero #{message.text} da cancellare su aMule da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stderr.chomp}") if message.from.id != $notify
end
else
puts "Numero errato download da cancellare su aMule: #{message.text} \n"
$log.info("Numero errato download da cancellare su aMule: #{message.text}")
bot.api.send_message(chat_id: message.chat.id, text: "Numero download errato! Deve essere un numero compreso fra 1 e #{$conta_down_e}!")
end
$bol_rimuovi_1 = false
$conta_down_e = 0
bot.api.send_message(chat_id: message.chat.id, text: "Comando /rimuovi_1 completato!")
elsif $bol_rimuovi_2
if message.text.to_i > 0 and message.text.to_i <= $conta_down_t
puts "Cancello il download numero #{message.text} da Transmission \n"
$log.info("Eseguo comando #{$cmd_remove_t_x.gsub("<number>",message.text)}")
errors = false
stdout,stderr,status = Open3.capture3($cmd_remove_t_x.gsub("<number>",message.text))
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nEliminato il download numero #{message.text}!")
bot.api.send_message(chat_id: $notify, text: "Eseguita cancellazione del download numero #{message.text} da Transmission da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stdout.chomp}") if message.from.id != $notify
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
bot.api.send_message(chat_id: $notify, text: "Errore in cancellazione del download numero #{message.text} da Transmission da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stderr.chomp}") if message.from.id != $notify
end
else
puts "Numero errato download da cancellare su Transmission: #{message.text} \n"
$log.info("Numero errato download da cancellare su Transmission: #{message.text}")
bot.api.send_message(chat_id: message.chat.id, text: "Numero download errato! Deve essere un numero compreso fra 1 e #{$conta_down_t}!")
end
$bol_rimuovi_2 = false
$conta_down_t = 0
bot.api.send_message(chat_id: message.chat.id, text: "Comando /rimuovi_2 completato!")
elsif $bol_muovi_1
unless $bol_muovi_1_step2 # step 1
if message.text.to_i > 0 and message.text.to_i <= $conta_muovi_e
puts "Ricevuto file da muovere numero #{message.text} da aMule \n"
puts "Chiedo in quale cartella muoverlo \n"
messaggio = ""
conta = 1
$array_kodi_folder.each do |riga|
messaggio += "#{conta.to_s}) #{riga}\n"
conta += 1
end
$bol_muovi_1_step2 = true
$file_da_muovere = message.text
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nIn quale cartella vuoi muovere il file?")
bot.api.send_message(chat_id: message.chat.id, text: "#{messaggio}")
else
puts "Numero errato file da muovere da aMule: #{message.text} \n"
$log.info("Numero errato file da muovere da aMule: #{message.text}")
bot.api.send_message(chat_id: message.chat.id, text: "Numero file errato! Deve essere un numero compreso fra 1 e #{$conta_muovi_e}!")
$bol_muovi_1 = false
$conta_muovi_e = 0
bot.api.send_message(chat_id: message.chat.id, text: "Comando /muovi_1 completato!")
end
else # step 2
if message.text.to_i > 0 and message.text.to_i <= $array_kodi_folder.count
puts "Muovo il file numero #{$file_da_muovere} da aMule nella cartella numero #{message.text} di Kodi \n"
errors = false
stdout,stderr,status = Open3.capture3($cmd_muovilist_1)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
array_e_choose = Array.new
array_e_choose = stdout.split(/\n/)
muovi = array_e_choose[$file_da_muovere.to_i-1]
folder = $array_kodi_folder[message.text.to_i-1]
$log.info("Eseguo comando #{$cmd_muovi_1.gsub("<filename>",muovi.dump).gsub("<folder>",folder)}")
stdout,stderr,status = Open3.capture3($cmd_ferma_e)
stdout,stderr,status = Open3.capture3($cmd_muovi_1.gsub("<filename>",muovi).gsub("<folder>",folder)) if status.success?
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nSpostato il file #{muovi} nella cartella #{folder}!")
bot.api.send_message(chat_id: $notify, text: "Eseguito spostamento del file #{muovi} da aMule nella cartella #{folder} da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stdout.chomp}") if message.from.id != $notify
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
bot.api.send_message(chat_id: $notify, text: "Errore in spostamento del file #{muovi} da aMule nella cartella #{folder} da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stderr.chomp}") if message.from.id != $notify
end
stdout,stderr,status = Open3.capture3($cmd_avvia_e)
$bol_muovi_1 = false
$bol_muovi_1_step2 = false
$conta_muovi_e = 0
$file_da_muovere = nil
bot.api.send_message(chat_id: message.chat.id, text: "Comando /muovi_1 completato!")
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
end
else
puts "Numero errato cartella in cui muovere il file da aMule: #{message.text} \n"
$log.info("Numero errato cartella in cui muovere il file da aMule: #{message.text}")
bot.api.send_message(chat_id: message.chat.id, text: "Numero cartella errato! Deve essere un numero compreso fra 1 e #{$array_kodi_folder.count.to_s}!")
$bol_muovi_1 = false
$bol_muovi_1_step2 = false
$conta_muovi_e = 0
$file_da_muovere = nil
bot.api.send_message(chat_id: message.chat.id, text: "Comando /muovi_1 completato!")
end
end
elsif $bol_muovi_2
unless $bol_muovi_2_step2 # step 1
if message.text.to_i > 0 and message.text.to_i <= $conta_muovi_t
puts "Ricevuto file da muovere numero #{message.text} da Transmission \n"
puts "Chiedo in quale cartella muoverlo \n"
messaggio = ""
conta = 1
$array_kodi_folder.each do |riga|
messaggio += "#{conta.to_s}) #{riga}\n"
conta += 1
end
$bol_muovi_2_step2 = true
$file_da_muovere = message.text
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nIn quale cartella vuoi muovere il file?")
bot.api.send_message(chat_id: message.chat.id, text: "#{messaggio}")
else
puts "Numero errato file da muovere da Transmission: #{message.text} \n"
$log.info("Numero errato file da muovere da Transmission: #{message.text}")
bot.api.send_message(chat_id: message.chat.id, text: "Numero file errato! Deve essere un numero compreso fra 1 e #{$conta_muovi_t}!")
$bol_muovi_2 = false
$conta_muovi_t = 0
bot.api.send_message(chat_id: message.chat.id, text: "Comando /muovi_2 completato!")
end
else # step 2
if message.text.to_i > 0 and message.text.to_i <= $array_kodi_folder.count
puts "Muovo il file numero #{$file_da_muovere} da Transmission nella cartella numero #{message.text} di Kodi \n"
errors = false
stdout,stderr,status = Open3.capture3($cmd_muovilist_2)
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
array_t_choose = Array.new
array_t_choose = stdout.split(/\n/)
muovi = array_t_choose[$file_da_muovere.to_i-1]
folder = $array_kodi_folder[message.text.to_i-1]
$log.info("Eseguo comando #{$cmd_muovi_2.gsub("<filename>",muovi).gsub("<folder>",folder)}")
stdout,stderr,status = Open3.capture3($cmd_ferma_t)
stdout,stderr,status = Open3.capture3($cmd_muovi_2.gsub("<filename>",muovi).gsub("<folder>",folder)) if status.success?
errors = true if !stderr.empty?
if errors == false
$log.info("Output: #{stdout.chomp}") if !stdout.empty?
bot.api.send_message(chat_id: message.chat.id, text: "OK!\nSpostato il file #{muovi} nella cartella #{folder}!")
bot.api.send_message(chat_id: $notify, text: "Eseguito spostamento del file #{muovi} da Transmission nella cartella #{folder} da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stdout.chomp}") if message.from.id != $notify
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
bot.api.send_message(chat_id: $notify, text: "Errore in spostamento del file #{muovi} da Transmission nella cartella #{folder} da #{message.from.id} - #{message.from.first_name}, risultato: \n#{stderr.chomp}") if message.from.id != $notify
end
stdout,stderr,status = Open3.capture3($cmd_avvia_t)
$bol_muovi_2 = false
$bol_muovi_2_step2 = false
$conta_muovi_t = 0
$file_da_muovere = nil
bot.api.send_message(chat_id: message.chat.id, text: "Comando /muovi_2 completato!")
else
$log.error(stderr.chomp) if !stderr.empty?
bot.api.send_message(chat_id: message.chat.id, text: "Errore!\n#{stderr.chomp}")
end
else
puts "Numero errato cartella in cui muovere il file da Transmission: #{message.text} \n"
$log.info("Numero errato cartella in cui muovere il file da Transmission: #{message.text}")