1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Fix restrict_chat_member until_date bug

This commit is contained in:
Badiboy 2021-01-14 15:45:47 +03:00
parent 82838e1d26
commit f56da17741

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import time import time
import datetime
try: try:
import ujson as json import ujson as json
@ -709,7 +710,9 @@ def get_method_by_type(data_type):
def kick_chat_member(token, chat_id, user_id, until_date=None): def kick_chat_member(token, chat_id, user_id, until_date=None):
method_url = 'kickChatMember' method_url = 'kickChatMember'
payload = {'chat_id': chat_id, 'user_id': user_id} payload = {'chat_id': chat_id, 'user_id': user_id}
if until_date: if isinstance(until_date, datetime.datetime):
payload['until_date'] = until_date.timestamp()
else:
payload['until_date'] = until_date payload['until_date'] = until_date
return _make_request(token, method_url, params=payload, method='post') return _make_request(token, method_url, params=payload, method='post')
@ -730,8 +733,6 @@ def restrict_chat_member(
can_invite_users=None, can_pin_messages=None): can_invite_users=None, can_pin_messages=None):
method_url = 'restrictChatMember' method_url = 'restrictChatMember'
permissions = {} permissions = {}
if until_date is not None:
permissions['until_date'] = until_date
if can_send_messages is not None: if can_send_messages is not None:
permissions['can_send_messages'] = can_send_messages permissions['can_send_messages'] = can_send_messages
if can_send_media_messages is not None: if can_send_media_messages is not None:
@ -750,6 +751,11 @@ def restrict_chat_member(
permissions['can_pin_messages'] = can_pin_messages permissions['can_pin_messages'] = can_pin_messages
permissions_json = json.dumps(permissions) permissions_json = json.dumps(permissions)
payload = {'chat_id': chat_id, 'user_id': user_id, 'permissions': permissions_json} payload = {'chat_id': chat_id, 'user_id': user_id, 'permissions': permissions_json}
if until_date is not None:
if isinstance(until_date, datetime.datetime):
payload['until_date'] = until_date.timestamp()
else:
payload['until_date'] = until_date
return _make_request(token, method_url, params=payload, method='post') return _make_request(token, method_url, params=payload, method='post')
@ -1246,7 +1252,10 @@ def send_poll(
if open_period is not None: if open_period is not None:
payload['open_period'] = open_period payload['open_period'] = open_period
if close_date is not None: if close_date is not None:
payload['close_date'] = close_date if isinstance(close_date, datetime.datetime):
payload['close_date'] = close_date.timestamp()
else:
payload['close_date'] = close_date
if is_closed is not None: if is_closed is not None:
payload['is_closed'] = is_closed payload['is_closed'] = is_closed