mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-02-16 18:31:45 +01:00
Use Collection
Instead of List
and Tuple
(#3025)
This commit is contained in:
parent
72e357a780
commit
f792102212
3 changed files with 78 additions and 79 deletions
|
@ -24,7 +24,7 @@ Warning:
|
||||||
the changelog.
|
the changelog.
|
||||||
"""
|
"""
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import IO, TYPE_CHECKING, Any, Dict, List, Optional, Tuple, TypeVar, Union
|
from typing import IO, TYPE_CHECKING, Any, Dict, Optional, Tuple, TypeVar, Union, Collection
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from telegram import InputFile
|
from telegram import InputFile
|
||||||
|
@ -54,8 +54,8 @@ DVInput = Union["DefaultValue[DVType]", DVType]
|
||||||
as ``Union[DefaultValue, type]``."""
|
as ``Union[DefaultValue, type]``."""
|
||||||
|
|
||||||
RT = TypeVar("RT")
|
RT = TypeVar("RT")
|
||||||
SLT = Union[RT, List[RT], Tuple[RT, ...]]
|
SCT = Union[RT, Collection[RT]]
|
||||||
"""Single instance or list/tuple of instances."""
|
"""Single instance or collection of instances."""
|
||||||
|
|
||||||
ReplyMarkup = Union[
|
ReplyMarkup = Union[
|
||||||
"InlineKeyboardMarkup", "ReplyKeyboardMarkup", "ReplyKeyboardRemove", "ForceReply"
|
"InlineKeyboardMarkup", "ReplyKeyboardMarkup", "ReplyKeyboardRemove", "ForceReply"
|
||||||
|
|
|
@ -22,7 +22,7 @@ from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, TypeVar, Union
|
||||||
|
|
||||||
from telegram import MessageEntity, Update
|
from telegram import MessageEntity, Update
|
||||||
from telegram._utils.defaultvalue import DEFAULT_TRUE
|
from telegram._utils.defaultvalue import DEFAULT_TRUE
|
||||||
from telegram._utils.types import SLT, DVInput
|
from telegram._utils.types import SCT, DVInput
|
||||||
from telegram.ext import filters as filters_module
|
from telegram.ext import filters as filters_module
|
||||||
from telegram.ext._handler import BaseHandler
|
from telegram.ext._handler import BaseHandler
|
||||||
from telegram.ext._utils.types import CCT, HandlerCallback
|
from telegram.ext._utils.types import CCT, HandlerCallback
|
||||||
|
@ -53,7 +53,7 @@ class CommandHandler(BaseHandler[Update, CCT]):
|
||||||
attributes to :class:`telegram.ext.CallbackContext`. See its docs for more info.
|
attributes to :class:`telegram.ext.CallbackContext`. See its docs for more info.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
command (:obj:`str` | Tuple[:obj:`str`] | List[:obj:`str`]):
|
command (:obj:`str` | Collection[:obj:`str`]):
|
||||||
The command or list of commands this handler should listen for.
|
The command or list of commands this handler should listen for.
|
||||||
Limitations are the same as described `here <https://core.telegram.org/bots#commands>`_
|
Limitations are the same as described `here <https://core.telegram.org/bots#commands>`_
|
||||||
callback (:term:`coroutine function`): The callback function for this handler. Will be
|
callback (:term:`coroutine function`): The callback function for this handler. Will be
|
||||||
|
@ -76,8 +76,7 @@ class CommandHandler(BaseHandler[Update, CCT]):
|
||||||
:exc:`ValueError`: When the command is too long or has illegal chars.
|
:exc:`ValueError`: When the command is too long or has illegal chars.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
command (:obj:`str` | Tuple[:obj:`str`] | List[:obj:`str`]):
|
command (List[:obj:`str`]): The list of commands this handler should listen for.
|
||||||
The command or list of commands this handler should listen for.
|
|
||||||
Limitations are the same as described `here <https://core.telegram.org/bots#commands>`_
|
Limitations are the same as described `here <https://core.telegram.org/bots#commands>`_
|
||||||
callback (:term:`coroutine function`): The callback function for this handler.
|
callback (:term:`coroutine function`): The callback function for this handler.
|
||||||
filters (:class:`telegram.ext.filters.BaseFilter`): Optional. Only allow updates with these
|
filters (:class:`telegram.ext.filters.BaseFilter`): Optional. Only allow updates with these
|
||||||
|
@ -91,7 +90,7 @@ class CommandHandler(BaseHandler[Update, CCT]):
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
command: SLT[str],
|
command: SCT[str],
|
||||||
callback: HandlerCallback[Update, CCT, RT],
|
callback: HandlerCallback[Update, CCT, RT],
|
||||||
filters: filters_module.BaseFilter = None,
|
filters: filters_module.BaseFilter = None,
|
||||||
block: DVInput[bool] = DEFAULT_TRUE,
|
block: DVInput[bool] = DEFAULT_TRUE,
|
||||||
|
@ -207,9 +206,9 @@ class PrefixHandler(CommandHandler):
|
||||||
attributes to :class:`telegram.ext.CallbackContext`. See its docs for more info.
|
attributes to :class:`telegram.ext.CallbackContext`. See its docs for more info.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
prefix (:obj:`str` | Tuple[:obj:`str`] | List[:obj:`str`]):
|
prefix (:obj:`str` | Collection[:obj:`str`]):
|
||||||
The prefix(es) that will precede :attr:`command`.
|
The prefix(es) that will precede :attr:`command`.
|
||||||
command (:obj:`str` | Tuple[:obj:`str`] | List[:obj:`str`]):
|
command (:obj:`str` | Collection[:obj:`str`]):
|
||||||
The command or list of commands this handler should listen for.
|
The command or list of commands this handler should listen for.
|
||||||
callback (:term:`coroutine function`): The callback function for this handler. Will be
|
callback (:term:`coroutine function`): The callback function for this handler. Will be
|
||||||
called when :meth:`check_update` has determined that an update should be processed by
|
called when :meth:`check_update` has determined that an update should be processed by
|
||||||
|
@ -242,8 +241,8 @@ class PrefixHandler(CommandHandler):
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
prefix: SLT[str],
|
prefix: SCT[str],
|
||||||
command: SLT[str],
|
command: SCT[str],
|
||||||
callback: HandlerCallback[Update, CCT, RT],
|
callback: HandlerCallback[Update, CCT, RT],
|
||||||
filters: filters_module.BaseFilter = None,
|
filters: filters_module.BaseFilter = None,
|
||||||
block: DVInput[bool] = DEFAULT_TRUE,
|
block: DVInput[bool] = DEFAULT_TRUE,
|
||||||
|
|
|
@ -107,7 +107,7 @@ from typing import (
|
||||||
from telegram import Chat as TGChat
|
from telegram import Chat as TGChat
|
||||||
from telegram import Message, MessageEntity, Update
|
from telegram import Message, MessageEntity, Update
|
||||||
from telegram import User as TGUser
|
from telegram import User as TGUser
|
||||||
from telegram._utils.types import SLT
|
from telegram._utils.types import SCT
|
||||||
from telegram.constants import DiceEmoji as DiceEmojiEnum
|
from telegram.constants import DiceEmoji as DiceEmojiEnum
|
||||||
|
|
||||||
DataDict = Dict[str, list]
|
DataDict = Dict[str, list]
|
||||||
|
@ -588,8 +588,8 @@ class _ChatUserBaseFilter(MessageFilter, ABC):
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
chat_id: SLT[int] = None,
|
chat_id: SCT[int] = None,
|
||||||
username: SLT[str] = None,
|
username: SCT[str] = None,
|
||||||
allow_empty: bool = False,
|
allow_empty: bool = False,
|
||||||
):
|
):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
@ -608,7 +608,7 @@ class _ChatUserBaseFilter(MessageFilter, ABC):
|
||||||
...
|
...
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse_chat_id(chat_id: Optional[SLT[int]]) -> Set[int]:
|
def _parse_chat_id(chat_id: Optional[SCT[int]]) -> Set[int]:
|
||||||
if chat_id is None:
|
if chat_id is None:
|
||||||
return set()
|
return set()
|
||||||
if isinstance(chat_id, int):
|
if isinstance(chat_id, int):
|
||||||
|
@ -616,14 +616,14 @@ class _ChatUserBaseFilter(MessageFilter, ABC):
|
||||||
return set(chat_id)
|
return set(chat_id)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse_username(username: Optional[SLT[str]]) -> Set[str]:
|
def _parse_username(username: Optional[SCT[str]]) -> Set[str]:
|
||||||
if username is None:
|
if username is None:
|
||||||
return set()
|
return set()
|
||||||
if isinstance(username, str):
|
if isinstance(username, str):
|
||||||
return {username[1:] if username.startswith("@") else username}
|
return {username[1:] if username.startswith("@") else username}
|
||||||
return {chat[1:] if chat.startswith("@") else chat for chat in username}
|
return {chat[1:] if chat.startswith("@") else chat for chat in username}
|
||||||
|
|
||||||
def _set_chat_ids(self, chat_id: Optional[SLT[int]]) -> None:
|
def _set_chat_ids(self, chat_id: Optional[SCT[int]]) -> None:
|
||||||
if chat_id and self._usernames:
|
if chat_id and self._usernames:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
f"Can't set {self._chat_id_name} in conjunction with (already set) "
|
f"Can't set {self._chat_id_name} in conjunction with (already set) "
|
||||||
|
@ -631,7 +631,7 @@ class _ChatUserBaseFilter(MessageFilter, ABC):
|
||||||
)
|
)
|
||||||
self._chat_ids = self._parse_chat_id(chat_id)
|
self._chat_ids = self._parse_chat_id(chat_id)
|
||||||
|
|
||||||
def _set_usernames(self, username: Optional[SLT[str]]) -> None:
|
def _set_usernames(self, username: Optional[SCT[str]]) -> None:
|
||||||
if username and self._chat_ids:
|
if username and self._chat_ids:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
f"Can't set {self._username_name} in conjunction with (already set) "
|
f"Can't set {self._username_name} in conjunction with (already set) "
|
||||||
|
@ -644,7 +644,7 @@ class _ChatUserBaseFilter(MessageFilter, ABC):
|
||||||
return frozenset(self._chat_ids)
|
return frozenset(self._chat_ids)
|
||||||
|
|
||||||
@chat_ids.setter
|
@chat_ids.setter
|
||||||
def chat_ids(self, chat_id: SLT[int]) -> None:
|
def chat_ids(self, chat_id: SCT[int]) -> None:
|
||||||
self._set_chat_ids(chat_id)
|
self._set_chat_ids(chat_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -664,15 +664,15 @@ class _ChatUserBaseFilter(MessageFilter, ABC):
|
||||||
return frozenset(self._usernames)
|
return frozenset(self._usernames)
|
||||||
|
|
||||||
@usernames.setter
|
@usernames.setter
|
||||||
def usernames(self, username: SLT[str]) -> None:
|
def usernames(self, username: SCT[str]) -> None:
|
||||||
self._set_usernames(username)
|
self._set_usernames(username)
|
||||||
|
|
||||||
def add_usernames(self, username: SLT[str]) -> None:
|
def add_usernames(self, username: SCT[str]) -> None:
|
||||||
"""
|
"""
|
||||||
Add one or more chats to the allowed usernames.
|
Add one or more chats to the allowed usernames.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
username(:obj:`str` | Tuple[:obj:`str`] | List[:obj:`str`]): Which username(s) to
|
username(:obj:`str` | Collection[:obj:`str`]): Which username(s) to
|
||||||
allow through. Leading ``'@'`` s in usernames will be discarded.
|
allow through. Leading ``'@'`` s in usernames will be discarded.
|
||||||
"""
|
"""
|
||||||
if self._chat_ids:
|
if self._chat_ids:
|
||||||
|
@ -684,7 +684,7 @@ class _ChatUserBaseFilter(MessageFilter, ABC):
|
||||||
parsed_username = self._parse_username(username)
|
parsed_username = self._parse_username(username)
|
||||||
self._usernames |= parsed_username
|
self._usernames |= parsed_username
|
||||||
|
|
||||||
def _add_chat_ids(self, chat_id: SLT[int]) -> None:
|
def _add_chat_ids(self, chat_id: SCT[int]) -> None:
|
||||||
if self._usernames:
|
if self._usernames:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
f"Can't set {self._chat_id_name} in conjunction with (already set) "
|
f"Can't set {self._chat_id_name} in conjunction with (already set) "
|
||||||
|
@ -695,12 +695,12 @@ class _ChatUserBaseFilter(MessageFilter, ABC):
|
||||||
|
|
||||||
self._chat_ids |= parsed_chat_id
|
self._chat_ids |= parsed_chat_id
|
||||||
|
|
||||||
def remove_usernames(self, username: SLT[str]) -> None:
|
def remove_usernames(self, username: SCT[str]) -> None:
|
||||||
"""
|
"""
|
||||||
Remove one or more chats from allowed usernames.
|
Remove one or more chats from allowed usernames.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
username(:obj:`str` | Tuple[:obj:`str`] | List[:obj:`str`]): Which username(s) to
|
username(:obj:`str` | Collection[:obj:`str`]): Which username(s) to
|
||||||
disallow through. Leading ``'@'`` s in usernames will be discarded.
|
disallow through. Leading ``'@'`` s in usernames will be discarded.
|
||||||
"""
|
"""
|
||||||
if self._chat_ids:
|
if self._chat_ids:
|
||||||
|
@ -712,7 +712,7 @@ class _ChatUserBaseFilter(MessageFilter, ABC):
|
||||||
parsed_username = self._parse_username(username)
|
parsed_username = self._parse_username(username)
|
||||||
self._usernames -= parsed_username
|
self._usernames -= parsed_username
|
||||||
|
|
||||||
def _remove_chat_ids(self, chat_id: SLT[int]) -> None:
|
def _remove_chat_ids(self, chat_id: SCT[int]) -> None:
|
||||||
if self._usernames:
|
if self._usernames:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
f"Can't set {self._chat_id_name} in conjunction with (already set) "
|
f"Can't set {self._chat_id_name} in conjunction with (already set) "
|
||||||
|
@ -757,9 +757,9 @@ class Chat(_ChatUserBaseFilter):
|
||||||
replace the current set of allowed chats.
|
replace the current set of allowed chats.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
chat_id(:obj:`int` | Tuple[:obj:`int`] | List[:obj:`int`], optional):
|
chat_id(:obj:`int` | Collection[:obj:`int`], optional):
|
||||||
Which chat ID(s) to allow through.
|
Which chat ID(s) to allow through.
|
||||||
username(:obj:`str` | Tuple[:obj:`str`] | List[:obj:`str`], optional):
|
username(:obj:`str` | Collection[:obj:`str`], optional):
|
||||||
Which username(s) to allow through.
|
Which username(s) to allow through.
|
||||||
Leading ``'@'`` s in usernames will be discarded.
|
Leading ``'@'`` s in usernames will be discarded.
|
||||||
allow_empty(:obj:`bool`, optional): Whether updates should be processed, if no chat
|
allow_empty(:obj:`bool`, optional): Whether updates should be processed, if no chat
|
||||||
|
@ -779,22 +779,22 @@ class Chat(_ChatUserBaseFilter):
|
||||||
def get_chat_or_user(self, message: Message) -> Optional[TGChat]:
|
def get_chat_or_user(self, message: Message) -> Optional[TGChat]:
|
||||||
return message.chat
|
return message.chat
|
||||||
|
|
||||||
def add_chat_ids(self, chat_id: SLT[int]) -> None:
|
def add_chat_ids(self, chat_id: SCT[int]) -> None:
|
||||||
"""
|
"""
|
||||||
Add one or more chats to the allowed chat ids.
|
Add one or more chats to the allowed chat ids.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
chat_id(:obj:`int` | Tuple[:obj:`int`] | List[:obj:`int`]): Which chat ID(s) to allow
|
chat_id(:obj:`int` | Collection[:obj:`int`]): Which chat ID(s) to allow
|
||||||
through.
|
through.
|
||||||
"""
|
"""
|
||||||
return super()._add_chat_ids(chat_id)
|
return super()._add_chat_ids(chat_id)
|
||||||
|
|
||||||
def remove_chat_ids(self, chat_id: SLT[int]) -> None:
|
def remove_chat_ids(self, chat_id: SCT[int]) -> None:
|
||||||
"""
|
"""
|
||||||
Remove one or more chats from allowed chat ids.
|
Remove one or more chats from allowed chat ids.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
chat_id(:obj:`int` | Tuple[:obj:`int`] | List[:obj:`int`]): Which chat ID(s) to
|
chat_id(:obj:`int` | Collection[:obj:`int`]): Which chat ID(s) to
|
||||||
disallow through.
|
disallow through.
|
||||||
"""
|
"""
|
||||||
return super()._remove_chat_ids(chat_id)
|
return super()._remove_chat_ids(chat_id)
|
||||||
|
@ -930,7 +930,7 @@ CONTACT = _Contact(name="filters.CONTACT")
|
||||||
class _Dice(MessageFilter):
|
class _Dice(MessageFilter):
|
||||||
__slots__ = ("emoji", "values")
|
__slots__ = ("emoji", "values")
|
||||||
|
|
||||||
def __init__(self, values: SLT[int] = None, emoji: DiceEmojiEnum = None):
|
def __init__(self, values: SCT[int] = None, emoji: DiceEmojiEnum = None):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.emoji = emoji
|
self.emoji = emoji
|
||||||
self.values = [values] if isinstance(values, int) else values
|
self.values = [values] if isinstance(values, int) else values
|
||||||
|
@ -983,7 +983,7 @@ class Dice(_Dice):
|
||||||
``filters.TEXT | filters.Dice.ALL``.
|
``filters.TEXT | filters.Dice.ALL``.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
values (:obj:`int` | Tuple[:obj:`int`] | List[:obj:`int`], optional):
|
values (:obj:`int` | Collection[:obj:`int`], optional):
|
||||||
Which values to allow. If not specified, will allow the specified dice message.
|
Which values to allow. If not specified, will allow the specified dice message.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -996,12 +996,12 @@ class Dice(_Dice):
|
||||||
"""Dice messages with the emoji 🏀. Supports passing a list of integers.
|
"""Dice messages with the emoji 🏀. Supports passing a list of integers.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
values (:obj:`int` | Tuple[:obj:`int`] | List[:obj:`int`]): Which values to allow.
|
values (:obj:`int` | Collection[:obj:`int`]): Which values to allow.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
|
|
||||||
def __init__(self, values: SLT[int]):
|
def __init__(self, values: SCT[int]):
|
||||||
super().__init__(values, emoji=DiceEmojiEnum.BASKETBALL)
|
super().__init__(values, emoji=DiceEmojiEnum.BASKETBALL)
|
||||||
|
|
||||||
BASKETBALL = _Dice(emoji=DiceEmojiEnum.BASKETBALL)
|
BASKETBALL = _Dice(emoji=DiceEmojiEnum.BASKETBALL)
|
||||||
|
@ -1011,12 +1011,12 @@ class Dice(_Dice):
|
||||||
"""Dice messages with the emoji 🎳. Supports passing a list of integers.
|
"""Dice messages with the emoji 🎳. Supports passing a list of integers.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
values (:obj:`int` | Tuple[:obj:`int`] | List[:obj:`int`]): Which values to allow.
|
values (:obj:`int` | Collection[:obj:`int`]): Which values to allow.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
|
|
||||||
def __init__(self, values: SLT[int]):
|
def __init__(self, values: SCT[int]):
|
||||||
super().__init__(values, emoji=DiceEmojiEnum.BOWLING)
|
super().__init__(values, emoji=DiceEmojiEnum.BOWLING)
|
||||||
|
|
||||||
BOWLING = _Dice(emoji=DiceEmojiEnum.BOWLING)
|
BOWLING = _Dice(emoji=DiceEmojiEnum.BOWLING)
|
||||||
|
@ -1026,12 +1026,12 @@ class Dice(_Dice):
|
||||||
"""Dice messages with the emoji 🎯. Supports passing a list of integers.
|
"""Dice messages with the emoji 🎯. Supports passing a list of integers.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
values (:obj:`int` | Tuple[:obj:`int`] | List[:obj:`int`]): Which values to allow.
|
values (:obj:`int` | Collection[:obj:`int`]): Which values to allow.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
|
|
||||||
def __init__(self, values: SLT[int]):
|
def __init__(self, values: SCT[int]):
|
||||||
super().__init__(values, emoji=DiceEmojiEnum.DARTS)
|
super().__init__(values, emoji=DiceEmojiEnum.DARTS)
|
||||||
|
|
||||||
DARTS = _Dice(emoji=DiceEmojiEnum.DARTS)
|
DARTS = _Dice(emoji=DiceEmojiEnum.DARTS)
|
||||||
|
@ -1041,12 +1041,12 @@ class Dice(_Dice):
|
||||||
"""Dice messages with the emoji 🎲. Supports passing a list of integers.
|
"""Dice messages with the emoji 🎲. Supports passing a list of integers.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
values (:obj:`int` | Tuple[:obj:`int`] | List[:obj:`int`]): Which values to allow.
|
values (:obj:`int` | Collection[:obj:`int`]): Which values to allow.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
|
|
||||||
def __init__(self, values: SLT[int]):
|
def __init__(self, values: SCT[int]):
|
||||||
super().__init__(values, emoji=DiceEmojiEnum.DICE)
|
super().__init__(values, emoji=DiceEmojiEnum.DICE)
|
||||||
|
|
||||||
DICE = _Dice(emoji=DiceEmojiEnum.DICE) # skipcq: PTC-W0052
|
DICE = _Dice(emoji=DiceEmojiEnum.DICE) # skipcq: PTC-W0052
|
||||||
|
@ -1056,12 +1056,12 @@ class Dice(_Dice):
|
||||||
"""Dice messages with the emoji ⚽. Supports passing a list of integers.
|
"""Dice messages with the emoji ⚽. Supports passing a list of integers.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
values (:obj:`int` | Tuple[:obj:`int`] | List[:obj:`int`]): Which values to allow.
|
values (:obj:`int` | Collection[:obj:`int`]): Which values to allow.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
|
|
||||||
def __init__(self, values: SLT[int]):
|
def __init__(self, values: SCT[int]):
|
||||||
super().__init__(values, emoji=DiceEmojiEnum.FOOTBALL)
|
super().__init__(values, emoji=DiceEmojiEnum.FOOTBALL)
|
||||||
|
|
||||||
FOOTBALL = _Dice(emoji=DiceEmojiEnum.FOOTBALL)
|
FOOTBALL = _Dice(emoji=DiceEmojiEnum.FOOTBALL)
|
||||||
|
@ -1071,12 +1071,12 @@ class Dice(_Dice):
|
||||||
"""Dice messages with the emoji 🎰. Supports passing a list of integers.
|
"""Dice messages with the emoji 🎰. Supports passing a list of integers.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
values (:obj:`int` | Tuple[:obj:`int`] | List[:obj:`int`]): Which values to allow.
|
values (:obj:`int` | Collection[:obj:`int`]): Which values to allow.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
|
|
||||||
def __init__(self, values: SLT[int]):
|
def __init__(self, values: SCT[int]):
|
||||||
super().__init__(values, emoji=DiceEmojiEnum.SLOT_MACHINE)
|
super().__init__(values, emoji=DiceEmojiEnum.SLOT_MACHINE)
|
||||||
|
|
||||||
SLOT_MACHINE = _Dice(emoji=DiceEmojiEnum.SLOT_MACHINE)
|
SLOT_MACHINE = _Dice(emoji=DiceEmojiEnum.SLOT_MACHINE)
|
||||||
|
@ -1324,9 +1324,9 @@ class ForwardedFrom(_ChatUserBaseFilter):
|
||||||
the current set of allowed chats.
|
the current set of allowed chats.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
chat_id(:obj:`int` | Tuple[:obj:`int`] | List[:obj:`int`], optional):
|
chat_id(:obj:`int` | Collection[:obj:`int`], optional):
|
||||||
Which chat/user ID(s) to allow through.
|
Which chat/user ID(s) to allow through.
|
||||||
username(:obj:`str` | Tuple[:obj:`str`] | List[:obj:`str`], optional):
|
username(:obj:`str` | Collection[:obj:`str`], optional):
|
||||||
Which username(s) to allow through. Leading ``'@'`` s in usernames will be
|
Which username(s) to allow through. Leading ``'@'`` s in usernames will be
|
||||||
discarded.
|
discarded.
|
||||||
allow_empty(:obj:`bool`, optional): Whether updates should be processed, if no chat
|
allow_empty(:obj:`bool`, optional): Whether updates should be processed, if no chat
|
||||||
|
@ -1346,22 +1346,22 @@ class ForwardedFrom(_ChatUserBaseFilter):
|
||||||
def get_chat_or_user(self, message: Message) -> Union[TGUser, TGChat, None]:
|
def get_chat_or_user(self, message: Message) -> Union[TGUser, TGChat, None]:
|
||||||
return message.forward_from or message.forward_from_chat
|
return message.forward_from or message.forward_from_chat
|
||||||
|
|
||||||
def add_chat_ids(self, chat_id: SLT[int]) -> None:
|
def add_chat_ids(self, chat_id: SCT[int]) -> None:
|
||||||
"""
|
"""
|
||||||
Add one or more chats to the allowed chat ids.
|
Add one or more chats to the allowed chat ids.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
chat_id(:obj:`int` | Tuple[:obj:`int`] | List[:obj:`int`]): Which chat/user ID(s) to
|
chat_id(:obj:`int` | Collection[:obj:`int`]): Which chat/user ID(s) to
|
||||||
allow through.
|
allow through.
|
||||||
"""
|
"""
|
||||||
return super()._add_chat_ids(chat_id)
|
return super()._add_chat_ids(chat_id)
|
||||||
|
|
||||||
def remove_chat_ids(self, chat_id: SLT[int]) -> None:
|
def remove_chat_ids(self, chat_id: SCT[int]) -> None:
|
||||||
"""
|
"""
|
||||||
Remove one or more chats from allowed chat ids.
|
Remove one or more chats from allowed chat ids.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
chat_id(:obj:`int` | Tuple[:obj:`int`] | List[:obj:`int`]): Which chat/user ID(s) to
|
chat_id(:obj:`int` | Collection[:obj:`int`]): Which chat/user ID(s) to
|
||||||
disallow through.
|
disallow through.
|
||||||
"""
|
"""
|
||||||
return super()._remove_chat_ids(chat_id)
|
return super()._remove_chat_ids(chat_id)
|
||||||
|
@ -1428,7 +1428,7 @@ class Language(MessageFilter):
|
||||||
``MessageHandler(filters.Language("en"), callback_method)``
|
``MessageHandler(filters.Language("en"), callback_method)``
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
lang (:obj:`str` | Tuple[:obj:`str`] | List[:obj:`str`]):
|
lang (:obj:`str` | Collection[:obj:`str`]):
|
||||||
Which language code(s) to allow through.
|
Which language code(s) to allow through.
|
||||||
This will be matched using :obj:`str.startswith` meaning that
|
This will be matched using :obj:`str.startswith` meaning that
|
||||||
'en' will match both 'en_US' and 'en_GB'.
|
'en' will match both 'en_US' and 'en_GB'.
|
||||||
|
@ -1437,7 +1437,7 @@ class Language(MessageFilter):
|
||||||
|
|
||||||
__slots__ = ("lang",)
|
__slots__ = ("lang",)
|
||||||
|
|
||||||
def __init__(self, lang: SLT[str]):
|
def __init__(self, lang: SCT[str]):
|
||||||
if isinstance(lang, str):
|
if isinstance(lang, str):
|
||||||
lang = cast(str, lang)
|
lang = cast(str, lang)
|
||||||
self.lang = [lang]
|
self.lang = [lang]
|
||||||
|
@ -1596,9 +1596,9 @@ class SenderChat(_ChatUserBaseFilter):
|
||||||
the current set of allowed chats.
|
the current set of allowed chats.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
chat_id(:obj:`int` | Tuple[:obj:`int`] | List[:obj:`int`], optional):
|
chat_id(:obj:`int` | Collection[:obj:`int`], optional):
|
||||||
Which sender chat chat ID(s) to allow through.
|
Which sender chat chat ID(s) to allow through.
|
||||||
username(:obj:`str` | Tuple[:obj:`str`] | List[:obj:`str`], optional):
|
username(:obj:`str` | Collection[:obj:`str`], optional):
|
||||||
Which sender chat username(s) to allow through.
|
Which sender chat username(s) to allow through.
|
||||||
Leading ``'@'`` s in usernames will be discarded.
|
Leading ``'@'`` s in usernames will be discarded.
|
||||||
allow_empty(:obj:`bool`, optional): Whether updates should be processed, if no sender
|
allow_empty(:obj:`bool`, optional): Whether updates should be processed, if no sender
|
||||||
|
@ -1638,12 +1638,12 @@ class SenderChat(_ChatUserBaseFilter):
|
||||||
CHANNEL = _CHANNEL(name="filters.SenderChat.CHANNEL")
|
CHANNEL = _CHANNEL(name="filters.SenderChat.CHANNEL")
|
||||||
"""Messages whose sender chat is a channel."""
|
"""Messages whose sender chat is a channel."""
|
||||||
|
|
||||||
def add_chat_ids(self, chat_id: SLT[int]) -> None:
|
def add_chat_ids(self, chat_id: SCT[int]) -> None:
|
||||||
"""
|
"""
|
||||||
Add one or more sender chats to the allowed chat ids.
|
Add one or more sender chats to the allowed chat ids.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
chat_id(:obj:`int` | Tuple[:obj:`int`] | List[:obj:`int`]): Which sender chat ID(s) to
|
chat_id(:obj:`int` | Collection[:obj:`int`]): Which sender chat ID(s) to
|
||||||
allow through.
|
allow through.
|
||||||
"""
|
"""
|
||||||
return super()._add_chat_ids(chat_id)
|
return super()._add_chat_ids(chat_id)
|
||||||
|
@ -1651,12 +1651,12 @@ class SenderChat(_ChatUserBaseFilter):
|
||||||
def get_chat_or_user(self, message: Message) -> Optional[TGChat]:
|
def get_chat_or_user(self, message: Message) -> Optional[TGChat]:
|
||||||
return message.sender_chat
|
return message.sender_chat
|
||||||
|
|
||||||
def remove_chat_ids(self, chat_id: SLT[int]) -> None:
|
def remove_chat_ids(self, chat_id: SCT[int]) -> None:
|
||||||
"""
|
"""
|
||||||
Remove one or more sender chats from allowed chat ids.
|
Remove one or more sender chats from allowed chat ids.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
chat_id(:obj:`int` | Tuple[:obj:`int`] | List[:obj:`int`]): Which sender chat ID(s) to
|
chat_id(:obj:`int` | Collection[:obj:`int`]): Which sender chat ID(s) to
|
||||||
disallow through.
|
disallow through.
|
||||||
"""
|
"""
|
||||||
return super()._remove_chat_ids(chat_id)
|
return super()._remove_chat_ids(chat_id)
|
||||||
|
@ -2103,9 +2103,9 @@ class User(_ChatUserBaseFilter):
|
||||||
``MessageHandler(filters.User(1234), callback_method)``
|
``MessageHandler(filters.User(1234), callback_method)``
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
user_id(:obj:`int` | Tuple[:obj:`int`] | List[:obj:`int`], optional): Which user ID(s) to
|
user_id(:obj:`int` | Collection[:obj:`int`], optional): Which user ID(s) to
|
||||||
allow through.
|
allow through.
|
||||||
username(:obj:`str` | Tuple[:obj:`str`] | List[:obj:`str`], optional):
|
username(:obj:`str` | Collection[:obj:`str`], optional):
|
||||||
Which username(s) to allow through. Leading ``'@'`` s in usernames will be discarded.
|
Which username(s) to allow through. Leading ``'@'`` s in usernames will be discarded.
|
||||||
allow_empty(:obj:`bool`, optional): Whether updates should be processed, if no user is
|
allow_empty(:obj:`bool`, optional): Whether updates should be processed, if no user is
|
||||||
specified in :attr:`user_ids` and :attr:`usernames`. Defaults to :obj:`False`.
|
specified in :attr:`user_ids` and :attr:`usernames`. Defaults to :obj:`False`.
|
||||||
|
@ -2122,8 +2122,8 @@ class User(_ChatUserBaseFilter):
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
user_id: SLT[int] = None,
|
user_id: SCT[int] = None,
|
||||||
username: SLT[str] = None,
|
username: SCT[str] = None,
|
||||||
allow_empty: bool = False,
|
allow_empty: bool = False,
|
||||||
):
|
):
|
||||||
super().__init__(chat_id=user_id, username=username, allow_empty=allow_empty)
|
super().__init__(chat_id=user_id, username=username, allow_empty=allow_empty)
|
||||||
|
@ -2150,25 +2150,25 @@ class User(_ChatUserBaseFilter):
|
||||||
return self.chat_ids
|
return self.chat_ids
|
||||||
|
|
||||||
@user_ids.setter
|
@user_ids.setter
|
||||||
def user_ids(self, user_id: SLT[int]) -> None:
|
def user_ids(self, user_id: SCT[int]) -> None:
|
||||||
self.chat_ids = user_id # type: ignore[assignment]
|
self.chat_ids = user_id # type: ignore[assignment]
|
||||||
|
|
||||||
def add_user_ids(self, user_id: SLT[int]) -> None:
|
def add_user_ids(self, user_id: SCT[int]) -> None:
|
||||||
"""
|
"""
|
||||||
Add one or more users to the allowed user ids.
|
Add one or more users to the allowed user ids.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
user_id(:obj:`int` | Tuple[:obj:`int`] | List[:obj:`int`]): Which user ID(s) to allow
|
user_id(:obj:`int` | Collection[:obj:`int`]): Which user ID(s) to allow
|
||||||
through.
|
through.
|
||||||
"""
|
"""
|
||||||
return super()._add_chat_ids(user_id)
|
return super()._add_chat_ids(user_id)
|
||||||
|
|
||||||
def remove_user_ids(self, user_id: SLT[int]) -> None:
|
def remove_user_ids(self, user_id: SCT[int]) -> None:
|
||||||
"""
|
"""
|
||||||
Remove one or more users from allowed user ids.
|
Remove one or more users from allowed user ids.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
user_id(:obj:`int` | Tuple[:obj:`int`] | List[:obj:`int`]): Which user ID(s) to
|
user_id(:obj:`int` | Collection[:obj:`int`]): Which user ID(s) to
|
||||||
disallow through.
|
disallow through.
|
||||||
"""
|
"""
|
||||||
return super()._remove_chat_ids(user_id)
|
return super()._remove_chat_ids(user_id)
|
||||||
|
@ -2203,9 +2203,9 @@ class ViaBot(_ChatUserBaseFilter):
|
||||||
``MessageHandler(filters.ViaBot(1234), callback_method)``
|
``MessageHandler(filters.ViaBot(1234), callback_method)``
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
bot_id(:obj:`int` | Tuple[:obj:`int`] | List[:obj:`int`], optional): Which bot ID(s) to
|
bot_id(:obj:`int` | Collection[:obj:`int`], optional): Which bot ID(s) to
|
||||||
allow through.
|
allow through.
|
||||||
username(:obj:`str` | Tuple[:obj:`str`] | List[:obj:`str`], optional):
|
username(:obj:`str` | Collection[:obj:`str`], optional):
|
||||||
Which username(s) to allow through. Leading ``'@'`` s in usernames will be
|
Which username(s) to allow through. Leading ``'@'`` s in usernames will be
|
||||||
discarded.
|
discarded.
|
||||||
allow_empty(:obj:`bool`, optional): Whether updates should be processed, if no user
|
allow_empty(:obj:`bool`, optional): Whether updates should be processed, if no user
|
||||||
|
@ -2223,8 +2223,8 @@ class ViaBot(_ChatUserBaseFilter):
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
bot_id: SLT[int] = None,
|
bot_id: SCT[int] = None,
|
||||||
username: SLT[str] = None,
|
username: SCT[str] = None,
|
||||||
allow_empty: bool = False,
|
allow_empty: bool = False,
|
||||||
):
|
):
|
||||||
super().__init__(chat_id=bot_id, username=username, allow_empty=allow_empty)
|
super().__init__(chat_id=bot_id, username=username, allow_empty=allow_empty)
|
||||||
|
@ -2251,25 +2251,25 @@ class ViaBot(_ChatUserBaseFilter):
|
||||||
return self.chat_ids
|
return self.chat_ids
|
||||||
|
|
||||||
@bot_ids.setter
|
@bot_ids.setter
|
||||||
def bot_ids(self, bot_id: SLT[int]) -> None:
|
def bot_ids(self, bot_id: SCT[int]) -> None:
|
||||||
self.chat_ids = bot_id # type: ignore[assignment]
|
self.chat_ids = bot_id # type: ignore[assignment]
|
||||||
|
|
||||||
def add_bot_ids(self, bot_id: SLT[int]) -> None:
|
def add_bot_ids(self, bot_id: SCT[int]) -> None:
|
||||||
"""
|
"""
|
||||||
Add one or more bots to the allowed bot ids.
|
Add one or more bots to the allowed bot ids.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
bot_id(:obj:`int` | Tuple[:obj:`int`] | List[:obj:`int`]): Which bot ID(s) to allow
|
bot_id(:obj:`int` | Collection[:obj:`int`]): Which bot ID(s) to allow
|
||||||
through.
|
through.
|
||||||
"""
|
"""
|
||||||
return super()._add_chat_ids(bot_id)
|
return super()._add_chat_ids(bot_id)
|
||||||
|
|
||||||
def remove_bot_ids(self, bot_id: SLT[int]) -> None:
|
def remove_bot_ids(self, bot_id: SCT[int]) -> None:
|
||||||
"""
|
"""
|
||||||
Remove one or more bots from allowed bot ids.
|
Remove one or more bots from allowed bot ids.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
bot_id(:obj:`int` | Tuple[:obj:`int`] | List[:obj:`int`], optional): Which bot ID(s) to
|
bot_id(:obj:`int` | Collection[:obj:`int`], optional): Which bot ID(s) to
|
||||||
disallow through.
|
disallow through.
|
||||||
"""
|
"""
|
||||||
return super()._remove_chat_ids(bot_id)
|
return super()._remove_chat_ids(bot_id)
|
||||||
|
|
Loading…
Add table
Reference in a new issue