Skip to content

Commit

Permalink
Merge pull request eternnoir#1270 from Badiboy/master
Browse files Browse the repository at this point in the history
Check and update for full compatibility to Bot API up to 5.3
  • Loading branch information
Badiboy authored Aug 18, 2021
2 parents 3232811 + f6359bc commit 6e871b8
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 30 deletions.
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# <p align="center">pyTelegramBotAPI

<p align="center">A simple, but extensible Python implementation for the <a href="https://core.telegram.org/bots/api">Telegram Bot API</a>.

[![PyPi Package Version](https://img.shields.io/pypi/v/pyTelegramBotAPI.svg)](https://pypi.python.org/pypi/pyTelegramBotAPI)
[![Supported Python versions](https://img.shields.io/pypi/pyversions/pyTelegramBotAPI.svg)](https://pypi.python.org/pypi/pyTelegramBotAPI)
[![Build Status](https://travis-ci.org/eternnoir/pyTelegramBotAPI.svg?branch=master)](https://travis-ci.org/eternnoir/pyTelegramBotAPI)
[![PyPi downloads](https://img.shields.io/pypi/dm/pyTelegramBotAPI.svg)](https://pypi.org/project/pyTelegramBotAPI/)

# <p align="center">pyTelegramBotAPI

<p align="center">A simple, but extensible Python implementation for the <a href="https://core.telegram.org/bots/api">Telegram Bot API</a>.

## <p align="center">Supported Bot API version: <a href="https://core.telegram.org/bots/api#june-25-2021">5.3</a>!

##Contents

* [Getting started.](#getting-started)
* [Writing your first bot](#writing-your-first-bot)
* [Prerequisites](#prerequisites)
Expand Down Expand Up @@ -603,21 +608,20 @@ apihelper.proxy = {'https':'socks5://userproxy:password@proxy_address:port'}

## API conformance

_Checking is in progress..._

[Bot API 5.1](https://core.telegram.org/bots/api#march-9-2021) _- To be checked..._

*[Bot API 5.3](https://core.telegram.org/bots/api#june-25-2021) - ChatMemberXXX classes are full copies of ChatMember
*[Bot API 5.2](https://core.telegram.org/bots/api#april-26-2021)
*[Bot API 5.1](https://core.telegram.org/bots/api#march-9-2021)
*[Bot API 5.0](https://core.telegram.org/bots/api-changelog#november-4-2020)
*[Bot API 4.9](https://core.telegram.org/bots/api-changelog#june-4-2020)
*[Bot API 4.8](https://core.telegram.org/bots/api-changelog#april-24-2020)
*[Bot API 4.7](https://core.telegram.org/bots/api-changelog#march-30-2020)
*[Bot API 4.6](https://core.telegram.org/bots/api-changelog#january-23-2020)
*[Bot API 4.5](https://core.telegram.org/bots/api-changelog#december-31-2019) - No nested MessageEntities and Markdown2 support.
*[Bot API 4.5](https://core.telegram.org/bots/api-changelog#december-31-2019) - No nested MessageEntities and Markdown2 support
*[Bot API 4.4](https://core.telegram.org/bots/api-changelog#july-29-2019)
*[Bot API 4.3](https://core.telegram.org/bots/api-changelog#may-31-2019)
*[Bot API 4.2](https://core.telegram.org/bots/api-changelog#april-14-2019)
*[Bot API 4.1](https://core.telegram.org/bots/api-changelog#august-27-2018) - No Passport support.
*[Bot API 4.0](https://core.telegram.org/bots/api-changelog#july-26-2018) - No Passport support.
*[Bot API 4.1](https://core.telegram.org/bots/api-changelog#august-27-2018) - No Passport support
*[Bot API 4.0](https://core.telegram.org/bots/api-changelog#july-26-2018) - No Passport support
*[Bot API 3.6](https://core.telegram.org/bots/api-changelog#february-13-2018)
*[Bot API 3.5](https://core.telegram.org/bots/api-changelog#november-17-2017)
*[Bot API 3.4](https://core.telegram.org/bots/api-changelog#october-11-2017)
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
py==1.10.0
pytest==3.0.2
requests==2.20.0
wheel==0.24.0
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def read(filename):
install_requires=['requests'],
extras_require={
'json': 'ujson',
'PIL': 'Pillow',
'redis': 'redis>=3.4.1'
},
classifiers=[
Expand Down
3 changes: 1 addition & 2 deletions telebot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from datetime import datetime

import logging
Expand Down Expand Up @@ -1986,7 +1985,7 @@ def send_invoice(
timeout: Optional[int]=None,
allow_sending_without_reply: Optional[bool]=None,
max_tip_amount: Optional[int] = None,
suggested_tip_amounts: Optional[list]=None) -> types.Message:
suggested_tip_amounts: Optional[List[int]]=None) -> types.Message:
"""
Sends invoice
:param chat_id: Unique identifier for the target private chat
Expand Down
15 changes: 9 additions & 6 deletions telebot/apihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,11 +973,11 @@ def create_chat_invite_link(token, chat_id, expire_date, member_limit):
}

if expire_date is not None:
payload['expire_date'] = expire_date
if isinstance(payload['expire_date'], datetime):
payload['expire_date'] = payload['expire_date'].timestamp()

if member_limit is not None:
else:
payload['expire_date'] = expire_date
if member_limit:
payload['member_limit'] = member_limit

return _make_request(token, method_url, params=payload, method='post')
Expand All @@ -991,9 +991,10 @@ def edit_chat_invite_link(token, chat_id, invite_link, expire_date, member_limit
}

if expire_date is not None:
payload['expire_date'] = expire_date
if isinstance(payload['expire_date'], datetime):
payload['expire_date'] = payload['expire_date'].timestamp()
else:
payload['expire_date'] = expire_date

if member_limit is not None:
payload['member_limit'] = member_limit
Expand Down Expand Up @@ -1258,7 +1259,7 @@ def get_game_high_scores(token, user_id, chat_id=None, message_id=None, inline_m

def send_invoice(
token, chat_id, title, description, invoice_payload, provider_token, currency, prices,
start_parameter, photo_url=None, photo_size=None, photo_width=None, photo_height=None,
start_parameter = None, photo_url=None, photo_size=None, photo_width=None, photo_height=None,
need_name=None, need_phone_number=None, need_email=None, need_shipping_address=None,
send_phone_number_to_provider = None, send_email_to_provider = None, is_flexible=None,
disable_notification=None, reply_to_message_id=None, reply_markup=None, provider_data=None,
Expand Down Expand Up @@ -1298,8 +1299,10 @@ def send_invoice(
"""
method_url = r'sendInvoice'
payload = {'chat_id': chat_id, 'title': title, 'description': description, 'payload': invoice_payload,
'provider_token': provider_token, 'start_parameter': start_parameter, 'currency': currency,
'provider_token': provider_token, 'currency': currency,
'prices': _convert_list_json_serializable(prices)}
if start_parameter:
payload['start_parameter'] = start_parameter
if photo_url:
payload['photo_url'] = photo_url
if photo_size:
Expand Down
42 changes: 34 additions & 8 deletions telebot/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,10 @@ def de_json(cls, json_string):
opts['voice_chat_ended'] = VoiceChatEnded.de_json(obj['voice_chat_ended'])
content_type = 'voice_chat_ended'
if 'voice_chat_participants_invited' in obj:
opts['voice_chat_participants_invited'] = VoiceChatParticipantsInvited.de_json(
obj['voice_chat_participants_invited'])
opts['voice_chat_participants_invited'] = VoiceChatParticipantsInvited.de_json(obj['voice_chat_participants_invited'])
content_type = 'voice_chat_participants_invited'
if 'message_auto_delete_timer_changed' in obj:
opts['message_auto_delete_timer_changed'] = MessageAutoDeleteTimerChanged.de_json(
obj['message_auto_delete_timer_changed'])
opts['message_auto_delete_timer_changed'] = MessageAutoDeleteTimerChanged.de_json(obj['message_auto_delete_timer_changed'])
content_type = 'message_auto_delete_timer_changed'
if 'reply_markup' in obj:
opts['reply_markup'] = InlineKeyboardMarkup.de_json(obj['reply_markup'])
Expand Down Expand Up @@ -1232,6 +1230,29 @@ def __init__(self, user, status, custom_title=None, is_anonymous=None, can_be_ed
self.until_date: int = until_date


class ChatMemberOwner(ChatMember):
pass

class ChatMemberAdministrator(ChatMember):
pass


class ChatMemberMember(ChatMember):
pass


class ChatMemberRestricted(ChatMember):
pass


class ChatMemberLeft(ChatMember):
pass


class ChatMemberBanned(ChatMember):
pass


class ChatPermissions(JsonDeserializable, JsonSerializable, Dictionaryable):
@classmethod
def de_json(cls, json_string):
Expand Down Expand Up @@ -2744,14 +2765,18 @@ def to_json(self):
return json.dumps(self.to_dict())

def to_dict(self):
return {
json_dict = {
"invite_link": self.invite_link,
"creator": self.creator.to_dict(),
"is_primary": self.is_primary,
"is_revoked": self.is_revoked,
"expire_date": self.expire_date,
"member_limit": self.member_limit
"is_revoked": self.is_revoked
}
if self.expire_date:
json_dict["expire_date"] = self.expire_date
if self.member_limit:
json_dict["member_limit"] = self.member_limit
return json_dict


class ProximityAlertTriggered(JsonDeserializable):
@classmethod
Expand All @@ -2778,6 +2803,7 @@ def __init__(self):
"""
pass


class VoiceChatScheduled(JsonDeserializable):
@classmethod
def de_json(cls, json_string):
Expand Down
4 changes: 2 additions & 2 deletions telebot/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
import string
import threading
import traceback
import warnings
import functools
from typing import Any, Callable, List, Dict, Optional, Union

# noinspection PyPep8Naming
import queue as Queue
import logging

from telebot import types

try:
# noinspection PyPackageRequirements
from PIL import Image
from io import BytesIO
pil_imported = True
Expand Down
2 changes: 1 addition & 1 deletion telebot/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Versions should comply with PEP440.
# This line is parsed in setup.py:
__version__ = '3.8.2'
__version__ = '3.8.3'

0 comments on commit 6e871b8

Please sign in to comment.