mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2026-06-19 15:45:13 +00:00
Compare commits
41 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c6533a2d69 | |||
| 6c13762c93 | |||
| 06c09b96cf | |||
| 8a5ec3b2a1 | |||
| 21c26aed2f | |||
| 5fe1481ae9 | |||
| 1879cff82d | |||
| cd5e805692 | |||
| 90a77ab7a1 | |||
| 3928e27cf4 | |||
| 45b1124553 | |||
| 252b43dcb7 | |||
| d3d5c1e907 | |||
| cbf66d411d | |||
| 0e5b48f3b4 | |||
| df7cfdc8d0 | |||
| 89015e5ecc | |||
| 025d4c9a75 | |||
| d3bea4c3b4 | |||
| a6c12adda2 | |||
| dcb9129809 | |||
| bd1f171f51 | |||
| 54efb034a4 | |||
| fe94f146bb | |||
| 22b492762b | |||
| fea0c5cc2b | |||
| 688d6af541 | |||
| bcbd32cdd3 | |||
| 3fa8b97ed2 | |||
| 7cd4e2e205 | |||
| f2b0cb46a2 | |||
| cf5d184766 | |||
| 5738dc553f | |||
| 386accab80 | |||
| e7686db759 | |||
| 6c9490f2c6 | |||
| 855ab19dea | |||
| 797a3e6ea4 | |||
| bbd443d397 | |||
| 4e1597c614 | |||
| 75e338d5df |
@@ -8,6 +8,7 @@ python:
|
||||
- "pypy3"
|
||||
install:
|
||||
- pip install coveralls
|
||||
- pip install -r requirements.txt
|
||||
script:
|
||||
nosetests --with-coverage --cover-package telegram/
|
||||
after_success:
|
||||
|
||||
@@ -13,6 +13,7 @@ The following wonderful people contributed directly or indirectly to this projec
|
||||
- `ErgoZ Riftbit Vaper <https://github.com/ergoz>`_
|
||||
- `franciscod <https://github.com/franciscod>`_
|
||||
- `JASON0916 <https://github.com/JASON0916>`_
|
||||
- `jh0ker <https://github.com/jh0ker>`_
|
||||
- `JRoot3D <https://github.com/JRoot3D>`_
|
||||
- `macrojames <https://github.com/macrojames>`_
|
||||
- `njittam <https://github.com/njittam>`_
|
||||
|
||||
+29
-11
@@ -1,3 +1,32 @@
|
||||
2015-11-10
|
||||
Released 2.9
|
||||
Emoji class now uses bytes_to_native_str from future 3rd party lib
|
||||
Make user_from optional to work with channels channels
|
||||
Raise exception if Telegram times out on long-polling
|
||||
*Special thanks to @jh0ker for all hard work*
|
||||
|
||||
|
||||
2015-10-08
|
||||
Released 2.8.7
|
||||
Type as optional for GroupChat class
|
||||
|
||||
|
||||
2015-10-08
|
||||
Released 2.8.6
|
||||
Adds type to User and GroupChat classes (pre-release Telegram feature)
|
||||
|
||||
|
||||
2015-09-24
|
||||
Released 2.8.5
|
||||
Handles HTTP Bad Gateway (503) errors on request
|
||||
Fixes regression on Audio and Document for unicode fields
|
||||
|
||||
|
||||
2015-09-20
|
||||
Released 2.8.4
|
||||
getFile and File.download is now fully supported
|
||||
|
||||
|
||||
2015-09-10
|
||||
Released 2.8.3
|
||||
Moved Bot._requestURL to its own class (telegram.utils.request)
|
||||
@@ -100,7 +129,6 @@
|
||||
|
||||
|
||||
2015-07-19
|
||||
|
||||
Released 2.0
|
||||
Fixes bugs
|
||||
Improves __str__ over to_json()
|
||||
@@ -108,51 +136,43 @@
|
||||
|
||||
|
||||
2015-07-15
|
||||
|
||||
Released 1.9
|
||||
Python 3 officially supported
|
||||
PEP8 improvements
|
||||
|
||||
|
||||
2015-07-12
|
||||
|
||||
Released 1.8
|
||||
Fixes crash when replying an unicode text message (special thanks to JRoot3D)
|
||||
|
||||
|
||||
2015-07-11
|
||||
|
||||
Released 1.7
|
||||
Fixes crash when username is not defined on chat (special thanks to JRoot3D)
|
||||
|
||||
|
||||
2015-07-10
|
||||
|
||||
Released 1.6
|
||||
Improvements for GAE support
|
||||
|
||||
|
||||
2015-07-10
|
||||
|
||||
Released 1.5
|
||||
Fixes randomly unicode issues when using InputFile
|
||||
|
||||
|
||||
2015-07-10
|
||||
|
||||
Released 1.4
|
||||
requests lib is no longer required
|
||||
Google App Engine (GAE) is supported
|
||||
|
||||
|
||||
2015-07-10
|
||||
|
||||
Released 1.3
|
||||
Added support to setWebhook (special thanks to macrojames)
|
||||
|
||||
|
||||
2015-07-09
|
||||
|
||||
Released 1.2
|
||||
CustomKeyboard classes now available
|
||||
Emojis available
|
||||
@@ -160,12 +180,10 @@
|
||||
|
||||
|
||||
2015-07-08
|
||||
|
||||
Released 1.1
|
||||
PyPi package now available
|
||||
|
||||
|
||||
2015-07-08
|
||||
|
||||
Released 1.0
|
||||
Initial checkin of python-telegram-bot
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.PHONY: clean pep8 lint test
|
||||
.PHONY: clean pep8 lint test install
|
||||
|
||||
clean:
|
||||
rm -fr build
|
||||
@@ -16,6 +16,9 @@ lint:
|
||||
test:
|
||||
nosetests
|
||||
|
||||
install:
|
||||
pip install -r requirements.txt
|
||||
|
||||
help:
|
||||
@echo "Available targets:"
|
||||
@echo "- clean Clean up the source directory"
|
||||
|
||||
+4
-2
@@ -2,6 +2,8 @@ Python Telegram Bot
|
||||
|
||||
A Python wrapper around the Telegram Bot API.
|
||||
|
||||
*Stay tuned for library updates and new releases on our* `Telegram Channel <http://telegram.me/pythontelegrambotchannel>`_.
|
||||
|
||||
By `Leandro Toledo <leandrotoledodesouza@gmail.com>`_
|
||||
|
||||
.. image:: https://img.shields.io/pypi/v/python-telegram-bot.svg
|
||||
@@ -16,7 +18,7 @@ By `Leandro Toledo <leandrotoledodesouza@gmail.com>`_
|
||||
:target: https://readthedocs.org/projects/python-telegram-bot/?badge=latest
|
||||
:alt: Documentation Status
|
||||
|
||||
.. image:: https://img.shields.io/github/license/leandrotoledo/python-telegram-bot.svg
|
||||
.. image:: https://img.shields.io/pypi/l/python-telegram-bot.svg
|
||||
:target: http://www.gnu.org/licenses/lgpl-3.0.html
|
||||
:alt: LGPLv3 License
|
||||
|
||||
@@ -275,7 +277,7 @@ You may copy, distribute and modify the software provided that modifications are
|
||||
_`Contact`
|
||||
==========
|
||||
|
||||
Feel free to join to our `Telegram group <https://telegram.me/joinchat/00b9c0f802509b94d52953d3fa1ec504>`_.
|
||||
Feel free to join to our `Telegram group <https://telegram.me/joinchat/ALnA-AJQm5SEwuAzar3nvw>`_.
|
||||
|
||||
If you face trouble joining in the group please ping me `via Telegram <https://telegram.me/leandrotoledo>`_, I'll be glad to add you.
|
||||
|
||||
|
||||
+2
-2
@@ -58,9 +58,9 @@ author = u'Leandro Toledo'
|
||||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = '2.8'
|
||||
version = '2.9'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = '2.8.3'
|
||||
release = '2.9'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
|
||||
+3
-3
@@ -51,12 +51,12 @@ def echo(bot):
|
||||
for update in bot.getUpdates(offset=LAST_UPDATE_ID, timeout=10):
|
||||
# chat_id is required to reply any message
|
||||
chat_id = update.message.chat_id
|
||||
message = update.message.text.encode('utf-8')
|
||||
reply_text = update.message.text
|
||||
|
||||
if (message):
|
||||
if (reply_text):
|
||||
# Reply the message
|
||||
bot.sendMessage(chat_id=chat_id,
|
||||
text=message)
|
||||
text=reply_text)
|
||||
|
||||
# Updates global offset to get the new updates
|
||||
LAST_UPDATE_ID = update.update_id + 1
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
future
|
||||
@@ -15,7 +15,7 @@ def read(*paths):
|
||||
|
||||
setup(
|
||||
name='python-telegram-bot',
|
||||
version='2.8.3',
|
||||
version='2.9',
|
||||
author='Leandro Toledo',
|
||||
author_email='leandrotoledodesouza@gmail.com',
|
||||
license='LGPLv3',
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
"""A library that provides a Python interface to the Telegram Bot API"""
|
||||
|
||||
__author__ = 'leandrotoledodesouza@gmail.com'
|
||||
__version__ = '2.8.3'
|
||||
__version__ = '2.8.7'
|
||||
|
||||
from .base import TelegramObject
|
||||
from .user import User
|
||||
|
||||
+2
-2
@@ -52,8 +52,8 @@ class Audio(TelegramObject):
|
||||
self.file_id = str(file_id)
|
||||
self.duration = int(duration)
|
||||
# Optionals
|
||||
self.performer = str(kwargs.get('performer', ''))
|
||||
self.title = str(kwargs.get('title', ''))
|
||||
self.performer = kwargs.get('performer', '')
|
||||
self.title = kwargs.get('title', '')
|
||||
self.mime_type = str(kwargs.get('mime_type', ''))
|
||||
self.file_size = int(kwargs.get('file_size', 0))
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ class Document(TelegramObject):
|
||||
self.file_id = str(file_id)
|
||||
# Optionals
|
||||
self.thumb = kwargs.get('thumb')
|
||||
self.file_name = str(kwargs.get('file_name', ''))
|
||||
self.file_name = kwargs.get('file_name', '')
|
||||
self.mime_type = str(kwargs.get('mime_type', ''))
|
||||
self.file_size = int(kwargs.get('file_size', 0))
|
||||
|
||||
|
||||
+844
-842
File diff suppressed because it is too large
Load Diff
@@ -28,18 +28,26 @@ class GroupChat(TelegramObject):
|
||||
Attributes:
|
||||
id (int):
|
||||
title (str):
|
||||
type (str):
|
||||
|
||||
Args:
|
||||
id (int):
|
||||
title (str):
|
||||
**kwargs: Arbitrary keyword arguments.
|
||||
|
||||
Keyword Args:
|
||||
type (Optional[str]):
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
id,
|
||||
title):
|
||||
title,
|
||||
**kwargs):
|
||||
# Required
|
||||
self.id = int(id)
|
||||
self.title = title
|
||||
# Optionals
|
||||
self.type = kwargs.get('type', '')
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
|
||||
+2
-2
@@ -134,7 +134,7 @@ class Message(TelegramObject):
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['from_user'] = User.de_json(data['from'])
|
||||
data['from_user'] = User.de_json(data.get('from'))
|
||||
data['date'] = datetime.fromtimestamp(data['date'])
|
||||
if 'first_name' in data.get('chat', ''):
|
||||
data['chat'] = User.de_json(data.get('chat'))
|
||||
@@ -185,7 +185,7 @@ class Message(TelegramObject):
|
||||
data = super(Message, self).to_dict()
|
||||
|
||||
# Required
|
||||
data['from'] = data.pop('from_user')
|
||||
data['from'] = data.pop('from_user', None)
|
||||
data['date'] = self._totimestamp(self.date)
|
||||
# Optionals
|
||||
if self.forward_date:
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents a Telegram Message Parse Modes"""
|
||||
"""This module contains a object that represents a Telegram
|
||||
Message Parse Modes"""
|
||||
|
||||
|
||||
class ParseMode(object):
|
||||
|
||||
+4
-1
@@ -23,13 +23,14 @@ from telegram import TelegramObject
|
||||
|
||||
|
||||
class User(TelegramObject):
|
||||
"""This object represents a Telegram Sticker.
|
||||
"""This object represents a Telegram User.
|
||||
|
||||
Attributes:
|
||||
id (int):
|
||||
first_name (str):
|
||||
last_name (str):
|
||||
username (str):
|
||||
type (str):
|
||||
|
||||
Args:
|
||||
id (int):
|
||||
@@ -37,6 +38,7 @@ class User(TelegramObject):
|
||||
**kwargs: Arbitrary keyword arguments.
|
||||
|
||||
Keyword Args:
|
||||
type (Optional[str]):
|
||||
last_name (Optional[str]):
|
||||
username (Optional[str]):
|
||||
"""
|
||||
@@ -49,6 +51,7 @@ class User(TelegramObject):
|
||||
self.id = int(id)
|
||||
self.first_name = first_name
|
||||
# Optionals
|
||||
self.type = kwargs.get('type', '')
|
||||
self.last_name = kwargs.get('last_name', '')
|
||||
self.username = kwargs.get('username', '')
|
||||
|
||||
|
||||
@@ -20,15 +20,15 @@
|
||||
"""This module contains methods to make POST and GET requests"""
|
||||
|
||||
import json
|
||||
from ssl import SSLError
|
||||
|
||||
try:
|
||||
from urllib.parse import urlencode
|
||||
from urllib.request import urlopen, urlretrieve, Request
|
||||
from urllib.error import HTTPError, URLError
|
||||
from urllib.error import HTTPError
|
||||
except ImportError:
|
||||
from urllib import urlencode, urlretrieve
|
||||
from urllib import urlretrieve
|
||||
from urllib2 import urlopen, Request
|
||||
from urllib2 import HTTPError, URLError
|
||||
from urllib2 import HTTPError
|
||||
|
||||
from telegram import (InputFile, TelegramError)
|
||||
|
||||
@@ -78,6 +78,14 @@ def post(url,
|
||||
Returns:
|
||||
A JSON object.
|
||||
"""
|
||||
|
||||
# Add one second to the timeout of urlopen to allow data to be transferred
|
||||
# over the network.
|
||||
if 'timeout' in data:
|
||||
timeout = data['timeout'] + 1.
|
||||
else:
|
||||
timeout = None
|
||||
|
||||
try:
|
||||
if InputFile.is_inputfile(data):
|
||||
data = InputFile(data)
|
||||
@@ -90,14 +98,20 @@ def post(url,
|
||||
data=data.encode(),
|
||||
headers={'Content-Type': 'application/json'})
|
||||
|
||||
result = urlopen(request).read()
|
||||
result = urlopen(request, timeout=timeout).read()
|
||||
except HTTPError as error:
|
||||
if error.getcode() == 403:
|
||||
raise TelegramError('Unauthorized')
|
||||
if error.getcode() == 502:
|
||||
raise TelegramError('Bad Gateway')
|
||||
|
||||
message = _parse(error.read())
|
||||
raise TelegramError(message)
|
||||
except SSLError as error:
|
||||
if "The read operation timed out" == error.message:
|
||||
raise TelegramError("Timed out")
|
||||
|
||||
raise TelegramError(error.message)
|
||||
return _parse(result)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015 Leandro Toledo de Souza <leandrotoeldodesouza@gmail.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram Emoji"""
|
||||
|
||||
import os
|
||||
import unittest
|
||||
import sys
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from telegram.emoji import Emoji
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class EmojiTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram Emoji."""
|
||||
|
||||
def test_emoji(self):
|
||||
"""Test Emoji class"""
|
||||
print('Testing Emoji class')
|
||||
|
||||
for attr in dir(Emoji):
|
||||
if attr[0] != '_': # TODO: dirty way to filter out functions
|
||||
self.assertTrue(type(getattr(Emoji, attr)) is str)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -33,10 +33,12 @@ class GroupChatTest(BaseTest, unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.id = -28767330
|
||||
self.title = 'ToledosPalaceBot - Group'
|
||||
self.type = 'group'
|
||||
|
||||
self.json_dict = {
|
||||
'id': self.id,
|
||||
'title': self.title
|
||||
'title': self.title,
|
||||
'type': self.type
|
||||
}
|
||||
|
||||
def test_group_chat_de_json_empty_json(self):
|
||||
@@ -55,6 +57,7 @@ class GroupChatTest(BaseTest, unittest.TestCase):
|
||||
|
||||
self.assertEqual(group_chat.id, self.id)
|
||||
self.assertEqual(group_chat.title, self.title)
|
||||
self.assertEqual(group_chat.type, self.type)
|
||||
|
||||
def test_group_chat_to_json(self):
|
||||
"""Test GroupChat.to_json() method"""
|
||||
@@ -73,6 +76,7 @@ class GroupChatTest(BaseTest, unittest.TestCase):
|
||||
self.assertTrue(self.is_dict(group_chat.to_dict()))
|
||||
self.assertEqual(group_chat['id'], self.id)
|
||||
self.assertEqual(group_chat['title'], self.title)
|
||||
self.assertEqual(group_chat['type'], self.type)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
+6
-1
@@ -35,12 +35,14 @@ class UserTest(BaseTest, unittest.TestCase):
|
||||
self.first_name = "Leandro"
|
||||
self.last_name = "S."
|
||||
self.username = "leandrotoledo"
|
||||
self.type = "private"
|
||||
|
||||
self.json_dict = {
|
||||
'id': self.id,
|
||||
'first_name': self.first_name,
|
||||
'last_name': self.last_name,
|
||||
'username': self.username
|
||||
'username': self.username,
|
||||
'type': self.type
|
||||
}
|
||||
|
||||
def test_user_de_json(self):
|
||||
@@ -53,6 +55,7 @@ class UserTest(BaseTest, unittest.TestCase):
|
||||
self.assertEqual(user.first_name, self.first_name)
|
||||
self.assertEqual(user.last_name, self.last_name)
|
||||
self.assertEqual(user.username, self.username)
|
||||
self.assertEqual(user.type, self.type)
|
||||
|
||||
self.assertEqual(user.name, '@leandrotoledo')
|
||||
|
||||
@@ -69,6 +72,7 @@ class UserTest(BaseTest, unittest.TestCase):
|
||||
self.assertEqual(user.id, self.id)
|
||||
self.assertEqual(user.first_name, self.first_name)
|
||||
self.assertEqual(user.last_name, self.last_name)
|
||||
self.assertEqual(user.type, self.type)
|
||||
|
||||
self.assertEqual(user.name, '%s %s' % (self.first_name, self.last_name))
|
||||
|
||||
@@ -108,6 +112,7 @@ class UserTest(BaseTest, unittest.TestCase):
|
||||
self.assertEqual(user['first_name'], self.first_name)
|
||||
self.assertEqual(user['last_name'], self.last_name)
|
||||
self.assertEqual(user['username'], self.username)
|
||||
self.assertEqual(user['type'], self.type)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user