mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Compare commits
5 Commits
b8ebe4fd58
...
ac12d0fc02
Author | SHA1 | Date | |
---|---|---|---|
|
ac12d0fc02 | ||
|
995e28e9d8 | ||
|
1bfc082d46 | ||
|
1a35bbb127 | ||
|
e585c77830 |
@ -769,7 +769,6 @@ See more examples in our [examples](https://github.com/eternnoir/pyTelegramBotAP
|
|||||||
Telegram Bot API support new type Chat for message.chat.
|
Telegram Bot API support new type Chat for message.chat.
|
||||||
|
|
||||||
- Check the ```type``` attribute in ```Chat``` object:
|
- Check the ```type``` attribute in ```Chat``` object:
|
||||||
-
|
|
||||||
```python
|
```python
|
||||||
if message.chat.type == "private":
|
if message.chat.type == "private":
|
||||||
# private chat message
|
# private chat message
|
||||||
|
@ -28,8 +28,10 @@ By cloning repository
|
|||||||
Directly using pip
|
Directly using pip
|
||||||
------------------
|
------------------
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
$ pip install git+https://github.com/eternnoir/pyTelegramBotAPI.git
|
$ pip install git+https://github.com/eternnoir/pyTelegramBotAPI.git
|
||||||
|
|
||||||
|
|
||||||
It is generally recommended to use the first option.
|
It is generally recommended to use the first option.
|
||||||
|
|
||||||
While the API is production-ready, it is still under development and it has regular updates, do not forget to update it regularly by calling:
|
While the API is production-ready, it is still under development and it has regular updates, do not forget to update it regularly by calling:
|
||||||
|
@ -278,6 +278,18 @@ class StateFilter(AdvancedCustomFilter):
|
|||||||
async def check(self, message, text):
|
async def check(self, message, text):
|
||||||
if text == '*': return True
|
if text == '*': return True
|
||||||
|
|
||||||
|
# needs to work with callbackquery
|
||||||
|
if isinstance(message, types.Message):
|
||||||
|
chat_id = message.chat.id
|
||||||
|
user_id = message.from_user.id
|
||||||
|
|
||||||
|
if isinstance(message, types.CallbackQuery):
|
||||||
|
|
||||||
|
chat_id = message.message.chat.id
|
||||||
|
user_id = message.from_user.id
|
||||||
|
message = message.message
|
||||||
|
|
||||||
|
|
||||||
if isinstance(text, list):
|
if isinstance(text, list):
|
||||||
new_text = []
|
new_text = []
|
||||||
for i in text:
|
for i in text:
|
||||||
@ -288,7 +300,7 @@ class StateFilter(AdvancedCustomFilter):
|
|||||||
text = text.name
|
text = text.name
|
||||||
|
|
||||||
if message.chat.type == 'group':
|
if message.chat.type == 'group':
|
||||||
group_state = await self.bot.current_states.get_state(message.chat.id, message.from_user.id)
|
group_state = await self.bot.current_states.get_state(user_id, chat_id)
|
||||||
if group_state == text:
|
if group_state == text:
|
||||||
return True
|
return True
|
||||||
elif group_state in text and type(text) is list:
|
elif group_state in text and type(text) is list:
|
||||||
@ -296,7 +308,7 @@ class StateFilter(AdvancedCustomFilter):
|
|||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
user_state = await self.bot.current_states.get_state(message.chat.id, message.from_user.id)
|
user_state = await self.bot.current_states.get_state(user_id, chat_id)
|
||||||
if user_state == text:
|
if user_state == text:
|
||||||
return True
|
return True
|
||||||
elif type(text) is list and user_state in text:
|
elif type(text) is list and user_state in text:
|
||||||
|
@ -5,6 +5,8 @@ from telebot.handler_backends import State
|
|||||||
from telebot import types
|
from telebot import types
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SimpleCustomFilter(ABC):
|
class SimpleCustomFilter(ABC):
|
||||||
"""
|
"""
|
||||||
Simple Custom Filter base class.
|
Simple Custom Filter base class.
|
||||||
@ -281,6 +283,20 @@ class StateFilter(AdvancedCustomFilter):
|
|||||||
|
|
||||||
def check(self, message, text):
|
def check(self, message, text):
|
||||||
if text == '*': return True
|
if text == '*': return True
|
||||||
|
|
||||||
|
# needs to work with callbackquery
|
||||||
|
if isinstance(message, types.Message):
|
||||||
|
chat_id = message.chat.id
|
||||||
|
user_id = message.from_user.id
|
||||||
|
|
||||||
|
if isinstance(message, types.CallbackQuery):
|
||||||
|
|
||||||
|
chat_id = message.message.chat.id
|
||||||
|
user_id = message.from_user.id
|
||||||
|
message = message.message
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if isinstance(text, list):
|
if isinstance(text, list):
|
||||||
new_text = []
|
new_text = []
|
||||||
@ -290,8 +306,9 @@ class StateFilter(AdvancedCustomFilter):
|
|||||||
text = new_text
|
text = new_text
|
||||||
elif isinstance(text, State):
|
elif isinstance(text, State):
|
||||||
text = text.name
|
text = text.name
|
||||||
|
|
||||||
if message.chat.type == 'group':
|
if message.chat.type == 'group':
|
||||||
group_state = self.bot.current_states.get_state(message.chat.id, message.from_user.id)
|
group_state = self.bot.current_states.get_state(user_id, chat_id)
|
||||||
if group_state == text:
|
if group_state == text:
|
||||||
return True
|
return True
|
||||||
elif group_state in text and type(text) is list:
|
elif group_state in text and type(text) is list:
|
||||||
@ -299,7 +316,7 @@ class StateFilter(AdvancedCustomFilter):
|
|||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
user_state = self.bot.current_states.get_state(message.chat.id, message.from_user.id)
|
user_state = self.bot.current_states.get_state(user_id, chat_id)
|
||||||
if user_state == text:
|
if user_state == text:
|
||||||
return True
|
return True
|
||||||
elif type(text) is list and user_state in text:
|
elif type(text) is list and user_state in text:
|
||||||
|
Loading…
Reference in New Issue
Block a user