mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Merge pull request #1607 from coder2020official/newfeatures
ReadME update and filter updates
This commit is contained in:
commit
01f9e3b710
@ -398,7 +398,7 @@ Here is example of creating filter-class:
|
|||||||
```python
|
```python
|
||||||
class IsAdmin(telebot.custom_filters.SimpleCustomFilter):
|
class IsAdmin(telebot.custom_filters.SimpleCustomFilter):
|
||||||
# Class will check whether the user is admin or creator in group or not
|
# Class will check whether the user is admin or creator in group or not
|
||||||
key='is_admin'
|
key='is_chat_admin'
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def check(message: telebot.types.Message):
|
def check(message: telebot.types.Message):
|
||||||
return bot.get_chat_member(message.chat.id,message.from_user.id).status in ['administrator','creator']
|
return bot.get_chat_member(message.chat.id,message.from_user.id).status in ['administrator','creator']
|
||||||
@ -407,7 +407,7 @@ class IsAdmin(telebot.custom_filters.SimpleCustomFilter):
|
|||||||
bot.add_custom_filter(IsAdmin())
|
bot.add_custom_filter(IsAdmin())
|
||||||
|
|
||||||
# Now, you can use it in handler.
|
# Now, you can use it in handler.
|
||||||
@bot.message_handler(is_admin=True)
|
@bot.message_handler(is_chat_admin=True)
|
||||||
def admin_of_group(message):
|
def admin_of_group(message):
|
||||||
bot.send_message(message.chat.id, 'You are admin of this group!')
|
bot.send_message(message.chat.id, 'You are admin of this group!')
|
||||||
|
|
||||||
|
@ -201,6 +201,8 @@ class ChatFilter(AdvancedCustomFilter):
|
|||||||
key = 'chat_id'
|
key = 'chat_id'
|
||||||
|
|
||||||
async def check(self, message, text):
|
async def check(self, message, text):
|
||||||
|
if isinstance(message, types.CallbackQuery):
|
||||||
|
return message.message.chat.id in text
|
||||||
return message.chat.id in text
|
return message.chat.id in text
|
||||||
|
|
||||||
|
|
||||||
@ -216,7 +218,7 @@ class ForwardFilter(SimpleCustomFilter):
|
|||||||
key = 'is_forwarded'
|
key = 'is_forwarded'
|
||||||
|
|
||||||
async def check(self, message):
|
async def check(self, message):
|
||||||
return message.forward_from_chat is not None
|
return message.forward_date is not None
|
||||||
|
|
||||||
|
|
||||||
class IsReplyFilter(SimpleCustomFilter):
|
class IsReplyFilter(SimpleCustomFilter):
|
||||||
@ -231,6 +233,8 @@ class IsReplyFilter(SimpleCustomFilter):
|
|||||||
key = 'is_reply'
|
key = 'is_reply'
|
||||||
|
|
||||||
async def check(self, message):
|
async def check(self, message):
|
||||||
|
if isinstance(message, types.CallbackQuery):
|
||||||
|
return message.message.reply_to_message is not None
|
||||||
return message.reply_to_message is not None
|
return message.reply_to_message is not None
|
||||||
|
|
||||||
|
|
||||||
@ -266,6 +270,9 @@ class IsAdminFilter(SimpleCustomFilter):
|
|||||||
self._bot = bot
|
self._bot = bot
|
||||||
|
|
||||||
async def check(self, message):
|
async def check(self, message):
|
||||||
|
if isinstance(message, types.CallbackQuery):
|
||||||
|
result = await self._bot.get_chat_member(message.message.chat.id, message.from_user.id)
|
||||||
|
return result.status ('creator', 'administrator')
|
||||||
result = await self._bot.get_chat_member(message.chat.id, message.from_user.id)
|
result = await self._bot.get_chat_member(message.chat.id, message.from_user.id)
|
||||||
return result.status in ['creator', 'administrator']
|
return result.status in ['creator', 'administrator']
|
||||||
|
|
||||||
|
@ -208,6 +208,8 @@ class ChatFilter(AdvancedCustomFilter):
|
|||||||
key = 'chat_id'
|
key = 'chat_id'
|
||||||
|
|
||||||
def check(self, message, text):
|
def check(self, message, text):
|
||||||
|
if isinstance(message, types.CallbackQuery):
|
||||||
|
return message.message.chat.id in text
|
||||||
return message.chat.id in text
|
return message.chat.id in text
|
||||||
|
|
||||||
|
|
||||||
@ -223,7 +225,7 @@ class ForwardFilter(SimpleCustomFilter):
|
|||||||
key = 'is_forwarded'
|
key = 'is_forwarded'
|
||||||
|
|
||||||
def check(self, message):
|
def check(self, message):
|
||||||
return message.forward_from_chat is not None
|
return message.forward_date is not None
|
||||||
|
|
||||||
|
|
||||||
class IsReplyFilter(SimpleCustomFilter):
|
class IsReplyFilter(SimpleCustomFilter):
|
||||||
@ -238,6 +240,8 @@ class IsReplyFilter(SimpleCustomFilter):
|
|||||||
key = 'is_reply'
|
key = 'is_reply'
|
||||||
|
|
||||||
def check(self, message):
|
def check(self, message):
|
||||||
|
if isinstance(message, types.CallbackQuery):
|
||||||
|
return message.message.reply_to_message is not None
|
||||||
return message.reply_to_message is not None
|
return message.reply_to_message is not None
|
||||||
|
|
||||||
|
|
||||||
@ -273,6 +277,8 @@ class IsAdminFilter(SimpleCustomFilter):
|
|||||||
self._bot = bot
|
self._bot = bot
|
||||||
|
|
||||||
def check(self, message):
|
def check(self, message):
|
||||||
|
if isinstance(message, types.CallbackQuery):
|
||||||
|
return self._bot.get_chat_member(message.message.chat.id, message.from_user.id).status in ['creator', 'administrator']
|
||||||
return self._bot.get_chat_member(message.chat.id, message.from_user.id).status in ['creator', 'administrator']
|
return self._bot.get_chat_member(message.chat.id, message.from_user.id).status in ['creator', 'administrator']
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user