Skip to content

Commit f623db0

Browse files
committed
Revert "Feature/requests"
1 parent 026673d commit f623db0

13 files changed

Lines changed: 579 additions & 124 deletions

File tree

CHANGES.rst

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,3 @@
1-
2015-09-10
2-
Released 2.8.3
3-
Moved Bot._requestURL to its own class (telegram.utils.request)
4-
Much better, such wow, Telegram Objects tests
5-
Add consistency for str properties on Telegram Objects
6-
Better design to test if chat_id is invalid
7-
Add ability to set custom filename on Bot.sendDocument(..,filename='')
8-
Fix Sticker as InputFile
9-
Send JSON requests over urlencoded post data
10-
Markdown support for Bot.sendMessage(..., parse_mode=ParseMode.MARKDOWN)
11-
Refactor of TelegramError class (no more handling IOError or URLError)
12-
13-
14-
2015-09-05
15-
Released 2.8.2
16-
Fix regression on Telegram ReplyMarkup
17-
Add certificate to is_inputfile method
18-
19-
201
2015-09-05
212
Released 2.8.1
223
Fix regression on Telegram objects with thumb properties

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,9 @@ You may copy, distribute and modify the software provided that modifications are
268268
_`Contact`
269269
==========
270270

271-
Feel free to join to our `Telegram group <https://telegram.me/joinchat/00b9c0f802509b946b2e8e98b73e19be>`_.
271+
Feel free to join to our `Telegram group <https://telegram.me/joinchat/00b9c0f802509b94d52953d3fa1ec504>`_.
272272

273-
If you face trouble joining in the group please ping me `via Telegram <https://telegram.me/leandrotoledo>`_, I'll be glad to add you.
273+
*If you face trouble joining in the group please ping me on Telegram (@leandrotoledo), I'll be glad to add you.*
274274

275275
=======
276276
_`TODO`

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
# The short X.Y version.
6161
version = '2.8'
6262
# The full version, including alpha/beta/rc tags.
63-
release = '2.8.3'
63+
release = '2.8.1'
6464

6565
# The language for content autogenerated by Sphinx. Refer to documentation
6666
# for a list of supported languages.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
from telegram import CommandHandlerWithHelpAndFather, CommandHandler
2+
class ExampleCommandHandler(CommandHandlerWithHelpAndFather):
3+
"""This is an example how to use a CommandHandlerWithHelp or just a CommandHandler.
4+
5+
If You want to use a CommandHandler it is very easy.
6+
create a class which inherits a CommandHandler.
7+
create a method in this class which start with 'command_' and takes 1 argument: 'update' (which comes directly from
8+
getUpdate()).
9+
If you inherit CommandHandlerWithHelp it also creates a nice /help for you.
10+
"""
11+
def __init__(self, bot): # only necessary for a WithHelp
12+
super(ExampleCommandHandler, self).__init__(bot)
13+
self._help_title = 'Welcome this is a help file!' # optional
14+
self._help_before_list = """
15+
Yeah here I explain some things about this bot.
16+
and of course I can do this in Multiple lines.
17+
""" # default is empty
18+
self._help_list_title = ' These are the available commands:' # optional
19+
self._help_after_list = ' These are some footnotes' # default is empty
20+
self.is_reply = True # default is True
21+
22+
# only necessary if you want to override to default
23+
def _command_not_found(self, update):
24+
"""Inform the telegram user that the command was not found."""
25+
chat_id = update.message.chat.id
26+
reply_to = update.message.message_id
27+
message = "Sorry, I don't know how to do {command}.".format(command=update.message.text.split(' ')[0])
28+
self.bot.sendMessage(chat_id=chat_id, text=message, reply_to_message_id=reply_to)
29+
30+
# creates /test command. This code gets called when a telegram user enters /test
31+
def command_test(self, update):
32+
""" Test if the server is online. """
33+
chat_id = update.message.chat.id
34+
reply_to = update.message.message_id
35+
message = 'Yeah, the server is online!'
36+
self.bot.sendMessage(chat_id=chat_id, text=message, reply_to_message_id=reply_to)
37+
38+
# creates /parrot command
39+
def command_parrot(self, update):
40+
""" Says back what you say after the command"""
41+
chat_id = update.message.chat.id
42+
reply_to = update.message.message_id
43+
send = update.message.text.split(' ')
44+
message = update.message.text[len(send[0]):]
45+
if len(send) == 1:
46+
message = '...'
47+
self.bot.sendMessage(chat_id=chat_id, text=message, reply_to_message_id=reply_to)
48+
49+
# creates /p command
50+
def command_p(self, update):
51+
"""Does the same as parrot."""
52+
return self.command_parrot(update)
53+
54+
# this doesn't create a command.
55+
def another_test(self, update):
56+
""" This won't be called by the CommandHandler.
57+
58+
This is an example of a function that isn't a command in telegram.
59+
Because it didn't start with 'command_'.
60+
"""
61+
chat_id = update.message.chat.id
62+
reply_to = update.message.message_id
63+
message = 'Yeah, this is another test'
64+
self.bot.sendMessage(chat_id=chat_id, text=message, reply_to_message_id=reply_to)
65+
66+
67+
class Exampe2CommandHandler(CommandHandler):
68+
"""
69+
This is an example of a small working CommandHandler with only one command.
70+
"""
71+
def command_test(self, update):
72+
""" Test if the server is online. """
73+
chat_id = update.message.chat.id
74+
reply_to = update.message.message_id
75+
message = 'Yeah, the server is online!'
76+
self.bot.sendMessage(chat_id=chat_id, text=message, reply_to_message_id=reply_to)
77+
78+
if __name__ == '__main__':
79+
import telegram as telegram
80+
try:
81+
from mytoken import token
82+
except:
83+
token = '' # use your own token here
84+
print ('token = ', token)
85+
Bot = telegram.Bot(token=token)
86+
test_command_handler = ExampleCommandHandler(Bot)
87+
test_command_handler.run()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def read(*paths):
1515

1616
setup(
1717
name='python-telegram-bot',
18-
version='2.8.3',
18+
version='2.8.1',
1919
author='Leandro Toledo',
2020
author_email='leandrotoledodesouza@gmail.com',
2121
license='LGPLv3',

telegram/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"""A library that provides a Python interface to the Telegram Bot API"""
2020

2121
__author__ = 'leandrotoledodesouza@gmail.com'
22-
__version__ = '2.8.3'
22+
__version__ = '2.8.1'
2323

2424
from .base import TelegramObject
2525
from .user import User
@@ -46,10 +46,12 @@
4646
from .message import Message
4747
from .update import Update
4848
from .bot import Bot
49+
from .command_handler import *
4950

5051
__all__ = ['Bot', 'Emoji', 'TelegramError', 'InputFile', 'ReplyMarkup',
5152
'ForceReply', 'ReplyKeyboardHide', 'ReplyKeyboardMarkup',
5253
'UserProfilePhotos', 'ChatAction', 'Location', 'Contact',
5354
'Video', 'Sticker', 'Document', 'Audio', 'PhotoSize', 'GroupChat',
54-
'Update', 'ParseMode', 'Message', 'User', 'TelegramObject',
55-
'NullHandler', 'Voice']
55+
'Update', 'ParseMode', 'Message', 'User', 'TelegramObject', 'NullHandler',
56+
'Voice', 'CommandHandler', 'CommandHandlerWithHelp',
57+
'CommandHandlerWithFatherCommand', 'CommandHandlerWithHelpAndFather']

telegram/bot.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,7 @@ def getUserProfilePhotos(self,
619619
def getUpdates(self,
620620
offset=None,
621621
limit=100,
622-
timeout=0,
623-
requestTimeout=None):
622+
timeout=0):
624623
"""Use this method to receive incoming updates using long polling.
625624
626625
Args:
@@ -651,11 +650,7 @@ def getUpdates(self,
651650
if timeout:
652651
data['timeout'] = timeout
653652

654-
kwargs = {}
655-
if not requestTimeout is None:
656-
kwargs['timeout'] = requestTimeout
657-
658-
result = request.post(url, data, **kwargs)
653+
result = request.post(url, data)
659654

660655
if result:
661656
self.logger.info(

0 commit comments

Comments
 (0)