Passed
Push — main ( 1f3d08...95c480 )
by Miaad
10:28
created

message::isCommand()   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 of properties which has sub properties */
14
    private const subs = [
15
        'from' => 'BPT\types\user',
16
        'sender_chat' => 'BPT\types\chat',
17
        'chat' => 'BPT\types\chat',
18
        'forward_from' => 'BPT\types\user',
19
        'forward_from_chat' => 'BPT\types\chat',
20
        'reply_to_message' => 'BPT\types\message',
21
        'via_bot' => 'BPT\types\user',
22
        'array' => [
23
            'entities' => 'BPT\types\messageEntity',
24
            'photo' => 'BPT\types\photoSize',
25
            'caption_entities' => 'BPT\types\messageEntity',
26
            'new_chat_members' => 'BPT\types\user',
27
            'new_chat_photo' => 'BPT\types\photoSize',
28
        ],
29
        'animation' => 'BPT\types\animation',
30
        'audio' => 'BPT\types\audio',
31
        'document' => 'BPT\types\document',
32
        'sticker' => 'BPT\types\sticker',
33
        'video' => 'BPT\types\video',
34
        'video_note' => 'BPT\types\videoNote',
35
        'voice' => 'BPT\types\voice',
36
        'contact' => 'BPT\types\contact',
37
        'dice' => 'BPT\types\dice',
38
        'game' => 'BPT\types\game',
39
        'poll' => 'BPT\types\poll',
40
        'venue' => 'BPT\types\venue',
41
        'location' => 'BPT\types\location',
42
        'left_chat_member' => 'BPT\types\user',
43
        'message_auto_delete_timer_changed' => 'BPT\types\messageAutoDeleteTimerChanged',
44
        'pinned_message' => 'BPT\types\message',
45
        'invoice' => 'BPT\types\invoice',
46
        'successful_payment' => 'BPT\types\successfulPayment',
47
        'passport_data' => 'BPT\types\passportData',
48
        'proximity_alert_triggered' => 'BPT\types\proximityAlertTriggered',
49
        'forum_topic_created' => 'BPT\types\forumTopicCreated',
50
        'forum_topic_closed' => 'BPT\types\forumTopicClosed',
51
        'forum_topic_reopened' => 'BPT\types\forumTopicReopened',
52
        'video_chat_scheduled' => 'BPT\types\videoChatScheduled',
53
        'video_chat_started' => 'BPT\types\videoChatStarted',
54
        'video_chat_ended' => 'BPT\types\videoChatEnded',
55
        'video_chat_participants_invited' => 'BPT\types\videoChatParticipantsInvited',
56
        'web_app_data' => 'BPT\types\webAppData',
57
        'reply_markup' => 'BPT\types\inlineKeyboardMarkup',
58
    ];
59
60
    /** Unique message identifier inside this chat */
61
    public int $id;
62
63
    /** Unique message identifier inside this chat */
64
    public int $message_id;
65
66
    /** Optional. Unique identifier of a message thread to which the message belongs; for supergroups only */
67
    public null|int $message_thread_id = null;
68
69
    /**
70
     * Optional. Sender of the message; empty for messages sent to channels. For backward compatibility, the field
71
     * contains a fake sender user in non-channel chats, if the message was sent on behalf of a chat.
72
     */
73
    public null|user $from = null;
74
75
    /**
76
     * Optional. Sender of the message, sent on behalf of a chat. For example, the channel itself for channel posts,
77
     * the supergroup itself for messages from anonymous group administrators, the linked channel for messages
78
     * automatically forwarded to the discussion group. For backward compatibility, the field from contains a fake
79
     * sender user in non-channel chats, if the message was sent on behalf of a chat.
80
     */
81
    public null|chat $sender_chat = null;
82
83
    /** Date the message was sent in Unix time */
84
    public int $date;
85
86
    /** Conversation the message belongs to */
87
    public chat $chat;
88
89
    /** Optional. For forwarded messages, sender of the original message */
90
    public null|user $forward_from = null;
91
92
    /**
93
     * Optional. For messages forwarded from channels or from anonymous administrators, information about the
94
     * original sender chat
95
     */
96
    public null|chat $forward_from_chat = null;
97
98
    /** Optional. For messages forwarded from channels, identifier of the original message in the channel */
99
    public null|int $forward_from_message_id = null;
100
101
    /**
102
     * Optional. For forwarded messages that were originally sent in channels or by an anonymous chat administrator,
103
     * signature of the message sender if present
104
     */
105
    public null|string $forward_signature = null;
106
107
    /**
108
     * Optional. Sender's name for messages forwarded from users who disallow adding a link to their account in
109
     * forwarded messages
110
     */
111
    public null|string $forward_sender_name = null;
112
113
    /** Optional. For forwarded messages, date the original message was sent in Unix time */
114
    public null|int $forward_date = null;
115
116
    /** Optional. True, if the message is sent to a forum topic */
117
    public null|bool $is_topic_message = null;
118
119
    /**
120
     * Optional. True, if the message is a channel post that was automatically forwarded to the connected discussion
121
     * group
122
     */
