mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 02:03:04 +00:00
Allow to use datetime and timedelta in until_date argument.
This commit is contained in:
parent
5d81515487
commit
bd91d0acb9
2 changed files with 19 additions and 7 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import datetime
|
||||||
import io
|
import io
|
||||||
from typing import Union, TypeVar, List, Dict, Optional
|
from typing import Union, TypeVar, List, Dict, Optional
|
||||||
|
|
||||||
|
|
@ -727,8 +728,10 @@ class BaseBot:
|
||||||
|
|
||||||
return await self.request(api.Methods.GET_FILE, payload)
|
return await self.request(api.Methods.GET_FILE, payload)
|
||||||
|
|
||||||
async def kick_chat_member(self, chat_id: Union[Integer, String], user_id: Integer,
|
async def kick_chat_member(self, chat_id: Union[Integer, String],
|
||||||
until_date: Union[Integer] = None) -> Boolean:
|
user_id: Integer,
|
||||||
|
until_date: Optional[
|
||||||
|
Union[Integer, datetime.datetime, datetime.timedelta]] = None) -> Boolean:
|
||||||
"""
|
"""
|
||||||
Use this method to kick a user from a group, a supergroup or a channel.
|
Use this method to kick a user from a group, a supergroup or a channel.
|
||||||
In the case of supergroups and channels, the user will not be able to return to the group on their
|
In the case of supergroups and channels, the user will not be able to return to the group on their
|
||||||
|
|
@ -749,6 +752,7 @@ class BaseBot:
|
||||||
:return: In the case of supergroups and channels, the user will not be able to return to the
|
:return: In the case of supergroups and channels, the user will not be able to return to the
|
||||||
group on their own using invite links, etc.
|
group on their own using invite links, etc.
|
||||||
"""
|
"""
|
||||||
|
until_date = prepare_arg(until_date)
|
||||||
payload = generate_payload(**locals())
|
payload = generate_payload(**locals())
|
||||||
|
|
||||||
return await self.request(api.Methods.KICK_CHAT_MEMBER, payload)
|
return await self.request(api.Methods.KICK_CHAT_MEMBER, payload)
|
||||||
|
|
@ -773,11 +777,11 @@ class BaseBot:
|
||||||
|
|
||||||
async def restrict_chat_member(self, chat_id: Union[Integer, String],
|
async def restrict_chat_member(self, chat_id: Union[Integer, String],
|
||||||
user_id: Integer,
|
user_id: Integer,
|
||||||
until_date: Integer,
|
until_date: Optional[Union[Integer, datetime.datetime, datetime.timedelta]] = None,
|
||||||
can_send_messages: Boolean,
|
can_send_messages: Optional[Boolean] = None,
|
||||||
can_send_media_messages: Boolean,
|
can_send_media_messages: Optional[Boolean] = None,
|
||||||
can_send_other_messages: Boolean,
|
can_send_other_messages: Optional[Boolean] = None,
|
||||||
can_add_web_page_previews: Boolean) -> Boolean:
|
can_add_web_page_previews: Optional[Boolean] = None) -> Boolean:
|
||||||
"""
|
"""
|
||||||
Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup
|
Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup
|
||||||
for this to work and must have the appropriate admin rights. Pass True for all Booleanean
|
for this to work and must have the appropriate admin rights. Pass True for all Booleanean
|
||||||
|
|
@ -801,6 +805,7 @@ class BaseBot:
|
||||||
to their messages, implies can_send_media_messages
|
to their messages, implies can_send_media_messages
|
||||||
:return: Returns True on success.
|
:return: Returns True on success.
|
||||||
"""
|
"""
|
||||||
|
until_date = prepare_arg(until_date)
|
||||||
payload = generate_payload(**locals())
|
payload = generate_payload(**locals())
|
||||||
|
|
||||||
return await self.request(api.Methods.RESTRICT_CHAT_MEMBER, payload)
|
return await self.request(api.Methods.RESTRICT_CHAT_MEMBER, payload)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import datetime
|
||||||
|
|
||||||
from . import json
|
from . import json
|
||||||
|
|
||||||
DEFAULT_FILTER = ['self']
|
DEFAULT_FILTER = ['self']
|
||||||
|
|
@ -17,4 +19,9 @@ def prepare_arg(value):
|
||||||
return json.dumps(value)
|
return json.dumps(value)
|
||||||
elif hasattr(value, 'to_json'):
|
elif hasattr(value, 'to_json'):
|
||||||
return json.dumps(value.to_json())
|
return json.dumps(value.to_json())
|
||||||
|
elif isinstance(value, datetime.timedelta):
|
||||||
|
now = datetime.datetime.now()
|
||||||
|
return int((now + value).timestamp())
|
||||||
|
elif isinstance(value, datetime.datetime):
|
||||||
|
return int(value.timestamp())
|
||||||
return value
|
return value
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue