Skip to content

Commit

Permalink
- Set BotCommandScope as abstract class.
Browse files Browse the repository at this point in the history
- Docstrings from telegram API Scope types
  • Loading branch information
MAIKS1900 committed Jun 27, 2021
1 parent b2c6077 commit 491cc05
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion telebot/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging
from typing import Dict, List, Optional, Union
from abc import ABC

try:
import ujson as json
Expand Down Expand Up @@ -1279,8 +1280,19 @@ def to_dict(self):

# BotCommandScopes

class BotCommandScope(JsonSerializable):
class BotCommandScope(ABC, JsonSerializable):
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.chat_id: Optional[Union[int, str]] = chat_id
self.user_id: Optional[Union[int, str]] = user_id
Expand All @@ -1296,21 +1308,34 @@ def to_json(self):

class BotCommandScopeDefault(BotCommandScope):
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')


class BotCommandScopeAllPrivateChats(BotCommandScope):
def __init__(self):
"""
Represents the scope of bot commands, covering all private chats.
"""
super(BotCommandScopeAllPrivateChats, self).__init__(type='all_private_chats')


class BotCommandScopeAllGroupChats(BotCommandScope):
def __init__(self):
"""
Represents the scope of bot commands, covering all group and supergroup chats.
"""
super(BotCommandScopeAllGroupChats, self).__init__(type='all_group_chats')


class BotCommandScopeAllChatAdministrators(BotCommandScope):
def __init__(self):
"""
Represents the scope of bot commands, covering all group and supergroup chat administrators.
"""
super(BotCommandScopeAllChatAdministrators, self).__init__(type='all_chat_administrators')


Expand All @@ -1321,11 +1346,20 @@ def __init__(self, chat_id=None):

class BotCommandScopeChatAdministrators(BotCommandScope):
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)


class BotCommandScopeChatMember(BotCommandScope):
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)


Expand Down

0 comments on commit 491cc05

Please sign in to comment.