123
    public null|bool $is_automatic_forward = null;
124
125
    /**
126
     * Optional. For replies, the original message. Note that the Message object in this field will not contain
127
     * further reply_to_message fields even if it itself is a reply.
128
     */
129
    public null|message $reply_to_message = null;
130
131
    /** Optional. Bot through which the message was sent */
132
    public null|user $via_bot = null;
133
134
    /** Optional. Date the message was last edited in Unix time */
135
    public null|int $edit_date = null;
136
137
    /** Optional. True, if the message can't be forwarded */
138
    public null|bool $has_protected_content = null;
139
140
    /** Optional. The unique identifier of a media message group this message belongs to */
141
    public null|string $media_group_id = null;
142
143
    /**
144
     * Optional. Signature of the post author for messages in channels, or the custom title of an anonymous group
145
     * administrator
146
     */
147
    public null|string $author_signature = null;
148
149
    /** Optional. For text messages, the actual UTF-8 text of the message */
150
    public null|string $text = null;
151
152
    /** Optional. If user message was a command , this parameter will be the command */
153
    public string|null $command = null;
154
155
    /** Optional. If user message was a command , this parameter will be the command username(if exist) */
156
    public string|null $command_username = null;
157
158
    /** Optional. If user message was a command , this parameter will be the command payload(if exist) */
159
    public string|null $command_payload = null;
160
161
    /**
162
     * Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text
163
     * @var messageEntity[]
164
     */
165
    public null|array $entities = null;
166
167
    /**
168
     * Optional. Message is an animation, information about the animation. For backward compatibility, when this
169
     * field is set, the document field will also be set
170
     */
171
    public null|animation $animation = null;
172
173
    /** Optional. Message is an audio file, information about the file */
174
    public null|audio $audio = null;
175
176
    /** Optional. Message is a general file, information about the file */
177
    public null|document $document = null;
178
179
    /**
180
     * Optional. Message is a photo, available sizes of the photo
181
     * @var photoSize[]
182
     */
183
    public null|array $photo = null;
184
185
    /** Optional. Message is a sticker, information about the sticker */
186
    public null|sticker $sticker = null;
187
188
    /** Optional. Message is a video, information about the video */
189
    public null|video $video = null;
190
191
    /** Optional. Message is a video note, information about the video message */
192
    public null|videoNote $video_note = null;
193
194
    /** Optional. Message is a voice message, information about the file */
195
    public null|voice $voice = null;
196
197
    /** Optional. Caption for the animation, audio, document, photo, video or voice */
198
    public null|string $caption = null;
199
200
    /**
201
     * Optional. For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear
202
     * in the caption
203
     * @var messageEntity[]
204
     */
205
    public null|array $caption_entities = null;
206
207
    /** Optional. True, if the message media is covered by a spoiler animation */
208
    public null|bool $has_media_spoiler = null;
209
210
    /** Optional. Message is a shared contact, information about the contact */
211
    public null|contact $contact = null;
212
213
    /** Optional. Message is a dice with random value */
214
    public null|dice $dice = null;
215
216
    /** Optional. Message is a game, information about the game. More about games » */
217
    public null|game $game = null;
218
219
    /** Optional. Message is a native poll, information about the poll */
220
    public null|poll $poll = null;
221
222
    /**
223
     * Optional. Message is a venue, information about the venue. For backward compatibility, when this field is set,
224
     * the location field will also be set
225
     */
226
    public null|venue $venue = null;
227
228
    /** Optional. Message is a shared location, information about the location */
229
    public null|location $location = null;
230
231
    /**
232
     * Optional. New members that were added to the group or supergroup and information about them (the bot itself
233
     * may be one of these members)
234
     * @var user[]
235
     */
236
    public null|array $new_chat_members = null;
237
238
    /** Optional. A member was removed from the group, information about them (this member may be the bot itself) */
239
    public null|user $left_chat_member = null;
240
241
    /** Optional. A chat title was changed to this value */
242
    public null|string $new_chat_title = null;
243
244
    /**
245
     * Optional. A chat photo was change to this value
246
     * @var photoSize[]
247
     */
248
    public null|array $new_chat_photo = null;
249
250
    /** Optional. Service message: the chat photo was deleted */
251
    public null|bool $delete_chat_photo = null;
252
253
    /** Optional. Service message: the group has been created */
254
    public null|bool $group_chat_created = null;
255
256
    /**
257
     * Optional. Service message: the supergroup has been created. This field can't be received in a message coming
258
     * through updates, because bot can't be a member of a supergroup when it is created. It can only be found in
259
     * reply_to_message if someone replies to a very first message in a directly created supergroup.
260
     */
261
    public null|bool $supergroup_chat_created = null;
262
263
    /**
264
     * Optional. Service message: the channel has been created. This field can't be received in a message coming
265
     * through updates, because bot can't be a member of a channel when it is created. It can only be found in
266
     * reply_to_message if someone replies to a very first message in a channel.
267
     */
268
    public null|bool $channel_chat_created = null;
