@@ -3251,7 +3251,7 @@ def __init__(self, small_file_id, small_file_unique_id, big_file_id, big_file_un
3251
3251
self.big_file_unique_id: str = big_file_unique_id
3252
3252
3253
3253
3254
- class ChatMember(JsonDeserializable):
3254
+ class ChatMember(JsonDeserializable, ABC ):
3255
3255
"""
3256
3256
This object contains information about one member of a chat.
3257
3257
Currently, the following 6 types of chat members are supported:
@@ -3266,78 +3266,31 @@ class ChatMember(JsonDeserializable):
3266
3266
Telegram Documentation: https://core.telegram.org/bots/api#chatmember
3267
3267
"""
3268
3268
3269
+ def __init__(self, user, status, **kwargs):
3270
+ self.user: User = user
3271
+ self.status: str = status
3272
+
3269
3273
@classmethod
3270
3274
def de_json(cls, json_string):
3271
3275
if json_string is None: return None
3272
3276
obj = cls.check_json(json_string)
3273
3277
obj['user'] = User.de_json(obj['user'])
3274
- member_type = obj['status']
3278
+ status = obj['status']
3275
3279
# Ordered according to estimated appearance frequency.
3276
- if member_type == "member":
3280
+ if status == "member":
3277
3281
return ChatMemberMember(**obj)
3278
- elif member_type == "left":
3282
+ elif status == "left":
3279
3283
return ChatMemberLeft(**obj)
3280
- elif member_type == "kicked":
3284
+ elif status == "kicked":
3281
3285
return ChatMemberBanned(**obj)
3282
- elif member_type == "restricted":
3286
+ elif status == "restricted":
3283
3287
return ChatMemberRestricted(**obj)
3284
- elif member_type == "administrator":
3288
+ elif status == "administrator":
3285
3289
return ChatMemberAdministrator(**obj)
3286
- elif member_type == "creator":
3290
+ elif status == "creator":
3287
3291
return ChatMemberOwner(**obj)
3288
3292
else:
3289
- # Should not be here. For "if something happen" compatibility
3290
- return cls(**obj)
3291
-
3292
- def __init__(self, user, status, custom_title=None, is_anonymous=None, can_be_edited=None,
3293
- can_post_messages=None, can_edit_messages=None, can_delete_messages=None,
3294
- can_restrict_members=None, can_promote_members=None, can_change_info=None,
3295
- can_invite_users=None, can_pin_messages=None, is_member=None,
3296
- can_send_messages=None, can_send_audios=None, can_send_documents=None,
3297
- can_send_photos=None, can_send_videos=None, can_send_video_notes=None,
3298
- can_send_voice_notes=None,
3299
- can_send_polls=None,
3300
- can_send_other_messages=None, can_add_web_page_previews=None,
3301
- can_manage_chat=None, can_manage_video_chats=None,
3302
- until_date=None, can_manage_topics=None,
3303
- can_post_stories=None, can_edit_stories=None, can_delete_stories=None,
3304
- **kwargs):
3305
- self.user: User = user
3306
- self.status: str = status
3307
- self.custom_title: str = custom_title
3308
- self.is_anonymous: bool = is_anonymous
3309
- self.can_be_edited: bool = can_be_edited
3310
- self.can_post_messages: bool = can_post_messages
3311
- self.can_edit_messages: bool = can_edit_messages
3312
- self.can_delete_messages: bool = can_delete_messages
3313
- self.can_restrict_members: bool = can_restrict_members
3314
- self.can_promote_members: bool = can_promote_members
3315
- self.can_change_info: bool = can_change_info
3316
- self.can_invite_users: bool = can_invite_users
3317
- self.can_pin_messages: bool = can_pin_messages
3318
- self.is_member: bool = is_member
3319
- self.can_send_messages: bool = can_send_messages
3320
- self.can_send_polls: bool = can_send_polls
3321
- self.can_send_other_messages: bool = can_send_other_messages
3322
- self.can_add_web_page_previews: bool = can_add_web_page_previews
3323
- self.can_manage_chat: bool = can_manage_chat
3324
- self.can_manage_video_chats: bool = can_manage_video_chats
3325
- self.until_date: int = until_date
3326
- self.can_manage_topics: bool = can_manage_topics
3327
- self.can_send_audios: bool = can_send_audios
3328
- self.can_send_documents: bool = can_send_documents
3329
- self.can_send_photos: bool = can_send_photos
3330
- self.can_send_videos: bool = can_send_videos
3331
- self.can_send_video_notes: bool = can_send_video_notes
3332
- self.can_send_voice_notes: bool = can_send_voice_notes
3333
- self.can_post_stories: bool = can_post_stories
3334
- self.can_edit_stories: bool = can_edit_stories
3335
- self.can_delete_stories: bool = can_delete_stories
3336
-
3337
- @property
3338
- def can_manage_voice_chats(self):
3339
- log_deprecation_warning('The parameter "can_manage_voice_chats" is deprecated. Use "can_manage_video_chats" instead.')
3340
- return self.can_manage_video_chats
3293
+ raise ValueError(f"Unknown chat member type: {status}.")
3341
3294
3342
3295
3343
3296
# noinspection PyUnresolvedReferences
@@ -3362,7 +3315,10 @@ class ChatMemberOwner(ChatMember):
3362
3315
:return: Instance of the class
3363
3316
:rtype: :class:`telebot.types.ChatMemberOwner`
3364
3317
"""
3365
- pass
3318
+ def __init__(self, user, status, is_anonymous, custom_title=None, **kwargs):
3319
+ super().__init__(user, status, **kwargs)
3320
+ self.is_anonymous: bool = is_anonymous
3321
+ self.custom_title: Optional[str] = custom_title
3366
3322
3367
3323
3368
3324
# noinspection PyUnresolvedReferences
@@ -3409,36 +3365,60 @@ class ChatMemberAdministrator(ChatMember):
3409
3365
:param can_invite_users: True, if the user is allowed to invite new users to the chat
3410
3366
:type can_invite_users: :obj:`bool`
3411
3367
3368
+ :param can_post_stories: True, if the administrator can post channel stories
3369
+ :type can_post_stories: :obj:`bool`
3370
+
3371
+ :param can_edit_stories: True, if the administrator can edit stories
3372
+ :type can_edit_stories: :obj:`bool`
3373
+
3374
+ :param can_delete_stories: True, if the administrator can delete stories of other users
3375
+ :type can_delete_stories: :obj:`bool`
3376
+
3412
3377
:param can_post_messages: Optional. True, if the administrator can post in the channel; channels only
3413
3378
:type can_post_messages: :obj:`bool`
3414
3379
3415
- :param can_edit_messages: Optional. True, if the administrator can edit messages of other users and can pin
3416
- messages; channels only
3380
+ :param can_edit_messages: Optional. True, if the administrator can edit messages of other users and can pin messages; channels only
3417
3381
:type can_edit_messages: :obj:`bool`
3418
3382
3419
3383
:param can_pin_messages: Optional. True, if the user is allowed to pin messages; groups and supergroups only
3420
3384
:type can_pin_messages: :obj:`bool`
3421
3385
3422
- :param can_manage_topics: Optional. True, if the user is allowed to create, rename, close, and reopen forum topics;
3423
- supergroups only
3386
+ :param can_manage_topics: Optional. True, if the user is allowed to create, rename, close, and reopen forum topics; supergroups only
3424
3387
:type can_manage_topics: :obj:`bool`
3425
3388
3426
3389
:param custom_title: Optional. Custom title for this user
3427
3390
:type custom_title: :obj:`str`
3428
3391
3429
- :param can_post_stories: Optional. True, if the administrator can post channel stories
3430
- :type can_post_stories: :obj:`bool`
3431
-
3432
- :param can_edit_stories: Optional. True, if the administrator can edit stories
3433
- :type can_edit_stories: :obj:`bool`
3434
-
3435
- :param can_delete_stories: Optional. True, if the administrator can delete stories of other users
3436
- :type can_delete_stories: :obj:`bool`
3437
-
3438
3392
:return: Instance of the class
3439
3393
:rtype: :class:`telebot.types.ChatMemberAdministrator`
3440
3394
"""
3441
- pass
3395
+ def __init__(self, user, status, can_be_edited, is_anonymous, can_manage_chat, can_delete_messages,
3396
+ can_manage_video_chats, can_restrict_members, can_promote_members, can_change_info, can_invite_users,
3397
+ can_post_stories, can_edit_stories, can_delete_stories, can_post_messages=None, can_edit_messages=None,
3398
+ can_pin_messages=None, can_manage_topics=None, custom_title=None, **kwargs):
3399
+ super().__init__(user, status, **kwargs)
3400
+ self.can_be_edited: bool = can_be_edited
3401
+ self.is_anonymous: bool = is_anonymous
3402
+ self.can_manage_chat: bool = can_manage_chat
3403
+ self.can_delete_messages: bool = can_delete_messages
3404
+ self.can_manage_video_chats: bool = can_manage_video_chats
3405
+ self.can_restrict_members: bool = can_restrict_members
3406
+ self.can_promote_members: bool = can_promote_members
3407
+ self.can_change_info: bool = can_change_info
3408
+ self.can_invite_users: bool = can_invite_users
3409
+ self.can_post_stories: bool = can_post_stories
3410
+ self.can_edit_stories: bool = can_edit_stories
3411
+ self.can_delete_stories: bool = can_delete_stories
3412
+ self.can_post_messages: Optional[bool] = can_post_messages
3413
+ self.can_edit_messages: Optional[bool] = can_edit_messages
3414
+ self.can_pin_messages: Optional[bool] = can_pin_messages
3415
+ self.can_manage_topics: Optional[bool] = can_manage_topics
3416
+ self.custom_title: Optional[str] = custom_title
3417
+
3418
+ @property
3419
+ def can_manage_voice_chats(self):
3420
+ log_deprecation_warning('The parameter "can_manage_voice_chats" is deprecated. Use "can_manage_video_chats" instead.')
3421
+ return self.can_manage_video_chats
3442
3422
3443
3423
3444
3424
# noinspection PyUnresolvedReferences
@@ -3454,10 +3434,15 @@ class ChatMemberMember(ChatMember):
3454
3434
:param user: Information about the user
3455
3435
:type user: :class:`telebot.types.User`
3456
3436
3437
+ :param until_date: Optional. Date when the user's subscription will expire; Unix time. If 0, then the user is a member forever
3438
+ :type until_date: :obj:`int`
3439
+
3457
3440
:return: Instance of the class
3458
3441
:rtype: :class:`telebot.types.ChatMemberMember`
3459
3442
"""
3460
- pass
3443
+ def __init__(self, user, status, until_date=None, **kwargs):
3444
+ super().__init__(user, status, **kwargs)
3445
+ self.until_date: Optional[int] = until_date
3461
3446
3462
3447
3463
3448
# noinspection PyUnresolvedReferences
@@ -3476,18 +3461,6 @@ class ChatMemberRestricted(ChatMember):
3476
3461
:param is_member: True, if the user is a member of the chat at the moment of the request
3477
3462
:type is_member: :obj:`bool`
3478
3463
3479
- :param can_change_info: True, if the user is allowed to change the chat title, photo and other settings
3480
- :type can_change_info: :obj:`bool`
3481
-
3482
- :param can_invite_users: True, if the user is allowed to invite new users to the chat
3483
- :type can_invite_users: :obj:`bool`
3484
-
3485
- :param can_pin_messages: True, if the user is allowed to pin messages
3486
- :type can_pin_messages: :obj:`bool`
3487
-
3488
- :param can_manage_topics: True, if the user is allowed to create forum topics
3489
- :type can_manage_topics: :obj:`bool`
3490
-
3491
3464
:param can_send_messages: True, if the user is allowed to send text messages, contacts, locations and venues
3492
3465
:type can_send_messages: :obj:`bool`
3493
3466
@@ -3512,21 +3485,52 @@ class ChatMemberRestricted(ChatMember):
3512
3485
:param can_send_polls: True, if the user is allowed to send polls
3513
3486
:type can_send_polls: :obj:`bool`
3514
3487
3515
- :param can_send_other_messages: True, if the user is allowed to send animations, games, stickers and use inline
3516
- bots
3488
+ :param can_send_other_messages: True, if the user is allowed to send animations, games, stickers and use inline bots
3517
3489
:type can_send_other_messages: :obj:`bool`
3518
3490
3519
3491
:param can_add_web_page_previews: True, if the user is allowed to add web page previews to their messages
3520
3492
:type can_add_web_page_previews: :obj:`bool`
3521
3493
3522
- :param until_date: Date when restrictions will be lifted for this user; unix time. If 0, then the user is restricted
3523
- forever
3494
+ :param can_change_info: True, if the user is allowed to change the chat title, photo and other settings
3495
+ :type can_change_info: :obj:`bool`
3496
+
3497
+ :param can_invite_users: True, if the user is allowed to invite new users to the chat
3498
+ :type can_invite_users: :obj:`bool`
3499
+
3500
+ :param can_pin_messages: True, if the user is allowed to pin messages
3501
+ :type can_pin_messages: :obj:`bool`
3502
+
3503
+ :param can_manage_topics: True, if the user is allowed to create forum topics
3504
+ :type can_manage_topics: :obj:`bool`
3505
+
3506
+ :param until_date: Date when restrictions will be lifted for this user; unix time. If 0, then the user is restricted forever
3524
3507
:type until_date: :obj:`int`
3525
3508
3526
3509
:return: Instance of the class
3527
3510
:rtype: :class:`telebot.types.ChatMemberRestricted`
3528
3511
"""
3529
- pass
3512
+ def __init__(self, user, status, is_member, can_send_messages, can_send_audios, can_send_documents,
3513
+ can_send_photos, can_send_videos, can_send_video_notes, can_send_voice_notes, can_send_polls,
3514
+ can_send_other_messages, can_add_web_page_previews,
3515
+ can_change_info, can_invite_users, can_pin_messages, can_manage_topics,
3516
+ until_date=None, **kwargs):
3517
+ super().__init__(user, status, **kwargs)
3518
+ self.is_member: bool = is_member
3519
+ self.can_send_messages: bool = can_send_messages
3520
+ self.can_send_audios: bool = can_send_audios
3521
+ self.can_send_documents: bool = can_send_documents
3522
+ self.can_send_photos: bool = can_send_photos
3523
+ self.can_send_videos: bool = can_send_videos
3524
+ self.can_send_video_notes: bool = can_send_video_notes
3525
+ self.can_send_voice_notes: bool = can_send_voice_notes
3526
+ self.can_send_polls: bool = can_send_polls
3527
+ self.can_send_other_messages: bool = can_send_other_messages
3528
+ self.can_add_web_page_previews: bool = can_add_web_page_previews
3529
+ self.can_change_info: bool = can_change_info
3530
+ self.can_invite_users: bool = can_invite_users
3531
+ self.can_pin_messages: bool = can_pin_messages
3532
+ self.can_manage_topics: bool = can_manage_topics
3533
+ self.until_date: Optional[int] = until_date
3530
3534
3531
3535
3532
3536
# noinspection PyUnresolvedReferences
@@ -3561,14 +3565,15 @@ class ChatMemberBanned(ChatMember):
3561
3565
:param user: Information about the user
3562
3566
:type user: :class:`telebot.types.User`
3563
3567
3564
- :param until_date: Date when restrictions will be lifted for this user; unix time. If 0, then the user is banned
3565
- forever
3568
+ :param until_date: Date when restrictions will be lifted for this user; unix time. If 0, then the user is banned forever
3566
3569
:type until_date: :obj:`int`
3567
3570
3568
3571
:return: Instance of the class
3569
3572
:rtype: :class:`telebot.types.ChatMemberBanned`
3570
3573
"""
3571
- pass
3574
+ def __init__(self, user, status, until_date=None, **kwargs):
3575
+ super().__init__(user, status, **kwargs)
3576
+ self.until_date: Optional[int] = until_date
3572
3577
3573
3578
3574
3579
class ChatPermissions(JsonDeserializable, JsonSerializable, Dictionaryable):
@@ -3577,8 +3582,7 @@ class ChatPermissions(JsonDeserializable, JsonSerializable, Dictionaryable):
3577
3582
3578
3583
Telegram Documentation: https://core.telegram.org/bots/api#chatpermissions
3579
3584
3580
- :param can_send_messages: Optional. True, if the user is allowed to send text messages, contacts, locations and
3581
- venues
3585
+ :param can_send_messages: Optional. True, if the user is allowed to send text messages, contacts, locations and venues
3582
3586
:type can_send_messages: :obj:`bool`
3583
3587
3584
3588
:param can_send_audios: Optional. True, if the user is allowed to send audios
0 commit comments