-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbot.php
More file actions
5273 lines (4200 loc) · 181 KB
/
bot.php
File metadata and controls
5273 lines (4200 loc) · 181 KB
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
<?php
declare(strict_types=1);
/**
* Copyright WizardLoop (C)
* This file is Written by wizardloop!
* @author wizardloop
* @copyright wizardloop
* @license https://opensource.org/license/mit MIT License
* @link wizardloop => https://wizardloop.t.me
*/
$autoload = __DIR__.'/vendor/autoload.php';
if (!file_exists($autoload)) {
die("Autoload file not found. Please run 'composer install'.");
}
require_once $autoload;
use danog\MadelineProto\Broadcast\Filter;
use danog\MadelineProto\Broadcast\Progress;
use danog\MadelineProto\Broadcast\Status;
use danog\MadelineProto\EventHandler\Attributes\Cron;
use danog\MadelineProto\EventHandler\Attributes\Handler;
use danog\MadelineProto\EventHandler\Filter\FilterCommandCaseInsensitive;
use danog\MadelineProto\EventHandler\Message;
use danog\MadelineProto\EventHandler\Message\ChannelMessage;
use danog\MadelineProto\EventHandler\Message\PrivateMessage;
use danog\MadelineProto\EventHandler\Message\GroupMessage;
use danog\MadelineProto\EventHandler\SimpleFilter\FromAdmin;
use danog\MadelineProto\EventHandler\SimpleFilter\Incoming;
use danog\MadelineProto\ParseMode;
use danog\MadelineProto\Settings;
use danog\MadelineProto\SimpleEventHandler;
use danog\MadelineProto\BotApiFileId;
use danog\MadelineProto\EventHandler\CallbackQuery;
use danog\MadelineProto\EventHandler\Filter\FilterButtonQueryData;
use danog\MadelineProto\EventHandler\Filter\Combinator\FiltersOr;
use danog\MadelineProto\EventHandler\Filter\FilterIncoming;
use danog\MadelineProto\EventHandler\Update;
use Amp\File;
use Amp\Http\Client\HttpClientBuilder;
use Amp\Http\Client\Request;
use BroadcastTool\BroadcastManager;
class Shabbat extends SimpleEventHandler
{
/*
* טקסטים כניסה / יציאת שבת
*/
public const CLOSER = "הקבוצה שלנו שומרת שבת ותהיה סגורה עד צאת השבת 🕯\n🇮🇱 שבת שלום לכולם 🇮🇱";
public const OPENER = "🇮🇱 שבוע טוב לכולם! 🇮🇱\nהקבוצה פתוחה לכתיבת הודעות.";
/*
* זמני שבת
*/
private function getZmanimForCities(): string {
$geonameIds = [
'ירושלים' => 281184,
'חיפה' => 294801,
'תל אביב' => 293397,
'באר שבע' => 295530,
];
$zmanim = "⌚️ <u><b>זמני כניסת ויציאת השבת:</b></u>\n\n";
$candleTimes = [];
$havdalahTimes = [];
$holidays = [];
$date = '';
$parashaText = '';
$mevarchimText = '';
$mevarchimMemo = '';
$client = HttpClientBuilder::buildDefault();
foreach ($geonameIds as $location => $geonameId) {
$url = "https://www.hebcal.com/shabbat?cfg=json&geonameid=$geonameId&ue=off&b=18&M=on&lg=he-x-NoNikud&tgt=_top";
$response = $client->request(new Request($url));
$body = $response->getBody()->buffer();
$json = json_decode($body, true);
if (!$json || !isset($json['items'])) {
$zmanim .= "⚠️ לא ניתן היה לשלוף את זמני השבת עבור: $location\n";
continue;
}
$candles = null;
$havdalah = null;
foreach ($json['items'] as $item) {
switch ($item['category']) {
case 'candles':
$holidayName = $item['memo'] ?? null;
if ($holidayName && isset($holidays[$holidayName])) {
$holidays[$holidayName]['candles'][$location] = (new \DateTime($item['date']))->format('H:i');
} else {
$candles = $item; // שבת
}
break;
case 'havdalah':
$holidayName = $item['memo'] ?? null;
if ($holidayName && isset($holidays[$holidayName])) {
$holidays[$holidayName]['havdalah'][$location] = (new \DateTime($item['date']))->format('H:i');
} else {
$havdalah = $item; // שבת
}
break;
case 'parashat':
$parashaText = $item['hebrew'];
break;
case 'holiday':
if ($location === 'ירושלים') {
$hDate = substr($item['date'],0,10);
$hTitle = $item['hebrew'];
$holidays[$hTitle]['date'] = $hDate;
}
break;
case 'mevarchim':
if ($location === 'ירושלים') {
$mevarchimText = $item['hebrew'];
$mevarchimMemo = $item['memo'] ?? '';
}
break;
}
}
$candleTimes[$location] = isset($candles['date']) ? (new \DateTime($candles['date']))->format('H:i') : 'לא ידוע';
$havdalahTimes[$location] = isset($havdalah['date']) ? (new \DateTime($havdalah['date']))->format('H:i') : 'לא ידוע';
if (empty($date) && isset($havdalah['date'])) {
$date = (new \DateTime($havdalah['date']))->format('d/m/Y');
}
}
$zmanim .= "🗓 <u>תאריך:</u> $date\n";
if ($parashaText) {
$zmanim .= "📖 <u>פרשת השבוע:</u> $parashaText\n";
}
if ($mevarchimText) {
$memo = $mevarchimMemo ? " ($mevarchimMemo)" : '';
$zmanim .= "🌒 <u>מברכים:</u> $mevarchimText$memo\n";
}
$zmanim .= "\n🕯 <u>כניסת שבת:</u>\n";
foreach ($candleTimes as $loc => $time) {
$zmanim .= "$loc: <code>$time</code>\n";
}
$zmanim .= "\n🍷 <u>יציאת שבת:</u>\n";
foreach ($havdalahTimes as $loc => $time) {
$zmanim .= "$loc: <code>$time</code>\n";
}
if ($holidays) {
uasort($holidays, fn($a,$b) => strtotime($a['date'] ?? '') <=> strtotime($b['date'] ?? ''));
$zmanim .= "\n🎉 <u>חגים קרובים:</u>\n";
foreach ($holidays as $title => $info) {
$hDateFormatted = isset($info['date']) ? (new \DateTime($info['date']))->format('d/m/Y') : '---';
$zmanim .= "• $title ($hDateFormatted)\n";
if (!empty($info['candles'])) {
$zmanim .= " 🕯 כניסה:\n";
foreach ($info['candles'] as $loc => $time) {
$zmanim .= " $loc: <code>$time</code>\n";
}
}
if (!empty($info['havdalah'])) {
$zmanim .= " 🍷 יציאה:\n";
foreach ($info['havdalah'] as $loc => $time) {
$zmanim .= " $loc: <code>$time</code>\n";
}
}
}
}
return $zmanim;
}
/*
* מנהלים
*/
public function getReportPeers() {
return array_map('trim', explode(',', parse_ini_file(__DIR__.'/.env')['ADMIN']));
}
/*
* עוזב ערוצים
*/
#[FilterIncoming]
public function ChannelsLeave(ChannelMessage $message): void {
try {
$this->channels->leaveChannel(channel: $message->chatId );
} catch (Throwable $e) {}
}
#[FilterCommandCaseInsensitive('start')]
public function StartCommand(Incoming & PrivateMessage $message): void {
try {
$senderid = $message->senderId;
$messageid = $message->id;
$User_Full = $this->getInfo($message->senderId);
$first_name = $User_Full['User']['first_name']?? null;
if($first_name == null){
$first_name = "null";
}
$me = $this->getSelf();
$me_username = $me['username'];
$txtbot = "היי <a href='mention:$senderid'>$first_name</a>, ברוך הבא 👋
הרובוט שישמור את השבת בקבוצה שלך!
🕯 <u>הרובוט בקוד פתוח בגיטהאב:</u>
github.com/wizardloop/shabbat";
$bot_API_markup[] = [['text'=>"זמני כניסת השבת 🕯",'callback_data'=>"זמנישבת"]];
$bot_API_markup[] = [['text'=>"הוסף אותי לקבוצה ➕",'url'=>"https://t.me/$me_username?startgroup&admin=restrict_members"]];
$bot_API_markup[] = [['text'=>"📖 כל הפקודות 💡",'callback_data'=>"כלהפקודות"]];
$bot_API_markup = [ 'inline_keyboard'=> $bot_API_markup,];
$inputReplyToMessage = ['_' => 'inputReplyToMessage', 'reply_to_msg_id' => $messageid];
$this->messages->sendMessage(no_webpage: true, peer: $message->senderId, reply_to: $inputReplyToMessage, message: "$txtbot", reply_markup: $bot_API_markup, parse_mode: 'HTML');
if (!file_exists(__DIR__."/data")) {
mkdir(__DIR__."/data");
}
if (!file_exists(__DIR__."/data/$senderid")) {
mkdir(__DIR__."/data/$senderid");
}
if (file_exists(__DIR__."/data/$senderid/grs1.txt")) {
unlink(__DIR__."/data/$senderid/grs1.txt");
}
} catch (Throwable $e) {
}
}
#[FilterButtonQueryData('חזרה')]
public function BackCommand(callbackQuery $query) {
try {
$userid = $query->userId;
$User_Full = $this->getInfo($userid);
$first_name = $User_Full['User']['first_name']?? null;
if($first_name == null){
$first_name = "null";
}
$me = $this->getSelf();
$me_username = $me['username'];
$txtbot = "היי <a href='mention:$userid'>$first_name</a>, ברוך הבא 👋
הרובוט שישמור את השבת בקבוצה שלך!
🕯 <u>הרובוט בקוד פתוח בגיטהאב:</u>
github.com/wizardloop/shabbat";
$bot_API_markup[] = [['text'=>"זמני כניסת השבת 🕯",'callback_data'=>"זמנישבת"]];
$bot_API_markup[] = [['text'=>"הוסף אותי לקבוצה ➕",'url'=>"https://t.me/$me_username?startgroup&admin=restrict_members"]];
$bot_API_markup[] = [['text'=>"📖 כל הפקודות 💡",'callback_data'=>"כלהפקודות"]];
$bot_API_markup = [ 'inline_keyboard'=> $bot_API_markup,];
$query->editText($message = "$txtbot", $replyMarkup = $bot_API_markup, ParseMode::HTML, $noWebpage = true, $scheduleDate = NULL);
if (file_exists(__DIR__."/"."data/$userid/grs1.txt")) {
unlink(__DIR__."/"."data/$userid/grs1.txt");
}
} catch (Throwable $e) {
}
}
#[FilterButtonQueryData('זמנישבת')]
public function ShabbatTimes(callbackQuery $query) {
try {
$bot_API_markup[] = [['text'=>"חזרה",'callback_data'=>"חזרה"]];
$bot_API_markup = [ 'inline_keyboard'=> $bot_API_markup,];
$editer = $query->editText($message = "⌛️", $replyMarkup = null, ParseMode::HTML, $noWebpage = false, $scheduleDate = NULL);
$ShabatTimes = $this->getZmanimForCities();
$editer2 = $query->editText($message = $ShabatTimes, $replyMarkup = $bot_API_markup, ParseMode::HTML, $noWebpage = false, $scheduleDate = NULL);
} catch (Throwable $e) {
$this->messages->sendMessage(peer: $query->userId, message: $e->getMessage());
}
}
#[FilterButtonQueryData('כלהפקודות')]
public function AllCommands(callbackQuery $query) {
try {
$txtbot = "<b>ברוכים הבאים לתפריט העזרה!</b> 🆘
בתפריט זה תמצאו את כל הפקודות והמידע";
$bot_API_markup[] = [['text'=>"כללי יסוד",'callback_data'=>"כללייסוד"]];
$bot_API_markup[] = [['text'=>"פקודות למנהלים",'callback_data'=>"פקודותלמנהלים"]];
$bot_API_markup[] = [['text'=>"פקודות לכל המשתמשים",'callback_data'=>"פקודותלכלהמשתמשים"]];
$bot_API_markup[] = [['text'=>"חזרה",'callback_data'=>"חזרה"]];
$bot_API_markup = [ 'inline_keyboard'=> $bot_API_markup,];
$query->editText($message = "$txtbot", $replyMarkup = $bot_API_markup, ParseMode::HTML, $noWebpage = false, $scheduleDate = NULL);
} catch (Throwable $e) {
}
}
#[FilterButtonQueryData('כללייסוד')]
public function Rules(callbackQuery $query) {
try {
$txtbot = "<b>(הרובוט הזה עובד רק בסופר קבוצה)</b>
🕯 על מנת שאני יוכל לסגור את הקבוצה בשבת, יש להוסיף אותי לקבוצה שלך כמנהל עם הרשאה לחסימת משתמשים.
לאחר ההוספה חובה לשלוח בקבוצה את הפקודה <code>/add</code> אחרת אני לא אשמור את השבת אצלך בקבוצה...
אתה יכול להשתמש בסימנים: /, !, . כדי להפעיל כל פקודה.
<i>טיפ: רוצה שאני רק אשלח את זמני השבת מבלי לסגור את הקבוצה? כתוב /add > הפעל התראות שבת > תסיר לי הרשאות ניהול(שאני לא יוכל לסגור את הקבוצה, אפשר גם כחבר רגיל בקבוצה ללא אדמין)</i>
<b>[בקרוב יהיה פעיל גם בחגים]</b>
זכור: אתה צריך להשתמש בפקודות בתוך הקבוצה, אלא אם כן הם תוכננו במיוחד עבור כל צ'אט (ראה 'פקודות לכל המשתמשים').";
$me = $this->getSelf();
$me_username = $me['username'];
$bot_API_markup[] = [['text'=>"הוסף אותי לקבוצה ➕",'url'=>"https://t.me/$me_username?startgroup&admin=restrict_members"]];
$bot_API_markup[] = [['text'=>"חזרה",'callback_data'=>"כלהפקודות"]];
$bot_API_markup = [ 'inline_keyboard'=> $bot_API_markup,];
$query->editText($message = "$txtbot", $replyMarkup = $bot_API_markup, ParseMode::HTML, $noWebpage = false, $scheduleDate = NULL);
} catch (Throwable $e) {
}
}
#[FilterButtonQueryData('פקודותלמנהלים')]
public function CommandForAdmins(callbackQuery $query) {
try {
$txtbot = "💡 <b>רשימת פקודות זמינות:</b>
/add - שליחת פקודה זו בקבוצה תוסיף את הקבוצה לבסיס נתונים על מנת שהיא תסגר בשבת!
/remove - הסרת הקבוצה מהבסיס נתונים... הקבוצה לא תסגר בשבת!
/settings - התאם אישית את הרובוט בקבוצה שלך.
⚙️ <b>מה אפשר לעשות בהגדרות?</b>
באפשרותכם להגדיר האם הקבוצה תקבל מידי יום שישי (בשעה 13:30) הודעה עם זמני כניסת השבת!
כמו כן באפשרותכם להגדיר הודעה מותאמת אישית שתשלח בערב שבת כשהקבוצה נסגרת!
והודעה מותאמת אישית שתשלח במוצאי שבת כשהקבוצה נפתחת!
<b>הקבוצה תיסגר לפי זמן:</b> ירושלים
כניסה: 18 דקות לפני השקיעה.
יציאה: 8.5 מעלות
⌚️ הקבוצה תסגר 10 דק' לפני הזמן.
<i>פקודות אלו יש לשלוח בקבוצה בלבד</i>";
$bot_API_markup[] = [['text'=>"חזרה",'callback_data'=>"כלהפקודות"]];
$bot_API_markup = [ 'inline_keyboard'=> $bot_API_markup,];
$query->editText($message = "$txtbot", $replyMarkup = $bot_API_markup, ParseMode::HTML, $noWebpage = false, $scheduleDate = NULL);
} catch (Throwable $e) {
}
}
#[FilterButtonQueryData('פקודותלכלהמשתמשים')]
public function CommandForAll(callbackQuery $query) {
try {
$me = $this->getSelf();
$me_username = '@'.$me['username'];
$txtbot = "💡 <b>רשימת פקודות זמינות:</b>
/shabat - הצגת זמני כניסת ויציאת השבת.
(ניתן גם לכתוב /shabbat )
/stats - כמה קבוצות שומרות שבת 📊
/donate - תמיכה ברובוט ⭐️
<b>ניתן גם להשתמש במצב אינליין:</b>
<code>$me_username shabat</code>
או:
<code>$me_username shabbat</code>
או:
<code>$me_username שבת</code>
<i>פקודות אלו ניתן לשלוח בכל צ'אט</i>";
$bot_API_markup[] = [['text'=>"חזרה",'callback_data'=>"כלהפקודות"]];
$bot_API_markup = [ 'inline_keyboard'=> $bot_API_markup,];
$query->editText($message = "$txtbot", $replyMarkup = $bot_API_markup, ParseMode::HTML, $noWebpage = false, $scheduleDate = NULL);
} catch (Throwable $e) {
}
}
#[FiltersOr(new FilterCommandCaseInsensitive('shabat'), new FilterCommandCaseInsensitive('shabbat'))]
public function shabatCommand(Incoming $message): void {
try {
$senderid = $message->senderId;
$messageid = $message->id;
$chatid = $message->chatId;
$inputReplyToMessage = ['_' => 'inputReplyToMessage', 'reply_to_msg_id' => $messageid];
$sentMessage = $this->messages->sendMessage(peer: $chatid, reply_to: $inputReplyToMessage, message: "⌛️", parse_mode: 'HTML');
$sentMessage2 = $this->extractMessageId($sentMessage);
$ShabatTimes = $this->getZmanimForCities();
$me = $this->getSelf();
$me_username = $me['username'];
$inlineQueryPeerTypePM = ['_' => 'inlineQueryPeerTypePM'];
$inlineQueryPeerTypeChat = ['_' => 'inlineQueryPeerTypeChat'];
$inlineQueryPeerTypeBotPM = ['_' => 'inlineQueryPeerTypeBotPM'];
$inlineQueryPeerTypeMegagroup = ['_' => 'inlineQueryPeerTypeMegagroup'];
$inlineQueryPeerTypeBroadcast = ['_' => 'inlineQueryPeerTypeBroadcast'];
$keyboardButtonSwitchInline = ['_' => 'keyboardButtonSwitchInline', 'same_peer' => false, 'text' => 'לשיתוף זמני השבת 🕯', 'query' => 'shabat', 'peer_types' => [$inlineQueryPeerTypePM, $inlineQueryPeerTypeChat, $inlineQueryPeerTypeBotPM, $inlineQueryPeerTypeMegagroup, $inlineQueryPeerTypeBroadcast]];
$keyboardButtonRow1 = ['_' => 'keyboardButtonRow', 'buttons' => [$keyboardButtonSwitchInline]];
$bot_API_markup = ['_' => 'replyInlineMarkup', 'rows' => [$keyboardButtonRow1]];
$this->messages->editMessage(peer: $message->chatId, id: $sentMessage2, message: "$ShabatTimes", reply_markup: $bot_API_markup, parse_mode: 'HTML');
} catch (Throwable $e) {
$this->messages->sendMessage(peer: $message->chatId, message: $e->getMessage());
}
}
public function onUpdateBotInlineQuery($update) {
try {
$ShabatTimes = $this->getZmanimForCities();
$me = $this->getSelf();
$me_username = $me['username'];
$inlineQueryPeerTypePM = ['_' => 'inlineQueryPeerTypePM'];
$inlineQueryPeerTypeChat = ['_' => 'inlineQueryPeerTypeChat'];
$inlineQueryPeerTypeBotPM = ['_' => 'inlineQueryPeerTypeBotPM'];
$inlineQueryPeerTypeMegagroup = ['_' => 'inlineQueryPeerTypeMegagroup'];
$inlineQueryPeerTypeBroadcast = ['_' => 'inlineQueryPeerTypeBroadcast'];
$keyboardButtonSwitchInline = ['_' => 'keyboardButtonSwitchInline', 'same_peer' => false, 'text' => 'לשיתוף זמני השבת 🕯', 'query' => 'shabat', 'peer_types' => [$inlineQueryPeerTypePM, $inlineQueryPeerTypeChat, $inlineQueryPeerTypeBotPM, $inlineQueryPeerTypeMegagroup, $inlineQueryPeerTypeBroadcast]];
$keyboardButtonRow1 = ['_' => 'keyboardButtonRow', 'buttons' => [$keyboardButtonSwitchInline]];
$bot_API_markup = ['_' => 'replyInlineMarkup', 'rows' => [$keyboardButtonRow1]];
$documentAttributeImageSize = ['_' => 'documentAttributeImageSize', 'w' => 475, 'h' => 475];
$inputWebDocument = ['_' => 'inputWebDocument', 'url' => 'https://telegra.ph/file/0b06390cc0e5236a5bd05-0fc4534fa4021ecb33.jpg', 'size' => 98166, 'mime_type' => 'image/jpeg', 'attributes' => [$documentAttributeImageSize]];
$botInlineMessageText = ['_' => 'inputBotInlineMessageText', 'message' => "$ShabatTimes", 'parse_mode'=> 'HTML', 'reply_markup' => $bot_API_markup];
$inputBotInlineResult = ['_' => 'botInlineResult', 'id' => '0', 'type' => 'article', 'title' => 'זמני כניסת השבת', 'description' => 'לחץ כאן לשיתוף זמני השבת!', 'thumb' => $inputWebDocument,'send_message' => $botInlineMessageText];
$this->logger("Got query ".$update['query']);
try {
$result = ['query_id' => $update['query_id'], 'results' => [$inputBotInlineResult], 'cache_time' => 0];
if ($update['query'] === 'shabat' || $update['query'] === 'shabbat' || $update['query'] === 'שבת') {
$this->messages->setInlineBotResults($result);
} else {
$this->messages->setInlineBotResults($result);
}
} catch (Throwable $e) {
try {
$this->messages->sendMessage(['peer' => $update['user_id'], 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]);
} catch (RPCErrorException $e) {
$this->logger($e);
} catch (Exception $e) {
$this->logger($e);
}
}
} catch (Throwable $e) {
$sentMessage = $this->messages->sendMessage(peer: $update['query_id'], message: $e->getMessage());
}
}
#[FilterButtonQueryData('סגור')]
public function closecommand(callbackQuery $query) {
try {
$this->messages->deleteMessages(revoke: true, id: [$query->messageId]);
} catch (Throwable $e) {
$query->answer($message = "אני לא יכול לסגור את ההודעה, סגור אותה בעצמך..", $alert = false, $url = null, $cacheTime = 0);
}
}
#[FilterCommandCaseInsensitive('add')]
public function addgroupCommand(Incoming & GroupMessage $message): void {
try {
$senderid = $message->senderId;
$messageid = $message->id;
$chatid = $message->chatId;
$me = $this->getSelf();
$me_name = $me['first_name'];
$me_id = $me['id'];
$Chat_Full = $this->getInfo($message->chatId);
$title = $Chat_Full['Chat']['title']?? null;
if($title == null){
$title = "(null)";
}
$admrgh = $Chat_Full['Chat']['admin_rights']['ban_users']?? null;
$type = $Chat_Full['type'];
if($type != "supergroup"){
$txtbot = "<b>אני פועל רק בקבוצות-על(supergroup)</b>";
$this->messages->sendMessage(peer: $message->chatId, message: "$txtbot", parse_mode: 'HTML');
}
if($type == "supergroup"){
if($message->senderId == $message->chatId){
$txtbot = "<b>הינך מנהל אנונימי.</b>
רק מנהל לא אנונימי יכול להוסיף את הקבוצה לבסיס נתונים!";
$this->messages->sendMessage(peer: $message->chatId, message: "$txtbot", parse_mode: 'HTML');
}else{
try {
$channelpart = $this->channels->getParticipant(['channel' => $message->chatId, 'participant' => $message->senderId]);
if(isset($channelpart['participant']['_'])&& ($channelpart['participant']['_'] == 'channelParticipantAdmin' || $channelpart['participant']['_'] == 'channelParticipantCreator')) $isadmin = true;
else $isadmin = false;
} catch (Throwable $e) {
$isadmin = false;
}
if($isadmin != false){
try {
$channelpart2 = $this->channels->getParticipant(['channel' => $chatid, 'participant' => $me_id ]);
if(isset($channelpart2['participant']['_'])&& ($channelpart2['participant']['_'] == 'channelParticipantAdmin' || $channelpart2['participant']['_'] == 'channelParticipantCreator')) $isadmin2 = true;
else $isadmin2 = false;
} catch (Throwable $e) {
$isadmin2 = false;
}
if($isadmin2 != false){
if($admrgh == null){
$txtbot = "<b>אין לי הרשאות ניהול מתאימות.</b>
(הרשאות לחסימת משתמשים ושינוי הרשאות)";
$this->messages->sendMessage(peer: $message->chatId, message: "$txtbot", parse_mode: 'HTML');
}
if($admrgh != null){
if (file_exists(__DIR__."/"."data/DBgroups.txt")) {
$filex = Amp\File\read(__DIR__."/"."data/DBgroups.txt");
$user1 = array_map('trim', explode("\n", $filex));
if (!in_array((string)$chatid, $user1, true)) {
if($filex != null){
$filex = $filex."\n";
Amp\File\write(__DIR__."/"."data/DBgroups.txt", "$filex"."$chatid");
$txtbot = "<b>הקבוצה נוספה לבסיס נתונים!</b>";
$this->messages->sendMessage(peer: $message->chatId, message: "$txtbot", parse_mode: 'HTML');
if (!file_exists(__DIR__."/"."data/$chatid")) {
mkdir(__DIR__."/"."data/$chatid");
}
}
if($filex == null){
$filex = null;
Amp\File\write(__DIR__."/"."data/DBgroups.txt", "$filex"."$chatid");
$txtbot = "<b>הקבוצה נוספה לבסיס נתונים!</b>";
$this->messages->sendMessage(peer: $message->chatId, message: "$txtbot", parse_mode: 'HTML');
if (!file_exists(__DIR__."/"."data/$chatid")) {
mkdir(__DIR__."/"."data/$chatid");
}
}
}
if (in_array((string)$chatid, $user1, true)) {
$txtbot = "<b>הקבוצה כבר בבסיס נתונים!</b>";
$this->messages->sendMessage(peer: $message->chatId, message: "$txtbot", parse_mode: 'HTML');
}
}
if (!file_exists(__DIR__."/"."data/DBgroups.txt")) {
$filex = null;
Amp\File\write(__DIR__."/"."data/DBgroups.txt", "$filex"."$chatid");
$txtbot = "<b>הקבוצה נוספה לבסיס נתונים!</b>";
$this->messages->sendMessage(peer: $message->chatId, message: "$txtbot", parse_mode: 'HTML');
if (__DIR__."/".!file_exists("data/$chatid")) {
mkdir(__DIR__."/"."data/$chatid");
}
}
}
}
if($isadmin2 != true){
$txtbot = "<b>אני לא מנהל בקבוצה.</b>
(יש להוסיף אותי כמנהל)";
$this->messages->sendMessage(peer: $message->chatId, message: "$txtbot", parse_mode: 'HTML');
}
}
if($isadmin != true){
$txtbot = "<b>אינך מנהל או יוצר בקבוצה.</b>
רק מנהלים יכולים להוסיף את הקבוצה לבסיס נתונים!";
$this->messages->sendMessage(peer: $message->chatId, message: "$txtbot", parse_mode: 'HTML');
}
}
}
} catch (Throwable $e) {
$error = $e->getMessage();
$sentMessage = $this->messages->sendMessage(peer: $message->chatId, message: $error);
}
}
#[FilterCommandCaseInsensitive('remove')]
public function removegroupCommand(Incoming & GroupMessage $message): void {
try {
$senderid = $message->senderId;
$messageid = $message->id;
$chatid = $message->chatId;
$me = $this->getSelf();
$me_name = $me['first_name'];
$me_id = $me['id'];
$Chat_Full = $this->getInfo($message->chatId);
$title = $Chat_Full['Chat']['title']?? null;
if($title == null){
$title = "(null)";
}
$admrgh = $Chat_Full['Chat']['admin_rights']['ban_users']?? null;
$type = $Chat_Full['type'];
if($type != "supergroup"){
$txtbot = "<b>אני פועל רק בקבוצות-על(supergroup)</b>";
$this->messages->sendMessage(peer: $message->chatId, message: "$txtbot", parse_mode: 'HTML');
}
if($type == "supergroup"){
if($message->senderId == $message->chatId){
$txtbot = "<b>הינך מנהל אנונימי.</b>
רק מנהל לא אנונימי יכול להוסיף את הקבוצה לבסיס נתונים!";
$this->messages->sendMessage(peer: $message->chatId, message: "$txtbot", parse_mode: 'HTML');
}else{
try {
$channelpart = $this->channels->getParticipant(['channel' => $chatid, 'participant' => $message->senderId ]);
if(isset($channelpart['participant']['_'])&& ($channelpart['participant']['_'] == 'channelParticipantAdmin' or $channelpart['participant']['_'] == 'channelParticipantCreator')) $isadmin = true;
else $isadmin = false;
}catch (\danog\MadelineProto\Exception $e) {
$estring = (string) $e;
if(preg_match("/USER_NOT_PARTICIPANT/",$estring)){
$isadmin = false;
}else{
$isadmin = false;
}
} catch (\danog\MadelineProto\RPCErrorException $e) {
$estring = (string) $e;
if ($e->rpc === 'USER_NOT_PARTICIPANT') {
$isadmin = false;
}else{
$isadmin = false;
}
}
if($isadmin != false){
try {
$channelpart2 = $this->channels->getParticipant(['channel' => $chatid, 'participant' => $me_id ]);
if(isset($channelpart2['participant']['_'])&& ($channelpart2['participant']['_'] == 'channelParticipantAdmin' or $channelpart2['participant']['_'] == 'channelParticipantCreator')) $isadmin2 = true;
else $isadmin2 = false;
} catch (Throwable $e) {
$isadmin2 = false;
}
if($isadmin2 != false){
if($admrgh == null){
$txtbot = "<b>אין לי הרשאות ניהול מתאימות.</b>
(הרשאות לחסימת משתמשים ושינוי הרשאות)";
$this->messages->sendMessage(peer: $message->chatId, message: "$txtbot", parse_mode: 'HTML');
}
if($admrgh != null){
if (file_exists(__DIR__."/"."data/DBgroups.txt")) {
$filex = Amp\File\read(__DIR__."/"."data/DBgroups.txt");
$user1 = array_map('trim', explode("\n", $filex));
if (in_array((string)$chatid, $user1, true)) {
$filex = Amp\File\read(__DIR__."/"."data/DBgroups.txt");
$chatidstring = (string) $chatid;
$result = str_replace($chatidstring,"",$filex);
Amp\File\write(__DIR__."/"."data/DBgroups.txt", $result);
$filex2 = Amp\File\read(__DIR__."/"."data/DBgroups.txt");
$result2 = preg_replace('/^[ \t]*[\r\n]+/m', '', $filex2);
Amp\File\write(__DIR__."/"."data/DBgroups.txt", $result2);
$txtbot = "<b>הקבוצה הוסרה בהצלחה! אני עוזב את הקבוצה...</b>";
$this->messages->sendMessage(peer: $message->chatId, message: "$txtbot", parse_mode: 'HTML');
$this->channels->leaveChannel(channel: $message->chatId );
if (file_exists(__DIR__."/"."data/$chatidstring/alertshabat.txt")) {
unlink(__DIR__."/"."data/$chatidstring/alertshabat.txt");
}
if (file_exists(__DIR__."/"."data/$chatidstring/msgclosermotan.txt")) {
unlink(__DIR__."/"."data/$chatidstring/msgclosermotan.txt");
}
}
if (!in_array((string)$chatid, $user1, true)) {
$txtbot = "<b>הקבוצה כבר הוסרה מבסיס נתונים!</b>";
$this->messages->sendMessage(peer: $message->chatId, message: "$txtbot", parse_mode: 'HTML');
}
}
if (!file_exists(__DIR__."/"."data/DBgroups.txt")) {
$txtbot = "<b>הקבוצה כבר הוסרה מבסיס נתונים!</b>";
$this->messages->sendMessage(peer: $message->chatId, message: "$txtbot", parse_mode: 'HTML');
}
}
}
if($isadmin2 != true){
$txtbot = "<b>אני לא מנהל בקבוצה.</b>
(יש להוסיף אותי כמנהל)";
$this->messages->sendMessage(peer: $message->chatId, message: "$txtbot", parse_mode: 'HTML');
}
}
if($isadmin != true){
$txtbot = "<b>אינך מנהל או יוצר בקבוצה.</b>
רק מנהלים יכולים להוסיף את הקבוצה לבסיס נתונים!";
$this->messages->sendMessage(peer: $message->chatId, message: "$txtbot", parse_mode: 'HTML');
}
}
}
} catch (Throwable $e) {
$error = $e->getMessage();
$sentMessage = $this->messages->sendMessage(peer: $message->chatId, message: $error);
}
}
#[FilterCommandCaseInsensitive('settings')]
public function grupsettingsCommand(Incoming & GroupMessage $message): void {
try {
$senderid = $message->senderId;
$messageid = $message->id;
$chatid = $message->chatId;
$me = $this->getSelf();
$me_name = $me['first_name'];
$me_id = $me['id'];
$me_username = $me['username'];
$Chat_Full = $this->getInfo($message->chatId);
$title = $Chat_Full['Chat']['title']?? null;
if($title == null){
$title = "(null)";
}
$admrgh = $Chat_Full['Chat']['admin_rights']['ban_users']?? null;
$type = $Chat_Full['type'];
if($type != "supergroup"){
$txtbot = "<b>אני פועל רק בקבוצות-על(supergroup)</b>";
$this->messages->sendMessage(peer: $message->chatId, message: "$txtbot", parse_mode: 'HTML');
}
if($type == "supergroup"){
if($message->senderId == $message->chatId){
$txtbot = "<b>הינך מנהל אנונימי.</b>
רק מנהל לא אנונימי יכול להוסיף את הקבוצה לבסיס נתונים!";
$this->messages->sendMessage(peer: $message->chatId, message: "$txtbot", parse_mode: 'HTML');
}else{
try {
$channelpart = $this->channels->getParticipant(['channel' => $chatid, 'participant' => $message->senderId ]);
if(isset($channelpart['participant']['_'])&& ($channelpart['participant']['_'] == 'channelParticipantAdmin' or $channelpart['participant']['_'] == 'channelParticipantCreator')) $isadmin = true;
else $isadmin = false;
} catch (Throwable $e) {
$isadmin = false;
}
if($isadmin != false){
try {
$channelpart2 = $this->channels->getParticipant(['channel' => $chatid, 'participant' => $me_id ]);
if(isset($channelpart2['participant']['_'])&& ($channelpart2['participant']['_'] == 'channelParticipantAdmin' or $channelpart2['participant']['_'] == 'channelParticipantCreator')) $isadmin2 = true;
else $isadmin2 = false;
}catch (\danog\MadelineProto\Exception $e) {
$estring = (string) $e;
if(preg_match("/USER_NOT_PARTICIPANT/",$estring)){
$isadmin2 = false;
}else{
$isadmin2 = false;
}
} catch (\danog\MadelineProto\RPCErrorException $e) {
$estring = (string) $e;
if ($e->rpc === 'USER_NOT_PARTICIPANT') {
$isadmin2 = false;
}else{
$isadmin2 = false;
}
}
if($isadmin2 != false){
if($admrgh == null){
$txtbot = "<b>אין לי הרשאות ניהול מתאימות.</b>
(הרשאות לחסימת משתמשים ושינוי הרשאות)";
$this->messages->sendMessage(peer: $message->chatId, message: "$txtbot", parse_mode: 'HTML');
}
if($admrgh != null){
if (file_exists(__DIR__."/"."data/DBgroups.txt")) {
$filex = Amp\File\read(__DIR__."/"."data/DBgroups.txt");
$user1 = array_map('trim', explode("\n", $filex));
if (!in_array((string)$chatid, $user1, true)) {
$txtbot = "<b>הקבוצה לא נוספה לבסיס נתונים!</b>
שלח את הפקודה <code>/add</code>";
$this->messages->sendMessage(peer: $message->chatId, message: "$txtbot", parse_mode: 'HTML');
}
if (in_array((string)$chatid, $user1, true)) {
$txtbot2 = "<b>התאם אישית את הרובוט בקבוצה:</b>";
if (!file_exists(__DIR__."/"."data/$chatid/alertshabat.txt")) {
$bot_API_markup[] = [['text'=>"OFF ❌",'callback_data'=>"שלחזמני"],['text'=>"זמני כניסת שבת",'callback_data'=>"הסברזמנישבת"]];
}
if (file_exists(__DIR__."/"."data/$chatid/alertshabat.txt")) {
$bot_API_markup[] = [['text'=>"ON ✅",'callback_data'=>"שלחזמני1"],['text'=>"זמני כניסת שבת",'callback_data'=>"הסברזמנישבת"]];
}
if (!file_exists(__DIR__."/"."data/$chatid/alertshabat2.txt")) {
$bot_API_markup[] = [['text'=>"OFF ❌",'callback_data'=>"הודעותלפניואחרי"],['text'=>"הודעות לפני ואחרי שבת",'callback_data'=>"הסברהודעותלפאח"]];
}
if (file_exists(__DIR__."/"."data/$chatid/alertshabat2.txt")) {
$bot_API_markup[] = [['text'=>"ON ✅",'callback_data'=>"הודעותלפניואחרי1"],['text'=>"הודעות לפני ואחרי שבת",'callback_data'=>"הסברהודעותלפאח"]];
}
$bot_API_markup[] = [['text'=>"הודעה לפני שבת ✏️",'callback_data'=>"הודעתסגירה"]];
$bot_API_markup[] = [['text'=>"הודעה במוצאי שבת ✏️",'callback_data'=>"הודעתפתיחה"]];
$bot_API_markup[] = [['text'=>"↪️ החזר לברירת מחדל",'callback_data'=>"החזרברירתמחדל"]];
$bot_API_markup[] = [['text'=>"סגור ✖️",'callback_data'=>"סגור"]];
$bot_API_markup = [ 'inline_keyboard'=> $bot_API_markup,];
try {
$this->messages->sendMessage(peer: $senderid, message: "$txtbot2", reply_markup: $bot_API_markup, parse_mode: 'HTML');
$txtbot = "<b>פאנל ההגדרות נשלח אליך בהודעה פרטית.</b>";
$bot_API_markup2[] = [['text'=>"לחץ כאן למעבר ⚙️",'url'=>"https://t.me/$me_username"]];
$bot_API_markup2 = [ 'inline_keyboard'=> $bot_API_markup2,];
$this->messages->sendMessage(peer: $message->chatId, message: "$txtbot", reply_markup: $bot_API_markup2, parse_mode: 'HTML');
} catch (Throwable $e) {
$error = $e->getMessage();
$sentMessage = $this->messages->sendMessage(peer: $message->chatId, message: $error);
}
if (!file_exists(__DIR__."/"."data/$senderid")) {
mkdir(__DIR__."/"."data/$senderid");
}
Amp\File\write(__DIR__."/"."data/$senderid/groupid.txt", "$chatid");
}
}
if (!file_exists(__DIR__."/"."data/DBgroups.txt")) {
$txtbot = "<b>הקבוצה לא נוספה לבסיס נתונים!</b>\nשלח את הפקודה <code>/add</code>";
$this->messages->sendMessage(peer: $message->chatId, message: "$txtbot", parse_mode: 'HTML');
}
}
}
if($isadmin2 != true){
$txtbot = "<b>אני לא מנהל בקבוצה.</b>
(יש להוסיף אותי כמנהל)";
$this->messages->sendMessage(peer: $message->chatId, message: "$txtbot", parse_mode: 'HTML');
}
}
if($isadmin != true){
$txtbot = "<b>אינך מנהל או יוצר בקבוצה.</b>
רק מנהלים יכולים לפתוח פאנל הגדרות!";
$this->messages->sendMessage(peer: $message->chatId, message: "$txtbot", parse_mode: 'HTML');
}
}
}
} catch (Throwable $e) {
$error = $e->getMessage();
$sentMessage = $this->messages->sendMessage(peer: $message->chatId, message: $error);
}
}
#[FiltersOr(new FilterCommandCaseInsensitive('add'), new FilterCommandCaseInsensitive('remove'), new FilterCommandCaseInsensitive('settings'))]
public function ifNotCommands(Incoming & PrivateMessage $message): void {
try {
$messageid = $message->id;
$this->messages->deleteMessages(revoke: true, id: [$messageid]);
$sentMessage = $this->messages->sendMessage(peer: $message->senderId, message: "❌ <i>פקודה זו יש לשלוח בקבוצה בלבד!</i>", parse_mode: 'HTML');
$sentMessage2 = $this->extractMessageId($sentMessage);
$this->sleep(3);
$this->messages->deleteMessages(revoke: true, id: [$sentMessage2]);
} catch (Throwable $e) {
}
}
#[FilterButtonQueryData('חזרהלהגדרות')]
public function backtosettings(callbackQuery $query) {
try {
$userid = $query->userId;
$chatid = $query->chatId;
$User_Full = $this->getInfo($userid);
$first_name = $User_Full['User']['first_name']?? null;
if($first_name == null){
$first_name = "null";
}
if (file_exists(__DIR__."/"."data/$userid/groupid.txt")) {
$filex = Amp\File\read(__DIR__."/"."data/$userid/groupid.txt");
}else{
$filex = "NULL";
}
$txtbot = "<b>התאם אישית את הרובוט בקבוצה:</b>";
if (!file_exists(__DIR__."/"."data/$filex/alertshabat.txt")) {
$bot_API_markup[] = [['text'=>"OFF ❌",'callback_data'=>"שלחזמני"],['text'=>"זמני כניסת שבת",'callback_data'=>"הסברזמנישבת"]];
}
if (file_exists(__DIR__."/"."data/$filex/alertshabat.txt")) {
$bot_API_markup[] = [['text'=>"ON ✅",'callback_data'=>"שלחזמני1"],['text'=>"זמני כניסת שבת",'callback_data'=>"הסברזמנישבת"]];
}
if (!file_exists(__DIR__."/"."data/$filex/alertshabat2.txt")) {
$bot_API_markup[] = [['text'=>"OFF ❌",'callback_data'=>"הודעותלפניואחרי"],['text'=>"הודעות לפני ואחרי שבת",'callback_data'=>"הסברהודעותלפאח"]];
}
if (file_exists(__DIR__."/"."data/$filex/alertshabat2.txt")) {
$bot_API_markup[] = [['text'=>"ON ✅",'callback_data'=>"הודעותלפניואחרי1"],['text'=>"הודעות לפני ואחרי שבת",'callback_data'=>"הסברהודעותלפאח"]];
}
$bot_API_markup[] = [['text'=>"הודעה לפני שבת ✏️",'callback_data'=>"הודעתסגירה"]];
$bot_API_markup[] = [['text'=>"הודעה במוצאי שבת ✏️",'callback_data'=>"הודעתפתיחה"]];
$bot_API_markup[] = [['text'=>"↪️ החזר לברירת מחדל",'callback_data'=>"החזרברירתמחדל"]];
$bot_API_markup[] = [['text'=>"סגור ✖️",'callback_data'=>"סגור"]];
$bot_API_markup = [ 'inline_keyboard'=> $bot_API_markup,];
$query->editText($message = "$txtbot", $replyMarkup = $bot_API_markup, ParseMode::HTML, $noWebpage = false, $scheduleDate = NULL);
} catch (Throwable $e) {
}
}
#[FilterButtonQueryData('החזרברירתמחדל')]
public function defaultset(callbackQuery $query) {
try {
$userid = $query->userId;
$chatid = $query->chatId;
$User_Full = $this->getInfo($userid);
$first_name = $User_Full['User']['first_name']?? null;
if($first_name == null){
$first_name = "null";
}
$txtbot = "<b>האם הינך בטוח?</b>
בלחיצה על כן, ההגדרות יאופסו!
(פעולה זו לא ניתנת לשחזור)";
$bot_API_markup[] = [['text'=>"כן, אני בטוח!",'callback_data'=>"החזרברירתמחדלאישור"]];
$bot_API_markup[] = [['text'=>"ביטול",'callback_data'=>"חזרהלהגדרות"]];
$bot_API_markup = [ 'inline_keyboard'=> $bot_API_markup,];