mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
- Set BotCommandScope as abstract class.
- Docstrings from telegram API Scope types
This commit is contained in:
parent
b2c6077f4d
commit
491cc05a95
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Dict, List, Optional, Union
|
from typing import Dict, List, Optional, Union
|
||||||
|
from abc import ABC
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import ujson as json
|
import ujson as json
|
||||||
@ -1279,8 +1280,19 @@ class BotCommand(JsonSerializable, JsonDeserializable):
|
|||||||
|
|
||||||
# BotCommandScopes
|
# BotCommandScopes
|
||||||
|
|
||||||
class BotCommandScope(JsonSerializable):
|
class BotCommandScope(ABC, JsonSerializable):
|
||||||
def __init__(self, type='default', chat_id=None, user_id=None):
|
def __init__(self, type='default', chat_id=None, user_id=None):
|
||||||
|
"""
|
||||||
|
Abstract class.
|
||||||
|
Use BotCommandScopeX classes to set a specific scope type:
|
||||||
|
BotCommandScopeDefault
|
||||||
|
BotCommandScopeAllPrivateChats
|
||||||
|
BotCommandScopeAllGroupChats
|
||||||
|
BotCommandScopeAllChatAdministrators
|
||||||
|
BotCommandScopeChat
|
||||||
|
BotCommandScopeChatAdministrators
|
||||||
|
BotCommandScopeChatMember
|
||||||
|
"""
|
||||||
self.type: str = type
|
self.type: str = type
|
||||||
self.chat_id: Optional[Union[int, str]] = chat_id
|
self.chat_id: Optional[Union[int, str]] = chat_id
|
||||||
self.user_id: Optional[Union[int, str]] = user_id
|
self.user_id: Optional[Union[int, str]] = user_id
|
||||||
@ -1296,21 +1308,34 @@ class BotCommandScope(JsonSerializable):
|
|||||||
|
|
||||||
class BotCommandScopeDefault(BotCommandScope):
|
class BotCommandScopeDefault(BotCommandScope):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
"""
|
||||||
|
Represents the default scope of bot commands.
|
||||||
|
Default commands are used if no commands with a narrower scope are specified for the user.
|
||||||
|
"""
|
||||||
super(BotCommandScopeDefault, self).__init__(type='default')
|
super(BotCommandScopeDefault, self).__init__(type='default')
|
||||||
|
|
||||||
|
|
||||||
class BotCommandScopeAllPrivateChats(BotCommandScope):
|
class BotCommandScopeAllPrivateChats(BotCommandScope):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
"""
|
||||||
|
Represents the scope of bot commands, covering all private chats.
|
||||||
|
"""
|
||||||
super(BotCommandScopeAllPrivateChats, self).__init__(type='all_private_chats')
|
super(BotCommandScopeAllPrivateChats, self).__init__(type='all_private_chats')
|
||||||
|
|
||||||
|
|
||||||
class BotCommandScopeAllGroupChats(BotCommandScope):
|
class BotCommandScopeAllGroupChats(BotCommandScope):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
"""
|
||||||
|
Represents the scope of bot commands, covering all group and supergroup chats.
|
||||||
|
"""
|
||||||
super(BotCommandScopeAllGroupChats, self).__init__(type='all_group_chats')
|
super(BotCommandScopeAllGroupChats, self).__init__(type='all_group_chats')
|
||||||
|
|
||||||
|
|
||||||
class BotCommandScopeAllChatAdministrators(BotCommandScope):
|
class BotCommandScopeAllChatAdministrators(BotCommandScope):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
"""
|
||||||
|
Represents the scope of bot commands, covering all group and supergroup chat administrators.
|
||||||
|
"""
|
||||||
super(BotCommandScopeAllChatAdministrators, self).__init__(type='all_chat_administrators')
|
super(BotCommandScopeAllChatAdministrators, self).__init__(type='all_chat_administrators')
|
||||||
|
|
||||||
|
|
||||||
@ -1321,11 +1346,20 @@ class BotCommandScopeChat(BotCommandScope):
|
|||||||
|
|
||||||
class BotCommandScopeChatAdministrators(BotCommandScope):
|
class BotCommandScopeChatAdministrators(BotCommandScope):
|
||||||
def __init__(self, chat_id=None):
|
def __init__(self, chat_id=None):
|
||||||
|
"""
|
||||||
|
Represents the scope of bot commands, covering a specific chat.
|
||||||
|
@param chat_id: Unique identifier for the target chat
|
||||||
|
"""
|
||||||
super(BotCommandScopeChatAdministrators, self).__init__(type='chat_administrators', chat_id=chat_id)
|
super(BotCommandScopeChatAdministrators, self).__init__(type='chat_administrators', chat_id=chat_id)
|
||||||
|
|
||||||
|
|
||||||
class BotCommandScopeChatMember(BotCommandScope):
|
class BotCommandScopeChatMember(BotCommandScope):
|
||||||
def __init__(self, chat_id=None, user_id=None):
|
def __init__(self, chat_id=None, user_id=None):
|
||||||
|
"""
|
||||||
|
Represents the scope of bot commands, covering all administrators of a specific group or supergroup chat
|
||||||
|
@param chat_id: Unique identifier for the target chat
|
||||||
|
@param user_id: Unique identifier of the target user
|
||||||
|
"""
|
||||||
super(BotCommandScopeChatMember, self).__init__(type='chat_administrators', chat_id=chat_id, user_id=user_id)
|
super(BotCommandScopeChatMember, self).__init__(type='chat_administrators', chat_id=chat_id, user_id=user_id)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user