Passed
Push — main ( 36dc31...e0778d )
by Miaad
10:46
created

message::isReplied()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
3
namespace BPT\types;
4
5
use BPT\constants\chatMemberStatus;
6
use BPT\telegram\telegram;
7
use stdClass;
8
9
/**
10
 * This object represents a message.
11
 */
12
class message extends types {
0 ignored issues
show
Bug introduced by
The type BPT\types\types was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
    /** Keep all properties which has sub properties */
14
    protected const subs = [
15
        'from' => 'BPT\types\user',
16
        'sender_chat' => 'BPT\types\chat',
17
        'sender_business_bot' => 'BPT\types\user',
18
        'chat' => 'BPT\types\chat',
19
        'forward_from' => 'BPT\types\user',
20
        'forward_from_chat' => 'BPT\types\chat',
21
        'forward_origin' => 'BPT\types\messageOrigin',
22
        'reply_to_message' => 'BPT\types\message',
23
        'external_reply' => 'BPT\types\externalReplyInfo',
24
        'quote' => 'BPT\types\textQuote',
25
        'reply_to_story' => 'BPT\types\story',
26
        'via_bot' => 'BPT\types\user',
27
        'array' => [
28
            'entities' => 'BPT\types\messageEntity',
29
            'photo' => 'BPT\types\photoSize',
30
            'caption_entities' => 'BPT\types\messageEntity',
31
            'new_chat_members' => 'BPT\types\user',
32
            'new_chat_photo' => 'BPT\types\photoSize',
33
        ],
34
        'link_preview_options' => 'BPT\types\linkPreviewOptions',
35
        'animation' => 'BPT\types\animation',
36
        'audio' => 'BPT\types\audio',
37
        'document' => 'BPT\types\document',
38
        'sticker' => 'BPT\types\sticker',
39
        'story' => 'BPT\types\story',
40
        'video' => 'BPT\types\video',
41
        'video_note' => 'BPT\types\videoNote',
42
        'voice' => 'BPT\types\voice',
43
        'contact' => 'BPT\types\contact',
44
        'dice' => 'BPT\types\dice',
45
        'game' => 'BPT\types\game',
46
        'poll' => 'BPT\types\poll',
47
        'venue' => 'BPT\types\venue',
48
        'location' => 'BPT\types\location',
49
        'left_chat_member' => 'BPT\types\user',
50
        'message_auto_delete_timer_changed' => 'BPT\types\messageAutoDeleteTimerChanged',
51
        'pinned_message' => 'BPT\types\maybeInaccessibleMessage',
52
        'invoice' => 'BPT\types\invoice',
53
        'successful_payment' => 'BPT\types\successfulPayment',
54
        'users_shared' => 'BPT\types\usersShared',
55
        'user_shared' => 'BPT\types\userShared',
56
        'chat_shared' => 'BPT\types\chatShared',
57
        'write_access_allowed' => 'BPT\types\writeAccessAllowed',
58
        'passport_data' => 'BPT\types\passportData',
59
        'proximity_alert_triggered' => 'BPT\types\proximityAlertTriggered',
60
        'boost_added' => 'BPT\types\chatBoostAdded',
61
        'chat_background_set' => 'BPT\types\chatBackground',
62
        'forum_topic_created' => 'BPT\types\forumTopicCreated',
63
        'forum_topic_edited' => 'BPT\types\forumTopicEdited',
64
        'forum_topic_closed' => 'BPT\types\forumTopicClosed',
65
        'forum_topic_reopened' => 'BPT\types\forumTopicReopened',
66
        'general_forum_topic_hidden' => 'BPT\types\generalForumTopicHidden',
67
        'general_forum_topic_unhidden' => 'BPT\types\generalForumTopicUnhidden',
68
        'giveaway_created' => 'BPT\types\giveawayCreated',
69
        'giveaway' => 'BPT\types\giveaway',
70
        'giveaway_winners' => 'BPT\types\giveawayWinners',
71
        'giveaway_completed' => 'BPT\types\giveawayCompleted',
72
        'video_chat_scheduled' => 'BPT\types\videoChatScheduled',
73
        'video_chat_started' => 'BPT\types\videoChatStarted',
74
        'video_chat_ended' => 'BPT\types\videoChatEnded',
75
        'video_chat_participants_invited' => 'BPT\types\videoChatParticipantsInvited',
76
        'web_app_data' => 'BPT\types\webAppData',
77
        'reply_markup' => 'BPT\types\inlineKeyboardMarkup',
78
    ];
79
80
    /** Unique message identifier inside this chat */
81
    public int $id;
82
83
    /** Unique message identifier inside this chat */
84
    public int $message_id;
85
86
    /** Optional. Unique identifier of a message thread to which the message belongs; for supergroups only */
87
    public null|int $message_thread_id = null;
88
89
    /**
90
     * Optional. Sender of the message; empty for messages sent to channels. For backward compatibility, the field
91
     * contains a fake sender user in non-channel chats, if the message was sent on behalf of a chat.
92
     */
93
    public null|user $from = null;
94
95
    /**
96
     * Optional. Sender of the message, sent on behalf of a chat. For example, the channel itself for channel posts,
97
     * the supergroup itself for messages from anonymous group administrators, the linked channel for messages
98
     * automatically forwarded to the discussion group. For backward compatibility, the field from contains a fake
99
     * sender user in non-channel chats, if the message was sent on behalf of a chat.
100
     */
101
    public null|chat $sender_chat = null;
102
103
    /** Optional. If the sender of the message boosted the chat, the number of boosts added by the user */
104
    public null|int $sender_boost_count = null;
105
106
    /**
107
     * Optional. The bot that actually sent the message on behalf of the business account. Available only for
108
     * outgoing messages sent on behalf of the connected business account.
109
     */
110
    public null|user $sender_business_bot = null;
111
112
    /** Date the message was sent in Unix time. It is always a positive number, representing a valid date. */
113
    public int $date;
114
115
    /**
116
     * Optional. Unique identifier of the business connection from which the message was received. If non-empty, the
117
     * message belongs to a chat of the corresponding business account that is independent from any potential bot
118
     * chat which might share the same identifier.
119
     */
120
    public null|string $business_connection_id = null;
121
122
    /** Chat the message belongs to */
123
    public chat $chat;
124
125
    /**
126
     * Optional. For forwarded messages, sender of the original message
127
     *
128
     * @deprecated used forward_origin instead
129
     */
130
    public null|user $forward_from = null;
131
132
    /**
133
     * Optional. For messages forwarded from channels or from anonymous administrators, information about the
134
     * original sender chat
135
     *
136
     * @deprecated used forward_origin instead
137
     */
138
    public null|chat $forward_from_chat = null;
139
140
    /**
141
     * Optional. For messages forwarded from channels, identifier of the original message in the channel
142
     *
143
     * @deprecated used forward_origin instead
144
     */
145
    public null|int $forward_from_message_id = null;
146
147
    /**
148
     * Optional. For forwarded messages that were originally sent in channels or by an anonymous chat administrator,
149
     * signature of the message sender if present
150
     *
151
     * @deprecated used forward_origin instead
152
     */
153
    public null|string $forward_signature = null;
154
155
    /**
156
     * Optional. Sender's name for messages forwarded from users who disallow adding a link to their account in
157
     * forwarded messages
158
     *
159
     * @deprecated used forward_origin instead
160
     */
161
    public null|string $forward_sender_name = null;
162
163
    /**
164
     * Optional. For forwarded messages, date the original message was sent in Unix time
165
     * @deprecated used forward_origin instead
166
     */
167
    public null|int $forward_date = null;
168
169
    /** Optional. Information about the original message for forwarded messages */
170
    public null|messageOrigin $forward_origin = null;
171
172
    /** Optional. True, if the message is sent to a forum topic */
173
    public null|bool $is_topic_message = null;
174
175
    /**
176
     * Optional. True, if the message is a channel post that was automatically forwarded to the connected discussion
177
     * group
178
     */
179
    public null|bool $is_automatic_forward = null;
180
181
    /**
182
     * Optional. For replies in the same chat and message thread, the original message. Note that the Message object
183
     * in this field will not contain further reply_to_message fields even if it itself is a reply.
184
     */
185
    public null|message $reply_to_message = null;
186
187
    /**
188
     * Optional. Information about the message that is being replied to, which may come from another chat or forum
189
     * topic
190
     */
191
    public null|externalReplyInfo $external_reply = null;
192
193
    /** Optional. For replies that quote part of the original message, the quoted part of the message */
194
    public null|textQuote $quote = null;
195
196
    /** Optional. For replies to a story, the original story */
197
    public null|story $reply_to_story = null;
198
199
    /** Optional. Bot through which the message was sent */
200
    public null|user $via_bot = null;
201
202
    /** Optional. Date the message was last edited in Unix time */
203
    public null|int $edit_date = null;
204
205
    /** Optional. True, if the message can't be forwarded */
206
    public null|bool $has_protected_content = null;
207
208
    /**
209
     * Optional. True, if the message was sent by an implicit action, for example, as an away or a greeting business
210
     * message, or as a scheduled message
211
     */
212
    public null|bool $is_from_offline = null;
213
214
    /** Optional. The unique identifier of a media message group this message belongs to */
215
    public null|string $media_group_id = null;
216
217
    /**
218
     * Optional. Signature of the post author for messages in channels, or the custom title of an anonymous group
219
     * administrator
220
     */
221
    public null|string $author_signature = null;
222
223
    /** Optional. For text messages, the actual UTF-8 text of the message */
224
    public null|string $text = null;
225
226
    /** Optional. If user message was a command , this parameter will be the command */
227
    public string|null $command = null;
228
229
    /** Optional. If user message was a command , this parameter will be the command username(if exist) */
230
    public string|null $command_username = null;
231
232
    /** Optional. If user message was a command , this parameter will be the command payload(if exist) */
233
    public string|null $command_payload = null;
234
235
    /**
236
     * Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text
237
     * @var messageEntity[]
238
     */
239
    public null|array $entities = null;
240
241
    /**
242
     * Optional. Options used for link preview generation for the message, if it is a text message and link preview
243
     * options were changed
244
     */
245
    public null|linkPreviewOptions $link_preview_options = null;
246
247
    /**
248
     * Optional. Message is an animation, information about the animation. For backward compatibility, when this
249
     * field is set, the document field will also be set
250
     */
251
    public null|animation $animation = null;
252
253
    /** Optional. Message is an audio file, information about the file */
254
    public null|audio $audio = null;
255
256
    /** Optional. Message is a general file, information about the file */
257
    public null|document $document = null;
258
259
    /**
260
     * Optional. Message is a photo, available sizes of the photo
261
     * @var photoSize[]
262
     */
263
    public null|array $photo = null;
264
265
    /** Optional. Message is a sticker, information about the sticker */
266
    public null|sticker $sticker = null;
267
268
    /** Optional. Message is a forwarded story */
269
    public null|story $story = null;
270
271
    /** Optional. Message is a video, information about the video */
272
    public null|video $video = null;
273
274
    /** Optional. Message is a video note, information about the video message */
275
    public null|videoNote $video_note = null;
276
277
    /** Optional. Message is a voice message, information about the file */
278
    public null|voice $voice = null;
279
280
    /** Optional. Caption for the animation, audio, document, photo, video or voice */
281
    public null|string $caption = null;
282
283
    /**
284
     * Optional. For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear
285
     * in the caption
286
     * @var messageEntity[]
287
     */
288
    public null|array $caption_entities = null;
289
290
    /** Optional. True, if the message media is covered by a spoiler animation */
291
    public null|bool $has_media_spoiler = null;
292
293
    /** Optional. Message is a shared contact, information about the contact */
294
    public null|contact $contact = null;
295
296
    /** Optional. Message is a dice with random value */
297
    public null|dice $dice = null;
298
299
    /** Optional. Message is a game, information about the game. More about games » */
300
    public null|game $game = null;
301
302
    /** Optional. Message is a native poll, information about the poll */
303
    public null|poll $poll = null;
304
305
    /**
306
     * Optional. Message is a venue, information about the venue. For backward compatibility, when this field is set,
307
     * the location field will also be set
308
     */
309
    public null|venue $venue = null;
310
311
    /** Optional. Message is a shared location, information about the location */
312
    public null|location $location = null;
313
314
    /**
315
     * Optional. New members that were added to the group or supergroup and information about them (the bot itself
316
     * may be one of these members)
317
     * @var user[]
318
     */
319
    public null|array $new_chat_members = null;
320
321
    /** Optional. A member was removed from the group, information about them (this member may be the bot itself) */
322
    public null|user $left_chat_member = null;
323
324
    /** Optional. A chat title was changed to this value */
325
    public null|string $new_chat_title = null;
326
327
    /**
328
     * Optional. A chat photo was change to this value
329
     * @var photoSize[]
330
     */
331
    public null|array $new_chat_photo = null;
332
333
    /** Optional. Service message: the chat photo was deleted */
334
    public null|bool $delete_chat_photo = null;
335
336
    /** Optional. Service message: the group has been created */
337
    public null|bool $group_chat_created = null;
338
339
    /**
340
     * Optional. Service message: the supergroup has been created. This field can't be received in a message coming
341
     * through updates, because bot can't be a member of a supergroup when it is created. It can only be found in
342
     * reply_to_message if someone replies to a very first message in a directly created supergroup.
343
     */
344
    public null|bool $supergroup_chat_created = null;
345
346
    /**
347
     * Optional. Service message: the channel has been created. This field can't be received in a message coming
348
     * through updates, because bot can't be a member of a channel when it is created. It can only be found in
349
     * reply_to_message if someone replies to a very first message in a channel.
350
     */
351
    public null|bool $channel_chat_created = null;
352
353
    /** Optional. Service message: auto-delete timer settings changed in the chat */
354
    public null|messageAutoDeleteTimerChanged $message_auto_delete_timer_changed = null;
355
356
    /**
357
     * Optional. The group has been migrated to a supergroup with the specified identifier. This number may have more
358
     * than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it.
359
     * But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for
360
     * storing this identifier.
361
     */
362
    public null|int $migrate_to_chat_id = null;
363
364
    /**
365
     * Optional. The supergroup has been migrated from a group with the specified identifier. This number may have
366
     * more than 32 significant bits and some programming languages may have difficulty/silent defects in
367
     * interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float
368
     * type are safe for storing this identifier.
369
     */
370
    public null|int $migrate_from_chat_id = null;
371
372
    /**
373
     * Optional. Specified message was pinned. Note that the Message object in this field will not contain further
374
     * reply_to_message fields even if it is itself a reply.
375
     */
376
    public null|maybeInaccessibleMessage $pinned_message = null;
377
378
    /** Optional. Message is an invoice for a payment, information about the invoice. More about payments » */
379
    public null|invoice $invoice = null;
380
381
    /**
382
     * Optional. Message is a service message about a successful payment, information about the payment. More about
383
     * payments »
384
     */
385
    public null|successfulPayment $successful_payment = null;
386
387
    /** Optional. Service message: users were shared with the bot */
388
    public null|usersShared $users_shared = null;
389
390
    /**
391
     * Optional. Service message: a user was shared with the bot
392
     *
393
     * This is a legacy property, and could be removed in the future
394
     *
395
     * @deprecated use users_shared instead
396
     */
397
    public null|userShared $user_shared = null;
398
399
    /** Optional. Service message: a chat was shared with the bot */
400
    public null|chatShared $chat_shared = null;
401
402
    /** Optional. The domain name of the website on which the user has logged in. More about Telegram Login » */
403
    public null|string $connected_website = null;
404
405
    /**
406
     * Optional. Service message: the user allowed the bot to write messages after adding it to the attachment or
407
     * side menu, launching a Web App from a link, or accepting an explicit request from a Web App sent by the method
408
     * requestWriteAccess
409
     */
410
    public null|writeAccessAllowed $write_access_allowed = null;
411
412
    /** Optional. Telegram Passport data */
413
    public null|passportData $passport_data = null;
414
415
    /**
416
     * Optional. Service message. A user in the chat triggered another user's proximity alert while sharing Live
417
     * Location.
418
     */
419
    public null|proximityAlertTriggered $proximity_alert_triggered = null;
420
421
    /** Optional. Service message: user boosted the chat */
422
    public null|chatBoostAdded $boost_added = null;
423
424
    /** Optional. Service message: chat background set */
425
    public null|chatBackground $chat_background_set = null;
426
427
    /** Optional. Service message: forum topic created */
428
    public null|forumTopicCreated $forum_topic_created = null;
429
430
    /** Optional. Service message: forum topic edited */
431
    public null|forumTopicEdited $forum_topic_edited = null;
432
433
    /** Optional. Service message: forum topic closed */
434
    public null|forumTopicClosed $forum_topic_closed = null;
435
436
    /** Optional. Service message: forum topic reopened */
437
    public null|forumTopicReopened $forum_topic_reopened = null;
438
439
    /** Optional. Service message: the 'General' forum topic hidden */
440
    public null|generalForumTopicHidden $general_forum_topic_hidden = null;
441
442
    /** Optional. Service message: the 'General' forum topic unhidden */
443
    public null|generalForumTopicUnhidden $general_forum_topic_unhidden = null;
444
445
    /** Optional. Service message: a scheduled giveaway was created */
446
    public null|giveawayCreated $giveaway_created = null;
447
448
    /** Optional. The message is a scheduled giveaway message */
449
    public null|giveaway $giveaway = null;
450
451
    /** Optional. A giveaway with public winners was completed */
452
    public null|giveawayWinners $giveaway_winners = null;
453
454
    /** Optional. Service message: a giveaway without public winners was completed */
455
    public null|giveawayCompleted $giveaway_completed = null;
456
457
    /** Optional. Service message: video chat scheduled */
458
    public null|videoChatScheduled $video_chat_scheduled = null;
459
460
    /** Optional. Service message: video chat started */
461
    public null|videoChatStarted $video_chat_started = null;
462
463
    /** Optional. Service message: video chat ended */
464
    public null|videoChatEnded $video_chat_ended = null;
465
466
    /** Optional. Service message: new participants invited to a video chat */
467
    public null|videoChatParticipantsInvited $video_chat_participants_invited = null;
468
469
    /** Optional. Service message: data sent by a Web App */
470
    public null|webAppData $web_app_data = null;
471
472
    /** Optional. Inline keyboard attached to the message. login_url buttons are represented as ordinary url buttons. */
473
    public null|inlineKeyboardMarkup $reply_markup = null;
474
475
476
    public function __construct(stdClass|null $object = null) {
477
        if ($object != null) {
478
            parent::__construct($object, self::subs);
479
        }
480
    }
481
482
    /**
483
     * Is it a command message or not
484
     *
485
     * @return bool
486
     */
487
    public function isCommand (): bool {
488
        return !empty($this->command);
489
    }
490
491
    /**
492
     * Is it forwarded or not
493
     *
494
     * @return bool
495
     */
496
    public function isForwarded (): bool {
497
        return $this->forward_origin !== null;
498
    }
499
500
    /**
501
     * Is it replied or not
502
     *
503
     * @return bool
504
     */
505
    public function isReplied (): bool {
506
        return !empty($this->reply_to_message);
507
    }
508
509
    /**
510
     * Is user admin of the chat or not
511
     *
512
     * Only in not private chat
513
     *
514
     * @return bool
515
     */
516
    public function isAdmin (): bool {
517
        return $this->chat->getMember($this->from->id)->status === chatMemberStatus::ADMINISTRATOR;
518
    }
519
520
    /**
521
     * Is user owner of the chat or not
522
     *
523
     * Only in not private chat
524
     *
525
     * @return bool
526
     */
527
    public function isOwner (): bool {
528
        return $this->chat->getMember($this->from->id)->status === chatMemberStatus::CREATOR;
529
    }
530
531
    /**
532
     * Ban member from this chat
533
     *
534
     * return false in private chats
535
     *
536
     * @param bool|null $answer
537
     *
538
     * @return responseError|bool
539
     */
540
    public function banMember(bool $answer = null): responseError|bool {
541
        if ($this->chat->isPrivate()) {
542
            return false;
543
        }
544
        return telegram::banChatMember($this->chat->id, $this->from->id, answer: $answer);
545
    }
546
547
    /**
548
     * kick member from this chat
549
     *
550
     * return false in private chats
551
     *
552
     * @param bool|null $answer
553
     *
554
     * @return responseError|bool
555
     */
556
    public function kickMember(bool $answer = null): responseError|bool {
557
        if ($this->chat->isPrivate()) {
558
            return false;
559
        }
560
        return telegram::unbanChatMember($this->chat->id, $this->from->id, answer: $answer);
561
    }
562
563
    /**
564
     * Delete this message
565
     *
566
     * @param bool|null $answer
567
     *
568
     * @return responseError|bool
569
     */
570
    public function delete (bool $answer = null): responseError|bool {
571
        return telegram::deleteMessage($this->chat->id,$this->id, answer: $answer);
572
    }
573
574
    /**
575
     * Pin this message
576
     *
577
     * @param bool|null $answer
578
     *
579
     * @return responseError|bool
580
     */
581
    public function pinChatMessage (bool $answer = null): responseError|bool {
582
        return telegram::deleteMessage($this->chat->id,$this->id, answer: $answer);
583
    }
584
585
    /**
586
     * Edit message text(Only for bot messages or channel messages)
587
     *
588
     * @param string    $text
589
     * @param bool|null $answer
590
     *
591
     * @return message|responseError|bool
592
     */
593
    public function editText (string $text, bool $answer = null): message|responseError|bool {
594
        return telegram::editMessageText($text,  $this->chat->id, $this->message_id, answer: $answer);
595
    }
596
597
    /**
598
     * Copy this message(Anonymous forward)
599
     *
600
     * @param int|string $chat_id
601
     * @param bool|null  $answer
602
     *
603
     * @return messageId|responseError
604
     */
605
    public function copy (int|string $chat_id, bool $answer = null): messageId|responseError {
606
        return telegram::copyMessage($chat_id, answer: $answer);
607
    }
608
609
    /**
610
     * Forward this message
611
     *
612
     * @param int|string $chat_id
613
     * @param bool|null  $answer
614
     *
615
     * @return message|responseError
616
     */
617
    public function forward (int|string $chat_id, bool $answer = null): message|responseError {
618
        return telegram::forwardMessage($chat_id, answer: $answer);
619
    }
620
}
621