Passed
Push — main ( 64ea8c...cb0dfb )
by Miaad
10:02
created

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