269
270
    /** Optional. Service message: auto-delete timer settings changed in the chat */
271
    public null|messageAutoDeleteTimerChanged $message_auto_delete_timer_changed = null;
272
273
    /**
274
     * Optional. The group has been migrated to a supergroup with the specified identifier. This number may have more
275
     * than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it.
276
     * But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for
277
     * storing this identifier.
278
     */
279
    public null|int $migrate_to_chat_id = null;
280
281
    /**
282
     * Optional. The supergroup has been migrated from a group with the specified identifier. This number may have
283
     * more than 32 significant bits and some programming languages may have difficulty/silent defects in
284
     * interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float
285
     * type are safe for storing this identifier.
286
     */
287
    public null|int $migrate_from_chat_id = null;
288
289
    /**
290
     * Optional. Specified message was pinned. Note that the Message object in this field will not contain further
291
     * reply_to_message fields even if it is itself a reply.
292
     */
293
    public null|message $pinned_message = null;
294
295
    /** Optional. Message is an invoice for a payment, information about the invoice. More about payments » */
296
    public null|invoice $invoice = null;
297
298
    /**
299
     * Optional. Message is a service message about a successful payment, information about the payment. More about
300
     * payments »
301
     */
302
    public null|successfulPayment $successful_payment = null;
303
304
    /** Optional. The domain name of the website on which the user has logged in. More about Telegram Login » */
305
    public null|string $connected_website = null;
306
307
    /** Optional. Service message: the user allowed the bot added to the attachment menu to write messages */
308
    public null|writeAccessAllowed $write_access_allowed = null;
309
310
    /** Optional. Telegram Passport data */
311
    public null|passportData $passport_data = null;
312
313
    /**
314
     * Optional. Service message. A user in the chat triggered another user's proximity alert while sharing Live
315
     * Location.
316
     */
317
    public null|proximityAlertTriggered $proximity_alert_triggered = null;
318
319
    /** Optional. Service message: forum topic created */
320
    public null|forumTopicCreated $forum_topic_created = null;
321
322
    /** Optional. Service message: forum topic edited */
323
    public null|forumTopicEdited $forum_topic_edited = null;
324
325
    /** Optional. Service message: forum topic closed */
326
    public null|forumTopicClosed $forum_topic_closed = null;
327
328
    /** Optional. Service message: forum topic reopened */
329
    public null|forumTopicReopened $forum_topic_reopened = null;
330
331
    /** Optional. Service message: the 'General' forum topic hidden */
332
    public null|generalForumTopicHidden $general_forum_topic_hidden = null;
333
334
    /** Optional. Service message: the 'General' forum topic unhidden */
335
    public null|generalForumTopicUnhidden $general_forum_topic_unhidden = null;
336
337
    /** Optional. Service message: video chat scheduled */
338
    public null|videoChatScheduled $video_chat_scheduled = null;
339
340
    /** Optional. Service message: video chat started */
341
    public null|videoChatStarted $video_chat_started = null;
342
343
    /** Optional. Service message: video chat ended */
344
    public null|videoChatEnded $video_chat_ended = null;
345
346
    /** Optional. Service message: new participants invited to a video chat */
347
    public null|videoChatParticipantsInvited $video_chat_participants_invited = null;
348
349
    /** Optional. Service message: data sent by a Web App */
350
    public null|webAppData $web_app_data = null;
351
352
    /** Optional. Inline keyboard attached to the message. login_url buttons are represented as ordinary url buttons. */
353
    public null|inlineKeyboardMarkup $reply_markup = null;
354
355
356
    public function __construct(stdClass|null $object = null) {
357
        if ($object != null) {
358
            parent::__construct($object, self::subs);
359
        }
360
    }
361
362
    public function isCommand (): bool {
363
        return !empty($this->command);
364
    }
365
366
    public function isForwarded (): bool {
367
        return $this->forward_from !== null || $this->forward_from_chat !== null;
368
    }
369
370
    public function isAdmin (): bool {
371
        return $this->chat->getMember($this->from->id)->status === chatMemberStatus::ADMINISTRATOR;
372
    }
373
374
    public function isOwner (): bool {
375
        return $this->chat->getMember($this->from->id)->status === chatMemberStatus::CREATOR;
376
    }
377
378
    public function banMember(): responseError|bool {
379
        if ($this->chat->isPrivate()) {
380
            return false;
381
        }
382
        return telegram::banChatMember($this->chat->id, $this->from->id);
383
    }
384
385
    public function delete (): responseError|bool {
386
        return telegram::deleteMessage($this->chat->id,$this->id);
387
    }
388
389
    public function editText (string $text): message|responseError|bool {
390
        return telegram::editMessageText($text,$this->chat->id,$this->message_id);
391
    }
392
393
    public function copy (int|string $chat_id): messageId|responseError {
394
        return telegram::copyMessage($chat_id);
395
    }
396
397
    public function forward (int|string $chat_id): message|responseError {
398
        return telegram::forwardMessage($chat_id);
399
    }
400
}
401