14
14
15
15
use Longman \TelegramBot \Entities \CallbackQuery ;
16
16
use Longman \TelegramBot \Entities \Chat ;
17
+ use Longman \TelegramBot \Entities \ChatBoostRemoved ;
18
+ use Longman \TelegramBot \Entities \ChatBoostUpdated ;
17
19
use Longman \TelegramBot \Entities \ChatJoinRequest ;
18
20
use Longman \TelegramBot \Entities \ChatMemberUpdated ;
19
21
use Longman \TelegramBot \Entities \ChosenInlineResult ;
@@ -149,6 +151,8 @@ protected static function defineTables(): void
149
151
$ tables = [
150
152
'callback_query ' ,
151
153
'chat ' ,
154
+ 'chat_boost_updated ' ,
155
+ 'chat_boost_removed ' ,
152
156
'chat_join_request ' ,
153
157
'chat_member_updated ' ,
154
158
'chosen_inline_result ' ,
@@ -340,10 +344,12 @@ protected static function insertTelegramUpdate(
340
344
?string $ poll_answer_poll_id = null ,
341
345
?string $ my_chat_member_updated_id = null ,
342
346
?string $ chat_member_updated_id = null ,
343
- ?string $ chat_join_request_id = null
347
+ ?string $ chat_join_request_id = null ,
348
+ ?string $ chat_boost_updated_id = null ,
349
+ ?string $ chat_boost_removed_id = null
344
350
): ?bool {
345
- if ($ message_id === null && $ edited_message_id === null && $ channel_post_id === null && $ edited_channel_post_id === null && $ message_reaction_id === null && $ message_reaction_count_id === null && $ inline_query_id === null && $ chosen_inline_result_id === null && $ callback_query_id === null && $ shipping_query_id === null && $ pre_checkout_query_id === null && $ poll_id === null && $ poll_answer_poll_id === null && $ my_chat_member_updated_id === null && $ chat_member_updated_id === null && $ chat_join_request_id === null ) {
346
- throw new TelegramException ('message_id, edited_message_id, channel_post_id, edited_channel_post_id, message_reaction_id, message_reaction_count_id, inline_query_id, chosen_inline_result_id, callback_query_id, shipping_query_id, pre_checkout_query_id, poll_id, poll_answer_poll_id, my_chat_member_updated_id, chat_member_updated_id are all null ' );
351
+ if ($ message_id === null && $ edited_message_id === null && $ channel_post_id === null && $ edited_channel_post_id === null && $ message_reaction_id === null && $ message_reaction_count_id === null && $ inline_query_id === null && $ chosen_inline_result_id === null && $ callback_query_id === null && $ shipping_query_id === null && $ pre_checkout_query_id === null && $ poll_id === null && $ poll_answer_poll_id === null && $ my_chat_member_updated_id === null && $ chat_member_updated_id === null && $ chat_join_request_id === null && $ chat_boost_updated_id === null && $ chat_boost_removed_id === null ) {
352
+ throw new TelegramException ('message_id, edited_message_id, channel_post_id, edited_channel_post_id, message_reaction_id, message_reaction_count_id, inline_query_id, chosen_inline_result_id, callback_query_id, shipping_query_id, pre_checkout_query_id, poll_id, poll_answer_poll_id, my_chat_member_updated_id, chat_member_updated_id, chat_join_request_id, chat_boost_updated_id, chat_boost_removed_id are all null ' );
347
353
}
348
354
349
355
if (!self ::isDbConnected ()) {
@@ -359,14 +365,14 @@ protected static function insertTelegramUpdate(
359
365
`inline_query_id`, `chosen_inline_result_id`,
360
366
`callback_query_id`, `shipping_query_id`, `pre_checkout_query_id`,
361
367
`poll_id`, `poll_answer_poll_id`, `my_chat_member_updated_id`, `chat_member_updated_id`,
362
- `chat_join_request_id`
368
+ `chat_join_request_id`, `chat_boost_updated_id`, `chat_boost_removed_id`
363
369
) VALUES (
364
370
:id, :chat_id, :message_id, :edited_message_id,
365
371
:channel_post_id, :edited_channel_post_id, :message_reaction_id, :message_reaction_count_id,
366
372
:inline_query_id, :chosen_inline_result_id,
367
373
:callback_query_id, :shipping_query_id, :pre_checkout_query_id,
368
374
:poll_id, :poll_answer_poll_id, :my_chat_member_updated_id, :chat_member_updated_id,
369
- :chat_join_request_id
375
+ :chat_join_request_id, :chat_boost_updated_id, :chat_boost_removed_id
370
376
)
371
377
' );
372
378
@@ -388,6 +394,8 @@ protected static function insertTelegramUpdate(
388
394
$ sth ->bindValue (':my_chat_member_updated_id ' , $ my_chat_member_updated_id );
389
395
$ sth ->bindValue (':chat_member_updated_id ' , $ chat_member_updated_id );
390
396
$ sth ->bindValue (':chat_join_request_id ' , $ chat_join_request_id );
397
+ $ sth ->bindValue (':chat_boost_updated_id ' , $ chat_boost_updated_id );
398
+ $ sth ->bindValue (':chat_boost_removed_id ' , $ chat_boost_removed_id );
391
399
392
400
return $ sth ->execute ();
393
401
} catch (PDOException $ e ) {
@@ -561,6 +569,8 @@ public static function insertRequest(Update $update): bool
561
569
$ my_chat_member_updated_id = null ;
562
570
$ chat_member_updated_id = null ;
563
571
$ chat_join_request_id = null ;
572
+ $ chat_boost_updated_id = null ;
573
+ $ chat_boost_removed_id = null ;
564
574
565
575
if (($ message = $ update ->getMessage ()) && self ::insertMessageRequest ($ message )) {
566
576
$ chat_id = $ message ->getChat ()->getId ();
@@ -602,6 +612,10 @@ public static function insertRequest(Update $update): bool
602
612
$ chat_member_updated_id = self ::$ pdo ->lastInsertId ();
603
613
} elseif (($ chat_join_request = $ update ->getChatJoinRequest ()) && self ::insertChatJoinRequestRequest ($ chat_join_request )) {
604
614
$ chat_join_request_id = self ::$ pdo ->lastInsertId ();
615
+ } elseif (($ chat_boost_updated = $ update ->getChatBoost ()) && self ::insertChatBoostUpdatedRequest ($ chat_boost_updated )) {
616
+ $ chat_boost_updated_id = self ::$ pdo ->lastInsertId ();
617
+ } elseif (($ chat_boost_removed = $ update ->getRemovedChatBoost ()) && self ::insertChatBoostRemovedRequest ($ chat_boost_removed )) {
618
+ $ chat_boost_removed_id = self ::$ pdo ->lastInsertId ();
605
619
} else {
606
620
return false ;
607
621
}
@@ -624,7 +638,9 @@ public static function insertRequest(Update $update): bool
624
638
$ poll_answer_poll_id ,
625
639
$ my_chat_member_updated_id ,
626
640
$ chat_member_updated_id ,
627
- $ chat_join_request_id
641
+ $ chat_join_request_id ,
642
+ $ chat_boost_updated_id ,
643
+ $ chat_boost_removed_id
628
644
);
629
645
}
630
646
@@ -1143,6 +1159,88 @@ public static function insertChatJoinRequestRequest(ChatJoinRequest $chat_join_r
1143
1159
}
1144
1160
}
1145
1161
1162
+ /**
1163
+ * Insert chat boost updated into database
1164
+ *
1165
+ * @param ChatBoostUpdated $chat_boost_updated
1166
+ *
1167
+ * @return bool If the insert was successful
1168
+ * @throws TelegramException
1169
+ */
1170
+ public static function insertChatBoostUpdatedRequest (ChatBoostUpdated $ chat_boost_updated ): bool
1171
+ {
1172
+ if (!self ::isDbConnected ()) {
1173
+ return false ;
1174
+ }
1175
+
1176
+ try {
1177
+ $ sth = self ::$ pdo ->prepare ('
1178
+ INSERT INTO ` ' . TB_CHAT_BOOST_UPDATED . '`
1179
+ (`chat_id`, `boost`, `created_at`)
1180
+ VALUES
1181
+ (:chat_id, :boost, :created_at)
1182
+ ' );
1183
+
1184
+ $ date = self ::getTimestamp ();
1185
+ $ chat_id = null ;
1186
+
1187
+ if ($ chat = $ chat_boost_updated ->getChat ()) {
1188
+ $ chat_id = $ chat ->getId ();
1189
+ self ::insertChat ($ chat , $ date );
1190
+ }
1191
+
1192
+ $ sth ->bindValue (':chat_id ' , $ chat_id );
1193
+ $ sth ->bindValue (':boost ' , $ chat_boost_updated ->getBoost ());
1194
+ $ sth ->bindValue (':created_at ' , $ date );
1195
+
1196
+ return $ sth ->execute ();
1197
+ } catch (PDOException $ e ) {
1198
+ throw new TelegramException ($ e ->getMessage ());
1199
+ }
1200
+ }
1201
+
1202
+ /**
1203
+ * Insert chat boost removed into database
1204
+ *
1205
+ * @param ChatBoostRemoved $chat_boost_removed
1206
+ *
1207
+ * @return bool If the insert was successful
1208
+ * @throws TelegramException
1209
+ */
1210
+ public static function insertChatBoostRemovedRequest (ChatBoostRemoved $ chat_boost_removed ): bool
1211
+ {
1212
+ if (!self ::isDbConnected ()) {
1213
+ return false ;
1214
+ }
1215
+
1216
+ try {
1217
+ $ sth = self ::$ pdo ->prepare ('
1218
+ INSERT INTO ` ' . TB_CHAT_BOOST_REMOVED . '`
1219
+ (`chat_id`, `boost_id`, `remove_date`, `source`, `created_at`)
1220
+ VALUES
1221
+ (:chat_id, :boost_id, :remove_date, :source, :created_at)
1222
+ ' );
1223
+
1224
+ $ date = self ::getTimestamp ();
1225
+ $ chat_id = null ;
1226
+
1227
+ if ($ chat = $ chat_boost_removed ->getChat ()) {
1228
+ $ chat_id = $ chat ->getId ();
1229
+ self ::insertChat ($ chat , $ date );
1230
+ }
1231
+
1232
+ $ sth ->bindValue (':chat_id ' , $ chat_id );
1233
+ $ sth ->bindValue (':boost_id ' , $ chat_boost_removed ->getBoostId ());
1234
+ $ sth ->bindValue (':remove_date ' , self ::getTimestamp ($ chat_boost_removed ->getRemoveDate ()));
1235
+ $ sth ->bindValue (':source ' , $ chat_boost_removed ->getSource ());
1236
+ $ sth ->bindValue (':created_at ' , $ date );
1237
+
1238
+ return $ sth ->execute ();
1239
+ } catch (PDOException $ e ) {
1240
+ throw new TelegramException ($ e ->getMessage ());
1241
+ }
1242
+ }
1243
+
1146
1244
/**
1147
1245
* Insert Message request in db
1148
1246
*
0 commit comments