-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
predicates.go
868 lines (735 loc) · 28.1 KB
/
predicates.go
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
package telegohandler
import (
"regexp"
"strings"
"github.com/mymmrac/telego"
)
// Any is always true
func Any() Predicate {
return func(_ telego.Update) bool {
return true
}
}
// None is always false
func None() Predicate {
return func(_ telego.Update) bool {
return false
}
}
// And is true if all the predicates are true
func And(predicates ...Predicate) Predicate {
return func(update telego.Update) bool {
for _, p := range predicates {
if !p(update) {
return false
}
}
return true
}
}
// Or is true if at least one of the predicates is true
func Or(predicates ...Predicate) Predicate {
return func(update telego.Update) bool {
for _, p := range predicates {
if p(update) {
return true
}
}
return false
}
}
// Union is true if at least one of the predicates is true
//
// Deprecated: Use [Or] predicate instead
func Union(predicates ...Predicate) Predicate {
return Or(predicates...)
}
// Not is true if predicate is false
func Not(predicate Predicate) Predicate {
return func(update telego.Update) bool {
return !predicate(update)
}
}
func anyMassage(message *telego.Message) bool {
return message != nil
}
// AnyMessage is true if the message isn't nil
func AnyMessage() Predicate {
return func(update telego.Update) bool {
return anyMassage(update.Message)
}
}
func anyMassageWithText(message *telego.Message) bool {
return message != nil && message.Text != ""
}
// AnyMessageWithText is true if the message isn't nil and its text is not empty
func AnyMessageWithText() Predicate {
return func(update telego.Update) bool {
return anyMassageWithText(update.Message)
}
}
func anyMassageWithFrom(message *telego.Message) bool {
return message != nil && message.From != nil
}
// AnyMessageWithFrom is true if the message isn't nil and its from (sender) is not nil
func AnyMessageWithFrom() Predicate {
return func(update telego.Update) bool {
return anyMassageWithFrom(update.Message)
}
}
func baseTextEqual(message *telego.Message, text string) bool {
return message != nil && message.Text == text
}
// TextEqual is true if the message isn't nil, and its text is equal to the specified text
func TextEqual(text string) Predicate {
return func(update telego.Update) bool {
return baseTextEqual(update.Message, text)
}
}
func baseTextEqualFold(message *telego.Message, text string) bool {
return message != nil && strings.EqualFold(message.Text, text)
}
// TextEqualFold is true if the message isn't nil, and its text equal fold (more general form of case-insensitivity
// equal) to the specified text
func TextEqualFold(text string) Predicate {
return func(update telego.Update) bool {
return baseTextEqualFold(update.Message, text)
}
}
func baseTextContains(message *telego.Message, text string) bool {
return message != nil && strings.Contains(message.Text, text)
}
// TextContains is true if the message isn't nil, and its text contains specified text
func TextContains(text string) Predicate {
return func(update telego.Update) bool {
return baseTextContains(update.Message, text)
}
}
func baseTextPrefix(message *telego.Message, prefix string) bool {
return message != nil && strings.HasPrefix(message.Text, prefix)
}
// TextPrefix is true if the message isn't nil, and its text has specified prefix
func TextPrefix(prefix string) Predicate {
return func(update telego.Update) bool {
return baseTextPrefix(update.Message, prefix)
}
}
func baseTextSuffix(message *telego.Message, suffix string) bool {
return message != nil && strings.HasSuffix(message.Text, suffix)
}
// TextSuffix is true if the message isn't nil, and its text has specified suffix
func TextSuffix(suffix string) Predicate {
return func(update telego.Update) bool {
return baseTextSuffix(update.Message, suffix)
}
}
func baseTextMatches(message *telego.Message, pattern *regexp.Regexp) bool {
return message != nil && pattern.MatchString(message.Text)
}
// TextMatches is true if the message isn't nil, and its text matches specified regexp
func TextMatches(pattern *regexp.Regexp) Predicate {
return func(update telego.Update) bool {
return baseTextMatches(update.Message, pattern)
}
}
// CommandRegexp matches to command and has match groups on command, bot username and arguments
var CommandRegexp = regexp.MustCompile(`(?s)^/(\w+)(@\w+)?(?:\s+(.+?)\s*)?$`)
// Command match group indexes in the [CommandRegexp]
const (
CommandMatchCmdGroup = 1
CommandMatchBotUsernameGroup = 2
CommandMatchArgsGroup = 3
)
// CommandMatchGroupsLen represents the length of match groups in the [CommandRegexp]
const CommandMatchGroupsLen = 4
// AnyCommand is true if the message isn't nil, and it matches to command regexp
func AnyCommand() Predicate {
return func(update telego.Update) bool {
return update.Message != nil && CommandRegexp.MatchString(update.Message.Text)
}
}
// CommandEqual is true if the message isn't nil, and it contains specified command
func CommandEqual(command string) Predicate {
return func(update telego.Update) bool {
if update.Message == nil {
return false
}
matches := CommandRegexp.FindStringSubmatch(update.Message.Text)
if len(matches) != CommandMatchGroupsLen {
return false
}
return strings.EqualFold(matches[CommandMatchCmdGroup], command)
}
}
// CommandEqualArgc is true if the message isn't nil, and it contains specified command with a number of args
func CommandEqualArgc(command string, argc int) Predicate {
return func(update telego.Update) bool {
if update.Message == nil {
return false
}
matches := CommandRegexp.FindStringSubmatch(update.Message.Text)
if len(matches) != CommandMatchGroupsLen {
return false
}
return strings.EqualFold(matches[CommandMatchCmdGroup], command) &&
(argc == 0 && matches[CommandMatchArgsGroup] == "" ||
len(strings.Fields(matches[CommandMatchArgsGroup])) == argc)
}
}
// CommandEqualArgv is true if the message isn't nil, and it contains specified command and args
func CommandEqualArgv(command string, argv ...string) Predicate {
return func(update telego.Update) bool {
if update.Message == nil {
return false
}
matches := CommandRegexp.FindStringSubmatch(update.Message.Text)
if len(matches) != CommandMatchGroupsLen {
return false
}
return strings.EqualFold(matches[CommandMatchCmdGroup], command) &&
(len(argv) == 0 && matches[CommandMatchArgsGroup] == "" ||
matches[CommandMatchArgsGroup] == strings.Join(argv, " "))
}
}
// SuccessPayment is true if the message isn't nil, and contains success payment
func SuccessPayment() Predicate {
return func(update telego.Update) bool {
return update.Message != nil && update.Message.SuccessfulPayment != nil
}
}
// AnyEditedMessage is true if the edited message isn't nil
func AnyEditedMessage() Predicate {
return func(update telego.Update) bool {
return anyMassage(update.EditedMessage)
}
}
// AnyEditedMessageWithText is true if the edited message isn't nil and its text is not empty
func AnyEditedMessageWithText() Predicate {
return func(update telego.Update) bool {
return anyMassageWithText(update.EditedMessage)
}
}
// AnyEditedMessageWithFrom is true if the edited message isn't nil and its from (sender) is not nil
func AnyEditedMessageWithFrom() Predicate {
return func(update telego.Update) bool {
return anyMassageWithFrom(update.EditedMessage)
}
}
// EditedTextEqual is true if the edited message isn't nil, and its text equals to the specified text
func EditedTextEqual(text string) Predicate {
return func(update telego.Update) bool {
return baseTextEqual(update.EditedMessage, text)
}
}
// EditedTextEqualFold is true if the edited message isn't nil, and its text equal fold (more general form of
// case-insensitivity equal) to the specified text
func EditedTextEqualFold(text string) Predicate {
return func(update telego.Update) bool {
return baseTextEqualFold(update.EditedMessage, text)
}
}
// EditedTextContains is true if the edited message isn't nil, and its text contains specified text
func EditedTextContains(text string) Predicate {
return func(update telego.Update) bool {
return baseTextContains(update.EditedMessage, text)
}
}
// EditedTextPrefix is true if the edited message isn't nil, and its text has specified prefix
func EditedTextPrefix(prefix string) Predicate {
return func(update telego.Update) bool {
return baseTextPrefix(update.EditedMessage, prefix)
}
}
// EditedTextSuffix is true if the edited message isn't nil, and its text has specified suffix
func EditedTextSuffix(suffix string) Predicate {
return func(update telego.Update) bool {
return baseTextSuffix(update.EditedMessage, suffix)
}
}
// EditedTextMatches is true if the edited message isn't nil, and its text matches specified regexp
func EditedTextMatches(pattern *regexp.Regexp) Predicate {
return func(update telego.Update) bool {
return baseTextMatches(update.EditedMessage, pattern)
}
}
// AnyChannelPost is true if channel post isn't nil
func AnyChannelPost() Predicate {
return func(update telego.Update) bool {
return anyMassage(update.ChannelPost)
}
}
// AnyChannelPostWithText is true if channel post isn't nil and its text is not empty
func AnyChannelPostWithText() Predicate {
return func(update telego.Update) bool {
return anyMassageWithText(update.ChannelPost)
}
}
// PostTextEqual is true if channel post isn't nil, and its text equals to the specified text
func PostTextEqual(text string) Predicate {
return func(update telego.Update) bool {
return baseTextEqual(update.ChannelPost, text)
}
}
// PostTextEqualFold is true if channel post isn't nil, and its text equal fold (more general form of case-insensitivity
// equal) to the specified text
func PostTextEqualFold(text string) Predicate {
return func(update telego.Update) bool {
return baseTextEqualFold(update.ChannelPost, text)
}
}
// PostTextContains is true if channel post isn't nil, and its text contains specified text
func PostTextContains(text string) Predicate {
return func(update telego.Update) bool {
return baseTextContains(update.ChannelPost, text)
}
}
// PostTextPrefix is true if channel post isn't nil, and its text has specified prefix
func PostTextPrefix(prefix string) Predicate {
return func(update telego.Update) bool {
return baseTextPrefix(update.ChannelPost, prefix)
}
}
// PostTextSuffix is true if channel post isn't nil, and its text has specified suffix
func PostTextSuffix(suffix string) Predicate {
return func(update telego.Update) bool {
return baseTextSuffix(update.ChannelPost, suffix)
}
}
// PostTextMatches is true if channel post isn't nil, and its text matches specified regexp
func PostTextMatches(pattern *regexp.Regexp) Predicate {
return func(update telego.Update) bool {
return baseTextMatches(update.ChannelPost, pattern)
}
}
// AnyEditedChannelPost is true if the edited channel post isn't nil
func AnyEditedChannelPost() Predicate {
return func(update telego.Update) bool {
return anyMassage(update.EditedChannelPost)
}
}
// AnyEditedChannelPostWithText is true if edited channel post isn't nil and its text is not empty
func AnyEditedChannelPostWithText() Predicate {
return func(update telego.Update) bool {
return anyMassageWithText(update.EditedChannelPost)
}
}
// EditedPostTextEqual is true if edited channel post isn't nil, and its text equals to the specified text
func EditedPostTextEqual(text string) Predicate {
return func(update telego.Update) bool {
return baseTextEqual(update.EditedChannelPost, text)
}
}
// EditedPostTextEqualFold is true if edited channel post isn't nil, and its text equal fold (more general form of
// case-insensitivity equal) to the specified text
func EditedPostTextEqualFold(text string) Predicate {
return func(update telego.Update) bool {
return baseTextEqualFold(update.EditedChannelPost, text)
}
}
// EditedPostTextContains is true if edited channel post isn't nil, and its text contains specified text
func EditedPostTextContains(text string) Predicate {
return func(update telego.Update) bool {
return baseTextContains(update.EditedChannelPost, text)
}
}
// EditedPostTextPrefix is true if edited channel post isn't nil, and its text has specified prefix
func EditedPostTextPrefix(prefix string) Predicate {
return func(update telego.Update) bool {
return baseTextPrefix(update.EditedChannelPost, prefix)
}
}
// EditedPostTextSuffix is true if edited channel post isn't nil, and its text has specified suffix
func EditedPostTextSuffix(suffix string) Predicate {
return func(update telego.Update) bool {
return baseTextSuffix(update.EditedChannelPost, suffix)
}
}
// EditedPostTextMatches is true if edited channel post isn't nil, and its text matches specified regexp
func EditedPostTextMatches(pattern *regexp.Regexp) Predicate {
return func(update telego.Update) bool {
return baseTextMatches(update.EditedChannelPost, pattern)
}
}
// AnyInlineQuery is true if inline query isn't nil
func AnyInlineQuery() Predicate {
return func(update telego.Update) bool {
return update.InlineQuery != nil
}
}
// InlineQueryEqual is true if inline query isn't nil, and its query equal to specified text
func InlineQueryEqual(text string) Predicate {
return func(update telego.Update) bool {
return update.InlineQuery != nil && update.InlineQuery.Query == text
}
}
// InlineQueryEqualFold is true if inline query isn't nil, and its query equal fold (more general form of
// case-insensitivity equal) to the specified text
func InlineQueryEqualFold(text string) Predicate {
return func(update telego.Update) bool {
return update.InlineQuery != nil && strings.EqualFold(update.InlineQuery.Query, text)
}
}
// InlineQueryContains is true if inline query isn't nil, and its query contains specified text
func InlineQueryContains(text string) Predicate {
return func(update telego.Update) bool {
return update.InlineQuery != nil && strings.Contains(update.InlineQuery.Query, text)
}
}
// InlineQueryPrefix is true if inline query isn't nil, and its query has specified prefix
func InlineQueryPrefix(prefix string) Predicate {
return func(update telego.Update) bool {
return update.InlineQuery != nil && strings.HasPrefix(update.InlineQuery.Query, prefix)
}
}
// InlineQuerySuffix is true if inline query isn't nil, and its query has specified suffix
func InlineQuerySuffix(suffix string) Predicate {
return func(update telego.Update) bool {
return update.InlineQuery != nil && strings.HasSuffix(update.InlineQuery.Query, suffix)
}
}
// InlineQueryMatches is true if inline query isn't nil, and its query matches specified regexp
func InlineQueryMatches(pattern *regexp.Regexp) Predicate {
return func(update telego.Update) bool {
return update.InlineQuery != nil && pattern.MatchString(update.InlineQuery.Query)
}
}
// AnyChosenInlineResult is true if the chosen inline result isn't nil
func AnyChosenInlineResult() Predicate {
return func(update telego.Update) bool {
return update.ChosenInlineResult != nil
}
}
// AnyCallbackQuery is true if the callback query isn't nil
func AnyCallbackQuery() Predicate {
return func(update telego.Update) bool {
return update.CallbackQuery != nil
}
}
// AnyCallbackQueryWithMessage is true if callback query and its message isn't nil
func AnyCallbackQueryWithMessage() Predicate {
return func(update telego.Update) bool {
return update.CallbackQuery != nil && update.CallbackQuery.Message != nil
}
}
// CallbackDataEqual is true if callback query isn't nil, and its data equal to specified text
func CallbackDataEqual(text string) Predicate {
return func(update telego.Update) bool {
return update.CallbackQuery != nil && update.CallbackQuery.Data == text
}
}
// CallbackDataEqualFold is true if the callback query isn't nil, and its data equal fold (more general form of
// case-insensitivity equal) to the specified text
func CallbackDataEqualFold(text string) Predicate {
return func(update telego.Update) bool {
return update.CallbackQuery != nil && strings.EqualFold(update.CallbackQuery.Data, text)
}
}
// CallbackDataContains is true if the callback query isn't nil, and its data contains specified text
func CallbackDataContains(text string) Predicate {
return func(update telego.Update) bool {
return update.CallbackQuery != nil && strings.Contains(update.CallbackQuery.Data, text)
}
}
// CallbackDataPrefix is true if the callback query isn't nil, and its data has specified prefix
func CallbackDataPrefix(prefix string) Predicate {
return func(update telego.Update) bool {
return update.CallbackQuery != nil && strings.HasPrefix(update.CallbackQuery.Data, prefix)
}
}
// CallbackDataSuffix is true if the callback query isn't nil, and its data has specified suffix
func CallbackDataSuffix(suffix string) Predicate {
return func(update telego.Update) bool {
return update.CallbackQuery != nil && strings.HasSuffix(update.CallbackQuery.Data, suffix)
}
}
// CallbackDataMatches is true if the callback query isn't nil, and its data matches specified regexp
func CallbackDataMatches(pattern *regexp.Regexp) Predicate {
return func(update telego.Update) bool {
return update.CallbackQuery != nil && pattern.MatchString(update.CallbackQuery.Data)
}
}
// AnyShippingQuery is true if shipping query isn't nil
func AnyShippingQuery() Predicate {
return func(update telego.Update) bool {
return update.ShippingQuery != nil
}
}
// AnyPreCheckoutQuery is true if the pre checkout query isn't nil
func AnyPreCheckoutQuery() Predicate {
return func(update telego.Update) bool {
return update.PreCheckoutQuery != nil
}
}
// AnyPoll is true if the poll isn't nil
func AnyPoll() Predicate {
return func(update telego.Update) bool {
return update.Poll != nil
}
}
// AnyPollAnswer is true if the poll answer isn't nil
func AnyPollAnswer() Predicate {
return func(update telego.Update) bool {
return update.PollAnswer != nil
}
}
// AnyMyChatMember is true if my chat member isn't nil
func AnyMyChatMember() Predicate {
return func(update telego.Update) bool {
return update.MyChatMember != nil
}
}
// AnyChatMember is true if chat member isn't nil
func AnyChatMember() Predicate {
return func(update telego.Update) bool {
return update.ChatMember != nil
}
}
// AnyChatJoinRequest is true if chat join request isn't nil
func AnyChatJoinRequest() Predicate {
return func(update telego.Update) bool {
return update.ChatJoinRequest != nil
}
}
func anyMassageWithCaption(message *telego.Message) bool {
return message != nil && message.Caption != ""
}
// AnyMessageWithCaption is true if the message isn't nil and its caption is not empty
func AnyMessageWithCaption() Predicate {
return func(update telego.Update) bool {
return anyMassageWithCaption(update.Message)
}
}
func baseCaptionEqual(message *telego.Message, text string) bool {
return message != nil && message.Caption == text
}
// CaptionEqual is true if the message isn't nil, and its caption is equal to the specified text
func CaptionEqual(text string) Predicate {
return func(update telego.Update) bool {
return baseCaptionEqual(update.Message, text)
}
}
func baseCaptionEqualFold(message *telego.Message, text string) bool {
return message != nil && strings.EqualFold(message.Caption, text)
}
// CaptionEqualFold is true if the message isn't nil, and its caption equal fold (more general form of
// case-insensitivity equal) to the specified text
func CaptionEqualFold(text string) Predicate {
return func(update telego.Update) bool {
return baseCaptionEqualFold(update.Message, text)
}
}
func baseCaptionContains(message *telego.Message, text string) bool {
return message != nil && strings.Contains(message.Caption, text)
}
// CaptionContains is true if the message isn't nil, and its caption contains specified text
func CaptionContains(text string) Predicate {
return func(update telego.Update) bool {
return baseCaptionContains(update.Message, text)
}
}
func baseCaptionPrefix(message *telego.Message, prefix string) bool {
return message != nil && strings.HasPrefix(message.Caption, prefix)
}
// CaptionPrefix is true if the message isn't nil, and its caption has specified prefix
func CaptionPrefix(prefix string) Predicate {
return func(update telego.Update) bool {
return baseCaptionPrefix(update.Message, prefix)
}
}
func baseCaptionSuffix(message *telego.Message, suffix string) bool {
return message != nil && strings.HasSuffix(message.Caption, suffix)
}
// CaptionSuffix is true if the message isn't nil, and its caption has specified suffix
func CaptionSuffix(suffix string) Predicate {
return func(update telego.Update) bool {
return baseCaptionSuffix(update.Message, suffix)
}
}
func baseCaptionMatches(message *telego.Message, pattern *regexp.Regexp) bool {
return message != nil && pattern.MatchString(message.Caption)
}
// CaptionMatches is true if the message isn't nil, and its caption matches specified regexp
func CaptionMatches(pattern *regexp.Regexp) Predicate {
return func(update telego.Update) bool {
return baseCaptionMatches(update.Message, pattern)
}
}
// AnyCaptionCommand is true if the message isn't nil, and its caption matches to command regexp
func AnyCaptionCommand() Predicate {
return func(update telego.Update) bool {
return update.Message != nil && CommandRegexp.MatchString(update.Message.Caption)
}
}
// CaptionCommandEqual is true if the message isn't nil, and its caption contains specified command
func CaptionCommandEqual(command string) Predicate {
return func(update telego.Update) bool {
if update.Message == nil {
return false
}
matches := CommandRegexp.FindStringSubmatch(update.Message.Caption)
if len(matches) != CommandMatchGroupsLen {
return false
}
return strings.EqualFold(matches[CommandMatchCmdGroup], command)
}
}
// CaptionCommandEqualArgc is true if the message isn't nil, and its caption contains specified
// command with a number of args
func CaptionCommandEqualArgc(command string, argc int) Predicate {
return func(update telego.Update) bool {
if update.Message == nil {
return false
}
matches := CommandRegexp.FindStringSubmatch(update.Message.Caption)
if len(matches) != CommandMatchGroupsLen {
return false
}
return strings.EqualFold(matches[CommandMatchCmdGroup], command) &&
(argc == 0 && matches[CommandMatchArgsGroup] == "" ||
len(strings.Fields(matches[CommandMatchArgsGroup])) == argc)
}
}
// CaptionCommandEqualArgv is true if the message isn't nil, and its caption contains specified command and args
func CaptionCommandEqualArgv(command string, argv ...string) Predicate {
return func(update telego.Update) bool {
if update.Message == nil {
return false
}
matches := CommandRegexp.FindStringSubmatch(update.Message.Caption)
if len(matches) != CommandMatchGroupsLen {
return false
}
return strings.EqualFold(matches[CommandMatchCmdGroup], command) &&
(len(argv) == 0 && matches[CommandMatchArgsGroup] == "" ||
matches[CommandMatchArgsGroup] == strings.Join(argv, " "))
}
}
// AnyEditedMessageWithCaption is true if the edited message isn't nil and its caption is not empty
func AnyEditedMessageWithCaption() Predicate {
return func(update telego.Update) bool {
return anyMassageWithCaption(update.EditedMessage)
}
}
// EditedCaptionEqual is true if the edited message isn't nil, and its caption equals to the specified text
func EditedCaptionEqual(text string) Predicate {
return func(update telego.Update) bool {
return baseCaptionEqual(update.EditedMessage, text)
}
}
// EditedCaptionEqualFold is true if the edited message isn't nil, and its caption equal fold (more general form of
// case-insensitivity equal) to the specified text
func EditedCaptionEqualFold(text string) Predicate {
return func(update telego.Update) bool {
return baseCaptionEqualFold(update.EditedMessage, text)
}
}
// EditedCaptionContains is true if the edited message isn't nil, and its caption contains specified text
func EditedCaptionContains(text string) Predicate {
return func(update telego.Update) bool {
return baseCaptionContains(update.EditedMessage, text)
}
}
// EditedCaptionPrefix is true if the edited message isn't nil, and its caption has specified prefix
func EditedCaptionPrefix(prefix string) Predicate {
return func(update telego.Update) bool {
return baseCaptionPrefix(update.EditedMessage, prefix)
}
}
// EditedCaptionSuffix is true if the edited message isn't nil, and its caption has specified suffix
func EditedCaptionSuffix(suffix string) Predicate {
return func(update telego.Update) bool {
return baseCaptionSuffix(update.EditedMessage, suffix)
}
}
// EditedCaptionMatches is true if the edited message isn't nil, and its caption matches specified regexp
func EditedCaptionMatches(pattern *regexp.Regexp) Predicate {
return func(update telego.Update) bool {
return baseCaptionMatches(update.EditedMessage, pattern)
}
}
// AnyChannelPostWithCaption is true if channel post isn't nil and its caption is not empty
func AnyChannelPostWithCaption() Predicate {
return func(update telego.Update) bool {
return anyMassageWithCaption(update.ChannelPost)
}
}
// PostCaptionEqual is true if channel post isn't nil, and its caption equals to the specified text
func PostCaptionEqual(text string) Predicate {
return func(update telego.Update) bool {
return baseCaptionEqual(update.ChannelPost, text)
}
}
// PostCaptionEqualFold is true if channel post isn't nil, and its caption equal fold (more general form of
// case-insensitivity equal) to the specified text
func PostCaptionEqualFold(text string) Predicate {
return func(update telego.Update) bool {
return baseCaptionEqualFold(update.ChannelPost, text)
}
}
// PostCaptionContains is true if channel post isn't nil, and its caption contains specified text
func PostCaptionContains(text string) Predicate {
return func(update telego.Update) bool {
return baseCaptionContains(update.ChannelPost, text)
}
}
// PostCaptionPrefix is true if channel post isn't nil, and its caption has specified prefix
func PostCaptionPrefix(prefix string) Predicate {
return func(update telego.Update) bool {
return baseCaptionPrefix(update.ChannelPost, prefix)
}
}
// PostCaptionSuffix is true if channel post isn't nil, and its caption has specified suffix
func PostCaptionSuffix(suffix string) Predicate {
return func(update telego.Update) bool {
return baseCaptionSuffix(update.ChannelPost, suffix)
}
}
// PostCaptionMatches is true if channel post isn't nil, and its caption matches specified regexp
func PostCaptionMatches(pattern *regexp.Regexp) Predicate {
return func(update telego.Update) bool {
return baseCaptionMatches(update.ChannelPost, pattern)
}
}
// AnyEditedChannelPostWithCaption is true if edited channel post isn't nil and its caption is not empty
func AnyEditedChannelPostWithCaption() Predicate {
return func(update telego.Update) bool {
return anyMassageWithCaption(update.EditedChannelPost)
}
}
// EditedPostCaptionEqual is true if edited channel post isn't nil, and its caption equals to the specified text
func EditedPostCaptionEqual(text string) Predicate {
return func(update telego.Update) bool {
return baseCaptionEqual(update.EditedChannelPost, text)
}
}
// EditedPostCaptionEqualFold is true if edited channel post isn't nil, and its caption equal fold (more general form of
// case-insensitivity equal) to the specified text
func EditedPostCaptionEqualFold(text string) Predicate {
return func(update telego.Update) bool {
return baseCaptionEqualFold(update.EditedChannelPost, text)
}
}
// EditedPostCaptionContains is true if edited channel post isn't nil, and its caption contains specified text
func EditedPostCaptionContains(text string) Predicate {
return func(update telego.Update) bool {
return baseCaptionContains(update.EditedChannelPost, text)
}
}
// EditedPostCaptionPrefix is true if edited channel post isn't nil, and its caption has specified prefix
func EditedPostCaptionPrefix(prefix string) Predicate {
return func(update telego.Update) bool {
return baseCaptionPrefix(update.EditedChannelPost, prefix)
}
}
// EditedPostCaptionSuffix is true if edited channel post isn't nil, and its caption has specified suffix
func EditedPostCaptionSuffix(suffix string) Predicate {
return func(update telego.Update) bool {
return baseCaptionSuffix(update.EditedChannelPost, suffix)
}
}
// EditedPostCaptionMatches is true if edited channel post isn't nil, and its caption matches specified regexp
func EditedPostCaptionMatches(pattern *regexp.Regexp) Predicate {
return func(update telego.Update) bool {
return baseCaptionMatches(update.EditedChannelPost, pattern)
}
}