mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-01-18 15:20:42 +01:00
Merge branch 'master' into bitwise-filters
# Conflicts: # telegram/ext/messagehandler.py # tests/test_filters.py
This commit is contained in:
commit
be0f5bc519
123 changed files with 959 additions and 424 deletions
|
@ -11,6 +11,7 @@ The following wonderful people contributed directly or indirectly to this projec
|
||||||
- `Avanatiker <https://github.com/Avanatiker>`_
|
- `Avanatiker <https://github.com/Avanatiker>`_
|
||||||
- `Balduro <https://github.com/Balduro>`_
|
- `Balduro <https://github.com/Balduro>`_
|
||||||
- `bimmlerd <https://github.com/bimmlerd>`_
|
- `bimmlerd <https://github.com/bimmlerd>`_
|
||||||
|
- `Eli Gao <https://github.com/eligao>`_
|
||||||
- `ErgoZ Riftbit Vaper <https://github.com/ergoz>`_
|
- `ErgoZ Riftbit Vaper <https://github.com/ergoz>`_
|
||||||
- `franciscod <https://github.com/franciscod>`_
|
- `franciscod <https://github.com/franciscod>`_
|
||||||
- `Jacob Bom <https://github.com/bomjacob>`_
|
- `Jacob Bom <https://github.com/bomjacob>`_
|
||||||
|
@ -18,6 +19,7 @@ The following wonderful people contributed directly or indirectly to this projec
|
||||||
- `jh0ker <https://github.com/jh0ker>`_
|
- `jh0ker <https://github.com/jh0ker>`_
|
||||||
- `JRoot3D <https://github.com/JRoot3D>`_
|
- `JRoot3D <https://github.com/JRoot3D>`_
|
||||||
- `jlmadurga <https://github.com/jlmadurga>`_
|
- `jlmadurga <https://github.com/jlmadurga>`_
|
||||||
|
- `Li-aung Yip <https://github.com/LiaungYip>`_
|
||||||
- `macrojames <https://github.com/macrojames>`_
|
- `macrojames <https://github.com/macrojames>`_
|
||||||
- `naveenvhegde <https://github.com/naveenvhegde>`_
|
- `naveenvhegde <https://github.com/naveenvhegde>`_
|
||||||
- `njittam <https://github.com/njittam>`_
|
- `njittam <https://github.com/njittam>`_
|
||||||
|
|
17
CHANGES.rst
17
CHANGES.rst
|
@ -2,6 +2,23 @@
|
||||||
Changes
|
Changes
|
||||||
=======
|
=======
|
||||||
|
|
||||||
|
**2016-09-24**
|
||||||
|
|
||||||
|
*Released 5.1*
|
||||||
|
|
||||||
|
- Drop Python 2.6 support
|
||||||
|
- Deprecate ``telegram.Emoji``
|
||||||
|
|
||||||
|
- Use ``ujson`` if available
|
||||||
|
- Add instance methods to ``Message``, ``Chat``, ``User``, ``InlineQuery`` and ``CallbackQuery``
|
||||||
|
- RegEx filtering for ``CallbackQueryHandler`` and ``InlineQueryHandler``
|
||||||
|
- New ``MessageHandler`` filters: ``forwarded`` and ``entity``
|
||||||
|
- Add ``Message.get_entity`` to correctly handle UTF-16 codepoints and ``MessageEntity`` offsets
|
||||||
|
- Fix bug in ``ConversationHandler`` when first handler ends the conversation
|
||||||
|
- Allow multiple ``Dispatcher`` instances
|
||||||
|
- Add ``ChatMigrated`` Exception
|
||||||
|
- Properly split and handle arguments in ``CommandHandler``
|
||||||
|
|
||||||
**2016-07-15**
|
**2016-07-15**
|
||||||
|
|
||||||
*Released 5.0*
|
*Released 5.0*
|
||||||
|
|
|
@ -96,6 +96,14 @@ You can install or upgrade python-telegram-bot with:
|
||||||
|
|
||||||
$ pip install python-telegram-bot --upgrade
|
$ pip install python-telegram-bot --upgrade
|
||||||
|
|
||||||
|
Or you can install from source with:
|
||||||
|
|
||||||
|
.. code:: shell
|
||||||
|
|
||||||
|
$ git clone https://github.com/python-telegram-bot/python-telegram-bot
|
||||||
|
$ cd python-telegram-bot
|
||||||
|
$ python setup.py install
|
||||||
|
|
||||||
===============
|
===============
|
||||||
Getting started
|
Getting started
|
||||||
===============
|
===============
|
||||||
|
|
|
@ -35,11 +35,11 @@ GENDER, PHOTO, LOCATION, BIO = range(4)
|
||||||
def start(bot, update):
|
def start(bot, update):
|
||||||
reply_keyboard = [['Boy', 'Girl', 'Other']]
|
reply_keyboard = [['Boy', 'Girl', 'Other']]
|
||||||
|
|
||||||
bot.sendMessage(update.message.chat_id,
|
update.message.reply_text(
|
||||||
text='Hi! My name is Professor Bot. I will hold a conversation with you. '
|
'Hi! My name is Professor Bot. I will hold a conversation with you. '
|
||||||
'Send /cancel to stop talking to me.\n\n'
|
'Send /cancel to stop talking to me.\n\n'
|
||||||
'Are you a boy or a girl?',
|
'Are you a boy or a girl?',
|
||||||
reply_markup=ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True))
|
reply_markup=ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True))
|
||||||
|
|
||||||
return GENDER
|
return GENDER
|
||||||
|
|
||||||
|
@ -47,9 +47,8 @@ def start(bot, update):
|
||||||
def gender(bot, update):
|
def gender(bot, update):
|
||||||
user = update.message.from_user
|
user = update.message.from_user
|
||||||
logger.info("Gender of %s: %s" % (user.first_name, update.message.text))
|
logger.info("Gender of %s: %s" % (user.first_name, update.message.text))
|
||||||
bot.sendMessage(update.message.chat_id,
|
update.message.reply_text('I see! Please send me a photo of yourself, '
|
||||||
text='I see! Please send me a photo of yourself, '
|
'so I know what you look like, or send /skip if you don\'t want to.')
|
||||||
'so I know what you look like, or send /skip if you don\'t want to.')
|
|
||||||
|
|
||||||
return PHOTO
|
return PHOTO
|
||||||
|
|
||||||
|
@ -59,8 +58,8 @@ def photo(bot, update):
|
||||||
photo_file = bot.getFile(update.message.photo[-1].file_id)
|
photo_file = bot.getFile(update.message.photo[-1].file_id)
|
||||||
photo_file.download('user_photo.jpg')
|
photo_file.download('user_photo.jpg')
|
||||||
logger.info("Photo of %s: %s" % (user.first_name, 'user_photo.jpg'))
|
logger.info("Photo of %s: %s" % (user.first_name, 'user_photo.jpg'))
|
||||||
bot.sendMessage(update.message.chat_id, text='Gorgeous! Now, send me your location please, '
|
update.message.reply_text('Gorgeous! Now, send me your location please, '
|
||||||
'or send /skip if you don\'t want to.')
|
'or send /skip if you don\'t want to.')
|
||||||
|
|
||||||
return LOCATION
|
return LOCATION
|
||||||
|
|
||||||
|
@ -68,8 +67,8 @@ def photo(bot, update):
|
||||||
def skip_photo(bot, update):
|
def skip_photo(bot, update):
|
||||||
user = update.message.from_user
|
user = update.message.from_user
|
||||||
logger.info("User %s did not send a photo." % user.first_name)
|
logger.info("User %s did not send a photo." % user.first_name)
|
||||||
bot.sendMessage(update.message.chat_id, text='I bet you look great! Now, send me your '
|
update.message.reply_text('I bet you look great! Now, send me your location please, '
|
||||||
'location please, or send /skip.')
|
'or send /skip.')
|
||||||
|
|
||||||
return LOCATION
|
return LOCATION
|
||||||
|
|
||||||
|
@ -79,8 +78,8 @@ def location(bot, update):
|
||||||
user_location = update.message.location
|
user_location = update.message.location
|
||||||
logger.info("Location of %s: %f / %f"
|
logger.info("Location of %s: %f / %f"
|
||||||
% (user.first_name, user_location.latitude, user_location.longitude))
|
% (user.first_name, user_location.latitude, user_location.longitude))
|
||||||
bot.sendMessage(update.message.chat_id, text='Maybe I can visit you sometime! '
|
update.message.reply_text('Maybe I can visit you sometime! '
|
||||||
'At last, tell me something about yourself.')
|
'At last, tell me something about yourself.')
|
||||||
|
|
||||||
return BIO
|
return BIO
|
||||||
|
|
||||||
|
@ -88,8 +87,8 @@ def location(bot, update):
|
||||||
def skip_location(bot, update):
|
def skip_location(bot, update):
|
||||||
user = update.message.from_user
|
user = update.message.from_user
|
||||||
logger.info("User %s did not send a location." % user.first_name)
|
logger.info("User %s did not send a location." % user.first_name)
|
||||||
bot.sendMessage(update.message.chat_id, text='You seem a bit paranoid! '
|
update.message.reply_text('You seem a bit paranoid! '
|
||||||
'At last, tell me something about yourself.')
|
'At last, tell me something about yourself.')
|
||||||
|
|
||||||
return BIO
|
return BIO
|
||||||
|
|
||||||
|
@ -97,8 +96,7 @@ def skip_location(bot, update):
|
||||||
def bio(bot, update):
|
def bio(bot, update):
|
||||||
user = update.message.from_user
|
user = update.message.from_user
|
||||||
logger.info("Bio of %s: %s" % (user.first_name, update.message.text))
|
logger.info("Bio of %s: %s" % (user.first_name, update.message.text))
|
||||||
bot.sendMessage(update.message.chat_id,
|
update.message.reply_text('Thank you! I hope we can talk again some day.')
|
||||||
text='Thank you! I hope we can talk again some day.')
|
|
||||||
|
|
||||||
return ConversationHandler.END
|
return ConversationHandler.END
|
||||||
|
|
||||||
|
@ -106,8 +104,7 @@ def bio(bot, update):
|
||||||
def cancel(bot, update):
|
def cancel(bot, update):
|
||||||
user = update.message.from_user
|
user = update.message.from_user
|
||||||
logger.info("User %s canceled the conversation." % user.first_name)
|
logger.info("User %s canceled the conversation." % user.first_name)
|
||||||
bot.sendMessage(update.message.chat_id,
|
update.message.reply_text('Bye! I hope we can talk again some day.')
|
||||||
text='Bye! I hope we can talk again some day.')
|
|
||||||
|
|
||||||
return ConversationHandler.END
|
return ConversationHandler.END
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ def echo(bot):
|
||||||
|
|
||||||
if update.message: # your bot can receive updates without messages
|
if update.message: # your bot can receive updates without messages
|
||||||
# Reply to the message
|
# Reply to the message
|
||||||
bot.sendMessage(chat_id=chat_id, text=update.message.text)
|
update.message.reply_text(update.message.text)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -29,15 +29,15 @@ logger = logging.getLogger(__name__)
|
||||||
# Define a few command handlers. These usually take the two arguments bot and
|
# Define a few command handlers. These usually take the two arguments bot and
|
||||||
# update. Error handlers also receive the raised TelegramError object in error.
|
# update. Error handlers also receive the raised TelegramError object in error.
|
||||||
def start(bot, update):
|
def start(bot, update):
|
||||||
bot.sendMessage(update.message.chat_id, text='Hi!')
|
update.message.reply_text('Hi!')
|
||||||
|
|
||||||
|
|
||||||
def help(bot, update):
|
def help(bot, update):
|
||||||
bot.sendMessage(update.message.chat_id, text='Help!')
|
update.message.reply_text('Help!')
|
||||||
|
|
||||||
|
|
||||||
def echo(bot, update):
|
def echo(bot, update):
|
||||||
bot.sendMessage(update.message.chat_id, text=update.message.text)
|
update.message.reply_text(update.message.text)
|
||||||
|
|
||||||
|
|
||||||
def error(bot, update, error):
|
def error(bot, update, error):
|
||||||
|
|
|
@ -34,11 +34,11 @@ logger = logging.getLogger(__name__)
|
||||||
# Define a few command handlers. These usually take the two arguments bot and
|
# Define a few command handlers. These usually take the two arguments bot and
|
||||||
# update. Error handlers also receive the raised TelegramError object in error.
|
# update. Error handlers also receive the raised TelegramError object in error.
|
||||||
def start(bot, update):
|
def start(bot, update):
|
||||||
bot.sendMessage(update.message.chat_id, text='Hi!')
|
update.message.reply_text('Hi!')
|
||||||
|
|
||||||
|
|
||||||
def help(bot, update):
|
def help(bot, update):
|
||||||
bot.sendMessage(update.message.chat_id, text='Help!')
|
update.message.reply_text('Help!')
|
||||||
|
|
||||||
|
|
||||||
def escape_markdown(text):
|
def escape_markdown(text):
|
||||||
|
@ -68,7 +68,7 @@ def inlinequery(bot, update):
|
||||||
"_%s_" % escape_markdown(query),
|
"_%s_" % escape_markdown(query),
|
||||||
parse_mode=ParseMode.MARKDOWN)))
|
parse_mode=ParseMode.MARKDOWN)))
|
||||||
|
|
||||||
bot.answerInlineQuery(update.inline_query.id, results=results)
|
update.inline_query.answer(results)
|
||||||
|
|
||||||
|
|
||||||
def error(bot, update, error):
|
def error(bot, update, error):
|
||||||
|
|
|
@ -20,7 +20,7 @@ def start(bot, update):
|
||||||
|
|
||||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||||
|
|
||||||
bot.sendMessage(update.message.chat_id, text="Please choose:", reply_markup=reply_markup)
|
update.message.reply_text('Please choose:', reply_markup=reply_markup)
|
||||||
|
|
||||||
|
|
||||||
def button(bot, update):
|
def button(bot, update):
|
||||||
|
@ -32,7 +32,7 @@ def button(bot, update):
|
||||||
|
|
||||||
|
|
||||||
def help(bot, update):
|
def help(bot, update):
|
||||||
bot.sendMessage(update.message.chat_id, text="Use /start to test this bot.")
|
update.message.reply_text("Use /start to test this bot.")
|
||||||
|
|
||||||
|
|
||||||
def error(bot, update, error):
|
def error(bot, update, error):
|
||||||
|
|
|
@ -31,7 +31,7 @@ timers = dict()
|
||||||
# Define a few command handlers. These usually take the two arguments bot and
|
# Define a few command handlers. These usually take the two arguments bot and
|
||||||
# update. Error handlers also receive the raised TelegramError object in error.
|
# update. Error handlers also receive the raised TelegramError object in error.
|
||||||
def start(bot, update):
|
def start(bot, update):
|
||||||
bot.sendMessage(update.message.chat_id, text='Hi! Use /set <seconds> to ' 'set a timer')
|
update.message.reply_text('Hi! Use /set <seconds> to set a timer')
|
||||||
|
|
||||||
|
|
||||||
def alarm(bot, job):
|
def alarm(bot, job):
|
||||||
|
@ -46,7 +46,7 @@ def set(bot, update, args, job_queue):
|
||||||
# args[0] should contain the time for the timer in seconds
|
# args[0] should contain the time for the timer in seconds
|
||||||
due = int(args[0])
|
due = int(args[0])
|
||||||
if due < 0:
|
if due < 0:
|
||||||
bot.sendMessage(chat_id, text='Sorry we can not go back to future!')
|
update.message.reply_text('Sorry we can not go back to future!')
|
||||||
return
|
return
|
||||||
|
|
||||||
# Add job to queue
|
# Add job to queue
|
||||||
|
@ -54,25 +54,25 @@ def set(bot, update, args, job_queue):
|
||||||
timers[chat_id] = job
|
timers[chat_id] = job
|
||||||
job_queue.put(job)
|
job_queue.put(job)
|
||||||
|
|
||||||
bot.sendMessage(chat_id, text='Timer successfully set!')
|
update.message.reply_text('Timer successfully set!')
|
||||||
|
|
||||||
except (IndexError, ValueError):
|
except (IndexError, ValueError):
|
||||||
bot.sendMessage(chat_id, text='Usage: /set <seconds>')
|
update.message.reply_text('Usage: /set <seconds>')
|
||||||
|
|
||||||
|
|
||||||
def unset(bot, update, job_queue):
|
def unset(bot, update):
|
||||||
"""Removes the job if the user changed their mind"""
|
"""Removes the job if the user changed their mind"""
|
||||||
chat_id = update.message.chat_id
|
chat_id = update.message.chat_id
|
||||||
|
|
||||||
if chat_id not in timers:
|
if chat_id not in timers:
|
||||||
bot.sendMessage(chat_id, text='You have no active timer')
|
update.message.reply_text('You have no active timer')
|
||||||
return
|
return
|
||||||
|
|
||||||
job = timers[chat_id]
|
job = timers[chat_id]
|
||||||
job.schedule_removal()
|
job.schedule_removal()
|
||||||
del timers[chat_id]
|
del timers[chat_id]
|
||||||
|
|
||||||
bot.sendMessage(chat_id, text='Timer successfully unset!')
|
update.message.reply_text('Timer successfully unset!')
|
||||||
|
|
||||||
|
|
||||||
def error(bot, update, error):
|
def error(bot, update, error):
|
||||||
|
@ -89,7 +89,7 @@ def main():
|
||||||
dp.add_handler(CommandHandler("start", start))
|
dp.add_handler(CommandHandler("start", start))
|
||||||
dp.add_handler(CommandHandler("help", start))
|
dp.add_handler(CommandHandler("help", start))
|
||||||
dp.add_handler(CommandHandler("set", set, pass_args=True, pass_job_queue=True))
|
dp.add_handler(CommandHandler("set", set, pass_args=True, pass_job_queue=True))
|
||||||
dp.add_handler(CommandHandler("unset", unset, pass_job_queue=True))
|
dp.add_handler(CommandHandler("unset", unset))
|
||||||
|
|
||||||
# log all errors
|
# log all errors
|
||||||
dp.add_error_handler(error)
|
dp.add_error_handler(error)
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -28,7 +28,7 @@ with codecs.open('README.rst', 'r', 'utf-8') as fd:
|
||||||
author='Leandro Toledo',
|
author='Leandro Toledo',
|
||||||
author_email='devs@python-telegram-bot.org',
|
author_email='devs@python-telegram-bot.org',
|
||||||
license='LGPLv3',
|
license='LGPLv3',
|
||||||
url='https://github.com/python-telegram-bot/python-telegram-bot',
|
url='https://python-telegram-bot.org/',
|
||||||
keywords='python telegram bot api wrapper',
|
keywords='python telegram bot api wrapper',
|
||||||
description='Not just a Python wrapper around the Telegram Bot API',
|
description='Not just a Python wrapper around the Telegram Bot API',
|
||||||
long_description=fd.read(),
|
long_description=fd.read(),
|
||||||
|
|
|
@ -55,10 +55,11 @@ class Audio(TelegramObject):
|
||||||
self.file_size = int(kwargs.get('file_size', 0))
|
self.file_size = int(kwargs.get('file_size', 0))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (str):
|
data (dict):
|
||||||
|
bot (telegram.Bot):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
telegram.Audio:
|
telegram.Audio:
|
||||||
|
|
|
@ -38,13 +38,14 @@ class TelegramObject(object):
|
||||||
return self.__dict__[item]
|
return self.__dict__[item]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (str):
|
data (dict):
|
||||||
|
bot (telegram.Bot):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
telegram.TelegramObject:
|
dict:
|
||||||
"""
|
"""
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
@ -68,6 +69,9 @@ class TelegramObject(object):
|
||||||
data = dict()
|
data = dict()
|
||||||
|
|
||||||
for key in iter(self.__dict__):
|
for key in iter(self.__dict__):
|
||||||
|
if key == 'bot':
|
||||||
|
continue
|
||||||
|
|
||||||
value = self.__dict__[key]
|
value = self.__dict__[key]
|
||||||
if value is not None:
|
if value is not None:
|
||||||
if hasattr(value, 'to_dict'):
|
if hasattr(value, 'to_dict'):
|
||||||
|
|
|
@ -154,7 +154,7 @@ class Bot(TelegramObject):
|
||||||
if result is True:
|
if result is True:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
return Message.de_json(result)
|
return Message.de_json(result, self)
|
||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ class Bot(TelegramObject):
|
||||||
|
|
||||||
result = self._request.get(url)
|
result = self._request.get(url)
|
||||||
|
|
||||||
self.bot = User.de_json(result)
|
self.bot = User.de_json(result, self)
|
||||||
|
|
||||||
return self.bot
|
return self.bot
|
||||||
|
|
||||||
|
@ -860,7 +860,7 @@ class Bot(TelegramObject):
|
||||||
|
|
||||||
result = self._request.post(url, data, timeout=kwargs.get('timeout'))
|
result = self._request.post(url, data, timeout=kwargs.get('timeout'))
|
||||||
|
|
||||||
return UserProfilePhotos.de_json(result)
|
return UserProfilePhotos.de_json(result, self)
|
||||||
|
|
||||||
@log
|
@log
|
||||||
def getFile(self, file_id, **kwargs):
|
def getFile(self, file_id, **kwargs):
|
||||||
|
@ -894,7 +894,7 @@ class Bot(TelegramObject):
|
||||||
if result.get('file_path'):
|
if result.get('file_path'):
|
||||||
result['file_path'] = '%s/%s' % (self.base_file_url, result['file_path'])
|
result['file_path'] = '%s/%s' % (self.base_file_url, result['file_path'])
|
||||||
|
|
||||||
return File.de_json(result, self._request)
|
return File.de_json(result, self)
|
||||||
|
|
||||||
@log
|
@log
|
||||||
def kickChatMember(self, chat_id, user_id, **kwargs):
|
def kickChatMember(self, chat_id, user_id, **kwargs):
|
||||||
|
@ -1225,7 +1225,7 @@ class Bot(TelegramObject):
|
||||||
else:
|
else:
|
||||||
self.logger.debug('No new updates found.')
|
self.logger.debug('No new updates found.')
|
||||||
|
|
||||||
return [Update.de_json(x) for x in result]
|
return [Update.de_json(u, self) for u in result]
|
||||||
|
|
||||||
@log
|
@log
|
||||||
def setWebhook(self, webhook_url=None, certificate=None, **kwargs):
|
def setWebhook(self, webhook_url=None, certificate=None, **kwargs):
|
||||||
|
@ -1325,7 +1325,7 @@ class Bot(TelegramObject):
|
||||||
|
|
||||||
result = self._request.post(url, data, timeout=kwargs.get('timeout'))
|
result = self._request.post(url, data, timeout=kwargs.get('timeout'))
|
||||||
|
|
||||||
return Chat.de_json(result)
|
return Chat.de_json(result, self)
|
||||||
|
|
||||||
@log
|
@log
|
||||||
def getChatAdministrators(self, chat_id, **kwargs):
|
def getChatAdministrators(self, chat_id, **kwargs):
|
||||||
|
@ -1360,7 +1360,7 @@ class Bot(TelegramObject):
|
||||||
|
|
||||||
result = self._request.post(url, data, timeout=kwargs.get('timeout'))
|
result = self._request.post(url, data, timeout=kwargs.get('timeout'))
|
||||||
|
|
||||||
return [ChatMember.de_json(x) for x in result]
|
return [ChatMember.de_json(x, self) for x in result]
|
||||||
|
|
||||||
@log
|
@log
|
||||||
def getChatMembersCount(self, chat_id, **kwargs):
|
def getChatMembersCount(self, chat_id, **kwargs):
|
||||||
|
@ -1423,11 +1423,11 @@ class Bot(TelegramObject):
|
||||||
|
|
||||||
result = self._request.post(url, data, timeout=kwargs.get('timeout'))
|
result = self._request.post(url, data, timeout=kwargs.get('timeout'))
|
||||||
|
|
||||||
return ChatMember.de_json(result)
|
return ChatMember.de_json(result, self)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
data = super(Bot, Bot).de_json(data)
|
data = super(Bot, Bot).de_json(data, bot)
|
||||||
|
|
||||||
return Bot(**data)
|
return Bot(**data)
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ from telegram import TelegramObject, Message, User
|
||||||
class CallbackQuery(TelegramObject):
|
class CallbackQuery(TelegramObject):
|
||||||
"""This object represents a Telegram CallbackQuery."""
|
"""This object represents a Telegram CallbackQuery."""
|
||||||
|
|
||||||
def __init__(self, id, from_user, data, **kwargs):
|
def __init__(self, id, from_user, data, bot=None, **kwargs):
|
||||||
# Required
|
# Required
|
||||||
self.id = id
|
self.id = id
|
||||||
self.from_user = from_user
|
self.from_user = from_user
|
||||||
|
@ -34,15 +34,26 @@ class CallbackQuery(TelegramObject):
|
||||||
self.message = kwargs.get('message')
|
self.message = kwargs.get('message')
|
||||||
self.inline_message_id = kwargs.get('inline_message_id', '')
|
self.inline_message_id = kwargs.get('inline_message_id', '')
|
||||||
|
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
|
"""
|
||||||
|
Args:
|
||||||
|
data (dict):
|
||||||
|
bot (telegram.Bot):
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
telegram.CallbackQuery:
|
||||||
|
"""
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data['from_user'] = User.de_json(data.get('from'))
|
data['from_user'] = User.de_json(data.get('from'), bot)
|
||||||
data['message'] = Message.de_json(data.get('message'))
|
data['message'] = Message.de_json(data.get('message'), bot)
|
||||||
|
|
||||||
return CallbackQuery(**data)
|
return CallbackQuery(bot=bot, **data)
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
"""
|
"""
|
||||||
|
@ -54,3 +65,7 @@ class CallbackQuery(TelegramObject):
|
||||||
# Required
|
# Required
|
||||||
data['from'] = data.pop('from_user', None)
|
data['from'] = data.pop('from_user', None)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def answer(self, *args, **kwargs):
|
||||||
|
"""Shortcut for ``bot.answerCallbackQuery(update.callback_query.id, *args, **kwargs)``"""
|
||||||
|
return self.bot.answerCallbackQuery(self.id, *args, **kwargs)
|
||||||
|
|
|
@ -40,6 +40,7 @@ class Chat(TelegramObject):
|
||||||
|
|
||||||
Keyword Args:
|
Keyword Args:
|
||||||
type (Optional[str]):
|
type (Optional[str]):
|
||||||
|
bot (Optional[Bot]): The Bot to use for instance methods
|
||||||
"""
|
"""
|
||||||
|
|
||||||
PRIVATE = 'private'
|
PRIVATE = 'private'
|
||||||
|
@ -47,7 +48,7 @@ class Chat(TelegramObject):
|
||||||
SUPERGROUP = 'supergroup'
|
SUPERGROUP = 'supergroup'
|
||||||
CHANNEL = 'channel'
|
CHANNEL = 'channel'
|
||||||
|
|
||||||
def __init__(self, id, type, **kwargs):
|
def __init__(self, id, type, bot=None, **kwargs):
|
||||||
# Required
|
# Required
|
||||||
self.id = int(id)
|
self.id = int(id)
|
||||||
self.type = type
|
self.type = type
|
||||||
|
@ -57,11 +58,14 @@ class Chat(TelegramObject):
|
||||||
self.first_name = kwargs.get('first_name', '')
|
self.first_name = kwargs.get('first_name', '')
|
||||||
self.last_name = kwargs.get('last_name', '')
|
self.last_name = kwargs.get('last_name', '')
|
||||||
|
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
bot (telegram.Bot):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
telegram.Chat:
|
telegram.Chat:
|
||||||
|
@ -69,4 +73,32 @@ class Chat(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return Chat(**data)
|
return Chat(bot=bot, **data)
|
||||||
|
|
||||||
|
def send_action(self, *args, **kwargs):
|
||||||
|
"""Shortcut for ``bot.sendChatAction(update.message.chat.id, *args, **kwargs)``"""
|
||||||
|
return self.bot.sendChatAction(self.id, *args, **kwargs)
|
||||||
|
|
||||||
|
def leave(self, *args, **kwargs):
|
||||||
|
"""Shortcut for ``bot.leaveChat(update.message.chat.id, *args, **kwargs)``"""
|
||||||
|
return self.bot.leaveChat(self.id, *args, **kwargs)
|
||||||
|
|
||||||
|
def get_administrators(self, *args, **kwargs):
|
||||||
|
"""Shortcut for ``bot.getChatAdministrators(update.message.chat.id, *args, **kwargs)``"""
|
||||||
|
return self.bot.getChatAdministrators(self.id, *args, **kwargs)
|
||||||
|
|
||||||
|
def get_members_count(self, *args, **kwargs):
|
||||||
|
"""Shortcut for ``bot.getChatMembersCount(update.message.chat.id, *args, **kwargs)``"""
|
||||||
|
return self.bot.getChatMembersCount(self.id, *args, **kwargs)
|
||||||
|
|
||||||
|
def get_member(self, *args, **kwargs):
|
||||||
|
"""Shortcut for ``bot.getChatMember(update.message.chat.id, *args, **kwargs)``"""
|
||||||
|
return self.bot.getChatMember(self.id, *args, **kwargs)
|
||||||
|
|
||||||
|
def kick_member(self, *args, **kwargs):
|
||||||
|
"""Shortcut for ``bot.kickChatMember(update.message.chat.id, *args, **kwargs)``"""
|
||||||
|
return self.bot.kickChatMember(self.id, *args, **kwargs)
|
||||||
|
|
||||||
|
def unban_member(self, *args, **kwargs):
|
||||||
|
"""Shortcut for ``bot.unbanChatMember(update.message.chat.id, *args, **kwargs)``"""
|
||||||
|
return self.bot.unbanChatMember(self.id, *args, **kwargs)
|
||||||
|
|
|
@ -46,10 +46,11 @@ class ChatMember(TelegramObject):
|
||||||
self.status = status
|
self.status = status
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
bot (telegram.Bot):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
telegram.ChatMember:
|
telegram.ChatMember:
|
||||||
|
@ -57,6 +58,6 @@ class ChatMember(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data['user'] = User.de_json(data.get('user'))
|
data['user'] = User.de_json(data.get('user'), bot)
|
||||||
|
|
||||||
return ChatMember(**data)
|
return ChatMember(**data)
|
||||||
|
|
|
@ -57,10 +57,11 @@ class ChosenInlineResult(TelegramObject):
|
||||||
self.inline_message_id = inline_message_id
|
self.inline_message_id = inline_message_id
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
bot (telegram.Bot):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
telegram.ChosenInlineResult:
|
telegram.ChosenInlineResult:
|
||||||
|
@ -69,9 +70,9 @@ class ChosenInlineResult(TelegramObject):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Required
|
# Required
|
||||||
data['from_user'] = User.de_json(data.pop('from'))
|
data['from_user'] = User.de_json(data.pop('from'), bot)
|
||||||
# Optionals
|
# Optionals
|
||||||
data['location'] = Location.de_json(data.get('location'))
|
data['location'] = Location.de_json(data.get('location'), bot)
|
||||||
|
|
||||||
return ChosenInlineResult(**data)
|
return ChosenInlineResult(**data)
|
||||||
|
|
||||||
|
|
|
@ -49,10 +49,11 @@ class Contact(TelegramObject):
|
||||||
self.user_id = int(kwargs.get('user_id', 0))
|
self.user_id = int(kwargs.get('user_id', 0))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (str):
|
data (dict):
|
||||||
|
bot (telegram.Bot):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
telegram.Contact:
|
telegram.Contact:
|
||||||
|
|
|
@ -52,10 +52,11 @@ class Document(TelegramObject):
|
||||||
self.file_size = int(kwargs.get('file_size', 0))
|
self.file_size = int(kwargs.get('file_size', 0))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (str):
|
data (dict):
|
||||||
|
bot (telegram.Bot):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
telegram.Document:
|
telegram.Document:
|
||||||
|
@ -63,6 +64,6 @@ class Document(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data['thumb'] = PhotoSize.de_json(data.get('thumb'))
|
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
|
||||||
|
|
||||||
return Document(**data)
|
return Document(**data)
|
||||||
|
|
|
@ -39,7 +39,8 @@ class CommandHandler(Handler):
|
||||||
pass_args (optional[bool]): If the handler should be passed the
|
pass_args (optional[bool]): If the handler should be passed the
|
||||||
arguments passed to the command as a keyword argument called `
|
arguments passed to the command as a keyword argument called `
|
||||||
``args``. It will contain a list of strings, which is the text
|
``args``. It will contain a list of strings, which is the text
|
||||||
following the command split on spaces. Default is ``False``
|
following the command split on single or consecutive whitespace characters.
|
||||||
|
Default is ``False``
|
||||||
pass_update_queue (optional[bool]): If set to ``True``, a keyword argument called
|
pass_update_queue (optional[bool]): If set to ``True``, a keyword argument called
|
||||||
``update_queue`` will be passed to the callback function. It will be the ``Queue``
|
``update_queue`` will be passed to the callback function. It will be the ``Queue``
|
||||||
instance used by the ``Updater`` and ``Dispatcher`` that contains new updates which can
|
instance used by the ``Updater`` and ``Dispatcher`` that contains new updates which can
|
||||||
|
@ -80,7 +81,7 @@ class CommandHandler(Handler):
|
||||||
message = update.message or update.edited_message
|
message = update.message or update.edited_message
|
||||||
|
|
||||||
if self.pass_args:
|
if self.pass_args:
|
||||||
optional_args['args'] = message.text.split(' ')[1:]
|
optional_args['args'] = message.text.split()[1:]
|
||||||
|
|
||||||
return self.callback(dispatcher.bot, update, **optional_args)
|
return self.callback(dispatcher.bot, update, **optional_args)
|
||||||
|
|
||||||
|
|
|
@ -213,10 +213,13 @@ class ConversationHandler(Handler):
|
||||||
|
|
||||||
def update_state(self, new_state, key):
|
def update_state(self, new_state, key):
|
||||||
if new_state == self.END:
|
if new_state == self.END:
|
||||||
del self.conversations[key]
|
if key in self.conversations:
|
||||||
|
del self.conversations[key]
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
elif isinstance(new_state, Promise):
|
elif isinstance(new_state, Promise):
|
||||||
self.conversations[key] = (self.conversations[key], new_state)
|
self.conversations[key] = (self.conversations.get(key), new_state)
|
||||||
|
|
||||||
elif new_state is not None:
|
elif new_state is not None:
|
||||||
self.conversations[key] = new_state
|
self.conversations[key] = new_state
|
||||||
|
|
|
@ -151,3 +151,24 @@ class Filters(object):
|
||||||
return bool(message.forward_date)
|
return bool(message.forward_date)
|
||||||
|
|
||||||
forwarded = Forwarded()
|
forwarded = Forwarded()
|
||||||
|
|
||||||
|
class Entity(BaseFilter):
|
||||||
|
"""Filters messages to only allow those which have a :class:`telegram.MessageEntity`
|
||||||
|
where their `type` matches `entity_type`.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
entity_type: Entity type to check for. All types can be found as constants
|
||||||
|
in :class:`telegram.MessageEntity`.
|
||||||
|
|
||||||
|
Returns: function to use as filter
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, entity_type):
|
||||||
|
self.entity_type = entity_type
|
||||||
|
|
||||||
|
def filter(self, message):
|
||||||
|
return any([entity.type == self.entity_type for entity in message.entities])
|
||||||
|
|
||||||
|
# We don't initialize since this filter accepts arguments.
|
||||||
|
|
||||||
|
entity = Entity
|
||||||
|
|
|
@ -78,7 +78,8 @@ class MessageHandler(Handler):
|
||||||
|
|
||||||
return self.callback(dispatcher.bot, update, **optional_args)
|
return self.callback(dispatcher.bot, update, **optional_args)
|
||||||
|
|
||||||
# old non-PEP8 Handler methods
|
# old non-PEP8 Handler methods
|
||||||
|
|
||||||
m = "telegram.MessageHandler."
|
m = "telegram.MessageHandler."
|
||||||
checkUpdate = deprecate(check_update, m + "checkUpdate", m + "check_update")
|
checkUpdate = deprecate(check_update, m + "checkUpdate", m + "check_update")
|
||||||
handleUpdate = deprecate(handle_update, m + "handleUpdate", m + "handle_update")
|
handleUpdate = deprecate(handle_update, m + "handleUpdate", m + "handle_update")
|
||||||
|
|
|
@ -35,7 +35,8 @@ class StringCommandHandler(Handler):
|
||||||
pass_args (optional[bool]): If the handler should be passed the
|
pass_args (optional[bool]): If the handler should be passed the
|
||||||
arguments passed to the command as a keyword argument called `
|
arguments passed to the command as a keyword argument called `
|
||||||
``args``. It will contain a list of strings, which is the text
|
``args``. It will contain a list of strings, which is the text
|
||||||
following the command split on spaces. Default is ``False``
|
following the command split on single or consecutive whitespace characters.
|
||||||
|
Default is ``False``
|
||||||
pass_update_queue (optional[bool]): If set to ``True``, a keyword argument called
|
pass_update_queue (optional[bool]): If set to ``True``, a keyword argument called
|
||||||
``update_queue`` will be passed to the callback function. It will be the ``Queue``
|
``update_queue`` will be passed to the callback function. It will be the ``Queue``
|
||||||
instance used by the ``Updater`` and ``Dispatcher`` that contains new updates which can
|
instance used by the ``Updater`` and ``Dispatcher`` that contains new updates which can
|
||||||
|
@ -65,7 +66,7 @@ class StringCommandHandler(Handler):
|
||||||
optional_args = self.collect_optional_args(dispatcher)
|
optional_args = self.collect_optional_args(dispatcher)
|
||||||
|
|
||||||
if self.pass_args:
|
if self.pass_args:
|
||||||
optional_args['args'] = update.split(' ')[1:]
|
optional_args['args'] = update.split()[1:]
|
||||||
|
|
||||||
return self.callback(dispatcher.bot, update, **optional_args)
|
return self.callback(dispatcher.bot, update, **optional_args)
|
||||||
|
|
||||||
|
|
|
@ -274,7 +274,8 @@ class Updater(object):
|
||||||
url_path = '/{0}'.format(url_path)
|
url_path = '/{0}'.format(url_path)
|
||||||
|
|
||||||
# Create and start server
|
# Create and start server
|
||||||
self.httpd = WebhookServer((listen, port), WebhookHandler, self.update_queue, url_path)
|
self.httpd = WebhookServer((listen, port), WebhookHandler, self.update_queue, url_path,
|
||||||
|
self.bot)
|
||||||
|
|
||||||
if use_ssl:
|
if use_ssl:
|
||||||
self._check_ssl_cert(cert, key)
|
self._check_ssl_cert(cert, key)
|
||||||
|
|
|
@ -33,7 +33,7 @@ class File(TelegramObject):
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
file_id (str):
|
file_id (str):
|
||||||
request (telegram.utils.request.Request):
|
bot (telegram.Bot):
|
||||||
**kwargs: Arbitrary keyword arguments.
|
**kwargs: Arbitrary keyword arguments.
|
||||||
|
|
||||||
Keyword Args:
|
Keyword Args:
|
||||||
|
@ -42,29 +42,30 @@ class File(TelegramObject):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, file_id, request, **kwargs):
|
def __init__(self, file_id, bot, **kwargs):
|
||||||
# Required
|
# Required
|
||||||
self.file_id = str(file_id)
|
self.file_id = str(file_id)
|
||||||
self._request = request
|
|
||||||
# Optionals
|
# Optionals
|
||||||
self.file_size = int(kwargs.get('file_size', 0))
|
self.file_size = int(kwargs.get('file_size', 0))
|
||||||
self.file_path = str(kwargs.get('file_path', ''))
|
self.file_path = str(kwargs.get('file_path', ''))
|
||||||
|
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data, request):
|
def de_json(data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
request (telegram.utils.request.Request):
|
bot (telegram.Bot):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
telegram.File:
|
telegram.File:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return File(request=request, **data)
|
return File(bot=bot, **data)
|
||||||
|
|
||||||
def download(self, custom_path=None):
|
def download(self, custom_path=None):
|
||||||
"""
|
"""
|
||||||
|
@ -79,4 +80,4 @@ class File(TelegramObject):
|
||||||
else:
|
else:
|
||||||
filename = basename(url)
|
filename = basename(url)
|
||||||
|
|
||||||
self._request.download(url, filename)
|
self.bot.request.download(url, filename)
|
||||||
|
|
|
@ -43,10 +43,11 @@ class ForceReply(ReplyMarkup):
|
||||||
self.selective = bool(kwargs.get('selective', False))
|
self.selective = bool(kwargs.get('selective', False))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (str):
|
data (dict):
|
||||||
|
bot (telegram.Bot):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
telegram.ForceReply:
|
telegram.ForceReply:
|
||||||
|
|
|
@ -52,8 +52,16 @@ class InlineKeyboardButton(TelegramObject):
|
||||||
self.switch_inline_query = kwargs.get('switch_inline_query')
|
self.switch_inline_query = kwargs.get('switch_inline_query')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
data = super(InlineKeyboardButton, InlineKeyboardButton).de_json(data)
|
"""
|
||||||
|
Args:
|
||||||
|
data (dict):
|
||||||
|
bot (telegram.Bot):
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
telegram.InlineKeyboardButton:
|
||||||
|
"""
|
||||||
|
data = super(InlineKeyboardButton, InlineKeyboardButton).de_json(data, bot)
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
@ -61,12 +69,12 @@ class InlineKeyboardButton(TelegramObject):
|
||||||
return InlineKeyboardButton(**data)
|
return InlineKeyboardButton(**data)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_list(data):
|
def de_list(data, bot):
|
||||||
if not data:
|
if not data:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
inline_keyboards = list()
|
inline_keyboards = list()
|
||||||
for inline_keyboard in data:
|
for inline_keyboard in data:
|
||||||
inline_keyboards.append(InlineKeyboardButton.de_json(inline_keyboard))
|
inline_keyboards.append(InlineKeyboardButton.de_json(inline_keyboard, bot))
|
||||||
|
|
||||||
return inline_keyboards
|
return inline_keyboards
|
||||||
|
|
|
@ -38,13 +38,21 @@ class InlineKeyboardMarkup(ReplyMarkup):
|
||||||
self.inline_keyboard = inline_keyboard
|
self.inline_keyboard = inline_keyboard
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
data = super(InlineKeyboardMarkup, InlineKeyboardMarkup).de_json(data)
|
"""
|
||||||
|
Args:
|
||||||
|
data (dict):
|
||||||
|
bot (telegram.Bot):
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
telegram.InlineKeyboardMarkup:
|
||||||
|
"""
|
||||||
|
data = super(InlineKeyboardMarkup, InlineKeyboardMarkup).de_json(data, bot)
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data['inline_keyboard'] = [InlineKeyboardButton.de_list(inline_keyboard)
|
data['inline_keyboard'] = [InlineKeyboardButton.de_list(inline_keyboard, bot)
|
||||||
for inline_keyboard in data['inline_keyboard']]
|
for inline_keyboard in data['inline_keyboard']]
|
||||||
|
|
||||||
return InlineKeyboardMarkup(**data)
|
return InlineKeyboardMarkup(**data)
|
||||||
|
|
|
@ -42,9 +42,10 @@ class InlineQuery(TelegramObject):
|
||||||
|
|
||||||
Keyword Args:
|
Keyword Args:
|
||||||
location (optional[:class:`telegram.Location`]):
|
location (optional[:class:`telegram.Location`]):
|
||||||
|
bot (Optional[Bot]): The Bot to use for instance methods
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, id, from_user, query, offset, **kwargs):
|
def __init__(self, id, from_user, query, offset, bot=None, **kwargs):
|
||||||
# Required
|
# Required
|
||||||
self.id = id
|
self.id = id
|
||||||
self.from_user = from_user
|
self.from_user = from_user
|
||||||
|
@ -54,24 +55,27 @@ class InlineQuery(TelegramObject):
|
||||||
# Optional
|
# Optional
|
||||||
self.location = kwargs.get('location')
|
self.location = kwargs.get('location')
|
||||||
|
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
bot (telegram.Bot):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
telegram.InlineQuery:
|
telegram.InlineQuery:
|
||||||
"""
|
"""
|
||||||
data = super(InlineQuery, InlineQuery).de_json(data)
|
data = super(InlineQuery, InlineQuery).de_json(data, bot)
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data['from_user'] = User.de_json(data.get('from'))
|
data['from_user'] = User.de_json(data.get('from'), bot)
|
||||||
data['location'] = Location.de_json(data.get('location'))
|
data['location'] = Location.de_json(data.get('location'), bot)
|
||||||
|
|
||||||
return InlineQuery(**data)
|
return InlineQuery(bot=bot, **data)
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
"""
|
"""
|
||||||
|
@ -84,3 +88,7 @@ class InlineQuery(TelegramObject):
|
||||||
data['from'] = data.pop('from_user', None)
|
data['from'] = data.pop('from_user', None)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def answer(self, *args, **kwargs):
|
||||||
|
"""Shortcut for ``bot.answerInlineQuery(update.inline_query.id, *args, **kwargs)``"""
|
||||||
|
return self.bot.answerInlineQuery(self.id, *args, **kwargs)
|
||||||
|
|
|
@ -35,11 +35,11 @@ class InlineQueryResult(TelegramObject):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, type, id):
|
def __init__(self, type, id, **kwargs):
|
||||||
# Required
|
# Required
|
||||||
self.type = str(type)
|
self.type = str(type)
|
||||||
self.id = str(id)
|
self.id = str(id)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
return super(InlineQueryResult, InlineQueryResult).de_json(data)
|
return super(InlineQueryResult, InlineQueryResult).de_json(data, bot)
|
||||||
|
|
|
@ -94,11 +94,11 @@ class InlineQueryResultArticle(InlineQueryResult):
|
||||||
self.thumb_height = thumb_height
|
self.thumb_height = thumb_height
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
data = super(InlineQueryResultArticle, InlineQueryResultArticle).de_json(data)
|
data = super(InlineQueryResultArticle, InlineQueryResultArticle).de_json(data, bot)
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'))
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultArticle(**data)
|
return InlineQueryResultArticle(**data)
|
||||||
|
|
|
@ -84,11 +84,11 @@ class InlineQueryResultAudio(InlineQueryResult):
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
data = super(InlineQueryResultAudio, InlineQueryResultAudio).de_json(data)
|
data = super(InlineQueryResultAudio, InlineQueryResultAudio).de_json(data, bot)
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'))
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultAudio(**data)
|
return InlineQueryResultAudio(**data)
|
||||||
|
|
|
@ -65,11 +65,11 @@ class InlineQueryResultCachedAudio(InlineQueryResult):
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
data = super(InlineQueryResultCachedAudio, InlineQueryResultCachedAudio).de_json(data)
|
data = super(InlineQueryResultCachedAudio, InlineQueryResultCachedAudio).de_json(data, bot)
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'))
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultCachedAudio(**data)
|
return InlineQueryResultCachedAudio(**data)
|
||||||
|
|
|
@ -49,12 +49,12 @@ class InlineQueryResultCachedDocument(InlineQueryResult):
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
data = super(InlineQueryResultCachedDocument,
|
data = super(InlineQueryResultCachedDocument,
|
||||||
InlineQueryResultCachedDocument).de_json(data)
|
InlineQueryResultCachedDocument).de_json(data, bot)
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'))
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultCachedDocument(**data)
|
return InlineQueryResultCachedDocument(**data)
|
||||||
|
|
|
@ -47,11 +47,11 @@ class InlineQueryResultCachedGif(InlineQueryResult):
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
data = super(InlineQueryResultCachedGif, InlineQueryResultCachedGif).de_json(data)
|
data = super(InlineQueryResultCachedGif, InlineQueryResultCachedGif).de_json(data, bot)
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'))
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultCachedGif(**data)
|
return InlineQueryResultCachedGif(**data)
|
||||||
|
|
|
@ -47,12 +47,12 @@ class InlineQueryResultCachedMpeg4Gif(InlineQueryResult):
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
data = super(InlineQueryResultCachedMpeg4Gif,
|
data = super(InlineQueryResultCachedMpeg4Gif,
|
||||||
InlineQueryResultCachedMpeg4Gif).de_json(data)
|
InlineQueryResultCachedMpeg4Gif).de_json(data, bot)
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'))
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultCachedMpeg4Gif(**data)
|
return InlineQueryResultCachedMpeg4Gif(**data)
|
||||||
|
|
|
@ -50,11 +50,11 @@ class InlineQueryResultCachedPhoto(InlineQueryResult):
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
data = super(InlineQueryResultCachedPhoto, InlineQueryResultCachedPhoto).de_json(data)
|
data = super(InlineQueryResultCachedPhoto, InlineQueryResultCachedPhoto).de_json(data, bot)
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'))
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultCachedPhoto(**data)
|
return InlineQueryResultCachedPhoto(**data)
|
||||||
|
|
|
@ -41,11 +41,12 @@ class InlineQueryResultCachedSticker(InlineQueryResult):
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
data = super(InlineQueryResultCachedSticker, InlineQueryResultCachedSticker).de_json(data)
|
data = super(InlineQueryResultCachedSticker,
|
||||||
|
InlineQueryResultCachedSticker).de_json(data, bot)
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'))
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultCachedSticker(**data)
|
return InlineQueryResultCachedSticker(**data)
|
||||||
|
|
|
@ -49,11 +49,11 @@ class InlineQueryResultCachedVideo(InlineQueryResult):
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
data = super(InlineQueryResultCachedVideo, InlineQueryResultCachedVideo).de_json(data)
|
data = super(InlineQueryResultCachedVideo, InlineQueryResultCachedVideo).de_json(data, bot)
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'))
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultCachedVideo(**data)
|
return InlineQueryResultCachedVideo(**data)
|
||||||
|
|
|
@ -46,11 +46,11 @@ class InlineQueryResultCachedVoice(InlineQueryResult):
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
data = super(InlineQueryResultCachedVoice, InlineQueryResultCachedVoice).de_json(data)
|
data = super(InlineQueryResultCachedVoice, InlineQueryResultCachedVoice).de_json(data, bot)
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'))
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultCachedVoice(**data)
|
return InlineQueryResultCachedVoice(**data)
|
||||||
|
|
|
@ -55,11 +55,11 @@ class InlineQueryResultContact(InlineQueryResult):
|
||||||
self.thumb_height = thumb_height
|
self.thumb_height = thumb_height
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
data = super(InlineQueryResultContact, InlineQueryResultContact).de_json(data)
|
data = super(InlineQueryResultContact, InlineQueryResultContact).de_json(data, bot)
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'))
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultContact(**data)
|
return InlineQueryResultContact(**data)
|
||||||
|
|
|
@ -60,11 +60,11 @@ class InlineQueryResultDocument(InlineQueryResult):
|
||||||
self.thumb_height = thumb_height
|
self.thumb_height = thumb_height
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
data = super(InlineQueryResultDocument, InlineQueryResultDocument).de_json(data)
|
data = super(InlineQueryResultDocument, InlineQueryResultDocument).de_json(data, bot)
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'))
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultDocument(**data)
|
return InlineQueryResultDocument(**data)
|
||||||
|
|
|
@ -56,11 +56,11 @@ class InlineQueryResultGif(InlineQueryResult):
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
data = super(InlineQueryResultGif, InlineQueryResultGif).de_json(data)
|
data = super(InlineQueryResultGif, InlineQueryResultGif).de_json(data, bot)
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'))
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultGif(**data)
|
return InlineQueryResultGif(**data)
|
||||||
|
|
|
@ -54,11 +54,11 @@ class InlineQueryResultLocation(InlineQueryResult):
|
||||||
self.thumb_height = thumb_height
|
self.thumb_height = thumb_height
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
data = super(InlineQueryResultLocation, InlineQueryResultLocation).de_json(data)
|
data = super(InlineQueryResultLocation, InlineQueryResultLocation).de_json(data, bot)
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'))
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultLocation(**data)
|
return InlineQueryResultLocation(**data)
|
||||||
|
|
|
@ -56,11 +56,11 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
data = super(InlineQueryResultMpeg4Gif, InlineQueryResultMpeg4Gif).de_json(data)
|
data = super(InlineQueryResultMpeg4Gif, InlineQueryResultMpeg4Gif).de_json(data, bot)
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'))
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultMpeg4Gif(**data)
|
return InlineQueryResultMpeg4Gif(**data)
|
||||||
|
|
|
@ -58,11 +58,11 @@ class InlineQueryResultPhoto(InlineQueryResult):
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
data = super(InlineQueryResultPhoto, InlineQueryResultPhoto).de_json(data)
|
data = super(InlineQueryResultPhoto, InlineQueryResultPhoto).de_json(data, bot)
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'))
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultPhoto(**data)
|
return InlineQueryResultPhoto(**data)
|
||||||
|
|
|
@ -60,11 +60,11 @@ class InlineQueryResultVenue(InlineQueryResult):
|
||||||
self.thumb_height = thumb_height
|
self.thumb_height = thumb_height
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
data = super(InlineQueryResultVenue, InlineQueryResultVenue).de_json(data)
|
data = super(InlineQueryResultVenue, InlineQueryResultVenue).de_json(data, bot)
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'))
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultVenue(**data)
|
return InlineQueryResultVenue(**data)
|
||||||
|
|
|
@ -63,11 +63,11 @@ class InlineQueryResultVideo(InlineQueryResult):
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
data = super(InlineQueryResultVideo, InlineQueryResultVideo).de_json(data)
|
data = super(InlineQueryResultVideo, InlineQueryResultVideo).de_json(data, bot)
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'))
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultVideo(**data)
|
return InlineQueryResultVideo(**data)
|
||||||
|
|
|
@ -47,11 +47,11 @@ class InlineQueryResultVoice(InlineQueryResult):
|
||||||
self.input_message_content = input_message_content
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
data = super(InlineQueryResultVoice, InlineQueryResultVoice).de_json(data)
|
data = super(InlineQueryResultVoice, InlineQueryResultVoice).de_json(data, bot)
|
||||||
|
|
||||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||||
data['input_message_content'] = InputMessageContent.de_json(
|
data['input_message_content'] = InputMessageContent.de_json(
|
||||||
data.get('input_message_content'))
|
data.get('input_message_content'), bot)
|
||||||
|
|
||||||
return InlineQueryResultVoice(**data)
|
return InlineQueryResultVoice(**data)
|
||||||
|
|
|
@ -33,5 +33,5 @@ class InputContactMessageContent(InputMessageContent):
|
||||||
self.last_name = last_name
|
self.last_name = last_name
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
return InputContactMessageContent(**data)
|
return InputContactMessageContent(**data)
|
||||||
|
|
|
@ -31,5 +31,5 @@ class InputLocationMessageContent(InputMessageContent):
|
||||||
self.longitude = longitude
|
self.longitude = longitude
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
return InputLocationMessageContent(**data)
|
return InputLocationMessageContent(**data)
|
||||||
|
|
|
@ -26,33 +26,33 @@ class InputMessageContent(TelegramObject):
|
||||||
"""Base class for Telegram InputMessageContent Objects"""
|
"""Base class for Telegram InputMessageContent Objects"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
data = super(InputMessageContent, InputMessageContent).de_json(data)
|
data = super(InputMessageContent, InputMessageContent).de_json(data, bot)
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from telegram import InputTextMessageContent
|
from telegram import InputTextMessageContent
|
||||||
return InputTextMessageContent.de_json(data)
|
return InputTextMessageContent.de_json(data, bot)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from telegram import InputVenueMessageContent
|
from telegram import InputVenueMessageContent
|
||||||
return InputVenueMessageContent.de_json(data)
|
return InputVenueMessageContent.de_json(data, bot)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from telegram import InputLocationMessageContent
|
from telegram import InputLocationMessageContent
|
||||||
return InputLocationMessageContent.de_json(data)
|
return InputLocationMessageContent.de_json(data, bot)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from telegram import InputContactMessageContent
|
from telegram import InputContactMessageContent
|
||||||
return InputContactMessageContent.de_json(data)
|
return InputContactMessageContent.de_json(data, bot)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -33,5 +33,5 @@ class InputTextMessageContent(InputMessageContent):
|
||||||
self.disable_web_page_preview = disable_web_page_preview
|
self.disable_web_page_preview = disable_web_page_preview
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
return InputTextMessageContent(**data)
|
return InputTextMessageContent(**data)
|
||||||
|
|
|
@ -35,5 +35,5 @@ class InputVenueMessageContent(InputMessageContent):
|
||||||
self.foursquare_id = foursquare_id
|
self.foursquare_id = foursquare_id
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
return InputVenueMessageContent(**data)
|
return InputVenueMessageContent(**data)
|
||||||
|
|
|
@ -43,19 +43,19 @@ class KeyboardButton(TelegramObject):
|
||||||
self.request_location = request_location
|
self.request_location = request_location
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return KeyboardButton(**data)
|
return KeyboardButton(**data)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_list(data):
|
def de_list(data, bot):
|
||||||
if not data:
|
if not data:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
keyboards = list()
|
keyboards = list()
|
||||||
for keyboard in data:
|
for keyboard in data:
|
||||||
keyboards.append(KeyboardButton.de_json(keyboard))
|
keyboards.append(KeyboardButton.de_json(keyboard, bot))
|
||||||
|
|
||||||
return keyboards
|
return keyboards
|
||||||
|
|
|
@ -39,10 +39,11 @@ class Location(TelegramObject):
|
||||||
self.latitude = float(latitude)
|
self.latitude = float(latitude)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (str):
|
data (dict):
|
||||||
|
bot (telegram.Bot):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
telegram.Location:
|
telegram.Location:
|
||||||
|
|
|
@ -103,9 +103,10 @@ class Message(TelegramObject):
|
||||||
migrate_to_chat_id (Optional[int]):
|
migrate_to_chat_id (Optional[int]):
|
||||||
migrate_from_chat_id (Optional[int]):
|
migrate_from_chat_id (Optional[int]):
|
||||||
channel_chat_created (Optional[bool]):
|
channel_chat_created (Optional[bool]):
|
||||||
|
bot (Optional[Bot]): The Bot to use for instance methods
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, message_id, from_user, date, chat, **kwargs):
|
def __init__(self, message_id, from_user, date, chat, bot=None, **kwargs):
|
||||||
# Required
|
# Required
|
||||||
self.message_id = int(message_id)
|
self.message_id = int(message_id)
|
||||||
self.from_user = from_user
|
self.from_user = from_user
|
||||||
|
@ -141,16 +142,19 @@ class Message(TelegramObject):
|
||||||
self.channel_chat_created = bool(kwargs.get('channel_chat_created', False))
|
self.channel_chat_created = bool(kwargs.get('channel_chat_created', False))
|
||||||
self.pinned_message = kwargs.get('pinned_message')
|
self.pinned_message = kwargs.get('pinned_message')
|
||||||
|
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def chat_id(self):
|
def chat_id(self):
|
||||||
"""int: Short for :attr:`Message.chat.id`"""
|
"""int: Short for :attr:`Message.chat.id`"""
|
||||||
return self.chat.id
|
return self.chat.id
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
bot (telegram.Bot):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
telegram.Message:
|
telegram.Message:
|
||||||
|
@ -158,30 +162,30 @@ class Message(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data['from_user'] = User.de_json(data.get('from'))
|
data['from_user'] = User.de_json(data.get('from'), bot)
|
||||||
data['date'] = datetime.fromtimestamp(data['date'])
|
data['date'] = datetime.fromtimestamp(data['date'])
|
||||||
data['chat'] = Chat.de_json(data.get('chat'))
|
data['chat'] = Chat.de_json(data.get('chat'), bot)
|
||||||
data['entities'] = MessageEntity.de_list(data.get('entities'))
|
data['entities'] = MessageEntity.de_list(data.get('entities'), bot)
|
||||||
data['forward_from'] = User.de_json(data.get('forward_from'))
|
data['forward_from'] = User.de_json(data.get('forward_from'), bot)
|
||||||
data['forward_from_chat'] = Chat.de_json(data.get('forward_from_chat'))
|
data['forward_from_chat'] = Chat.de_json(data.get('forward_from_chat'), bot)
|
||||||
data['forward_date'] = Message._fromtimestamp(data.get('forward_date'))
|
data['forward_date'] = Message._fromtimestamp(data.get('forward_date'))
|
||||||
data['reply_to_message'] = Message.de_json(data.get('reply_to_message'))
|
data['reply_to_message'] = Message.de_json(data.get('reply_to_message'), bot)
|
||||||
data['edit_date'] = Message._fromtimestamp(data.get('edit_date'))
|
data['edit_date'] = Message._fromtimestamp(data.get('edit_date'))
|
||||||
data['audio'] = Audio.de_json(data.get('audio'))
|
data['audio'] = Audio.de_json(data.get('audio'), bot)
|
||||||
data['document'] = Document.de_json(data.get('document'))
|
data['document'] = Document.de_json(data.get('document'), bot)
|
||||||
data['photo'] = PhotoSize.de_list(data.get('photo'))
|
data['photo'] = PhotoSize.de_list(data.get('photo'), bot)
|
||||||
data['sticker'] = Sticker.de_json(data.get('sticker'))
|
data['sticker'] = Sticker.de_json(data.get('sticker'), bot)
|
||||||
data['video'] = Video.de_json(data.get('video'))
|
data['video'] = Video.de_json(data.get('video'), bot)
|
||||||
data['voice'] = Voice.de_json(data.get('voice'))
|
data['voice'] = Voice.de_json(data.get('voice'), bot)
|
||||||
data['contact'] = Contact.de_json(data.get('contact'))
|
data['contact'] = Contact.de_json(data.get('contact'), bot)
|
||||||
data['location'] = Location.de_json(data.get('location'))
|
data['location'] = Location.de_json(data.get('location'), bot)
|
||||||
data['venue'] = Venue.de_json(data.get('venue'))
|
data['venue'] = Venue.de_json(data.get('venue'), bot)
|
||||||
data['new_chat_member'] = User.de_json(data.get('new_chat_member'))
|
data['new_chat_member'] = User.de_json(data.get('new_chat_member'), bot)
|
||||||
data['left_chat_member'] = User.de_json(data.get('left_chat_member'))
|
data['left_chat_member'] = User.de_json(data.get('left_chat_member'), bot)
|
||||||
data['new_chat_photo'] = PhotoSize.de_list(data.get('new_chat_photo'))
|
data['new_chat_photo'] = PhotoSize.de_list(data.get('new_chat_photo'), bot)
|
||||||
data['pinned_message'] = Message.de_json(data.get('pinned_message'))
|
data['pinned_message'] = Message.de_json(data.get('pinned_message'), bot)
|
||||||
|
|
||||||
return Message(**data)
|
return Message(bot=bot, **data)
|
||||||
|
|
||||||
def __getitem__(self, item):
|
def __getitem__(self, item):
|
||||||
if item in self.__dict__.keys():
|
if item in self.__dict__.keys():
|
||||||
|
@ -246,6 +250,168 @@ class Message(TelegramObject):
|
||||||
# Python 3 (< 3.3) and Python 2
|
# Python 3 (< 3.3) and Python 2
|
||||||
return int(mktime(dt_obj.timetuple()))
|
return int(mktime(dt_obj.timetuple()))
|
||||||
|
|
||||||
|
def _quote(self, kwargs):
|
||||||
|
"""Modify kwargs for replying with or without quoting"""
|
||||||
|
|
||||||
|
if 'reply_to_message_id' in kwargs:
|
||||||
|
if 'quote' in kwargs:
|
||||||
|
del kwargs['quote']
|
||||||
|
|
||||||
|
elif 'quote' in kwargs:
|
||||||
|
if kwargs['quote']:
|
||||||
|
kwargs['reply_to_message_id'] = self.message_id
|
||||||
|
|
||||||
|
del kwargs['quote']
|
||||||
|
|
||||||
|
else:
|
||||||
|
if self.chat.type != Chat.PRIVATE:
|
||||||
|
kwargs['reply_to_message_id'] = self.message_id
|
||||||
|
|
||||||
|
def reply_text(self, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
Shortcut for ``bot.sendMessage(update.message.chat_id, *args, **kwargs)``
|
||||||
|
|
||||||
|
Keyword Args:
|
||||||
|
quote (Optional[bool]): If set to ``True``, the message is sent as an actual reply to
|
||||||
|
this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
|
||||||
|
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self._quote(kwargs)
|
||||||
|
return self.bot.sendMessage(self.chat_id, *args, **kwargs)
|
||||||
|
|
||||||
|
def reply_photo(self, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
Shortcut for ``bot.sendPhoto(update.message.chat_id, *args, **kwargs)``
|
||||||
|
|
||||||
|
Keyword Args:
|
||||||
|
quote (Optional[bool]): If set to ``True``, the photo is sent as an actual reply to
|
||||||
|
this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
|
||||||
|
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self._quote(kwargs)
|
||||||
|
return self.bot.sendPhoto(self.chat_id, *args, **kwargs)
|
||||||
|
|
||||||
|
def reply_audio(self, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
Shortcut for ``bot.sendAudio(update.message.chat_id, *args, **kwargs)``
|
||||||
|
|
||||||
|
Keyword Args:
|
||||||
|
quote (Optional[bool]): If set to ``True``, the audio is sent as an actual reply to
|
||||||
|
this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
|
||||||
|
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self._quote(kwargs)
|
||||||
|
return self.bot.sendAudio(self.chat_id, *args, **kwargs)
|
||||||
|
|
||||||
|
def reply_document(self, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
Shortcut for ``bot.sendDocument(update.message.chat_id, *args, **kwargs)``
|
||||||
|
|
||||||
|
Keyword Args:
|
||||||
|
quote (Optional[bool]): If set to ``True``, the document is sent as an actual reply to
|
||||||
|
this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
|
||||||
|
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self._quote(kwargs)
|
||||||
|
return self.bot.sendDocument(self.chat_id, *args, **kwargs)
|
||||||
|
|
||||||
|
def reply_sticker(self, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
Shortcut for ``bot.sendSticker(update.message.chat_id, *args, **kwargs)``
|
||||||
|
|
||||||
|
Keyword Args:
|
||||||
|
quote (Optional[bool]): If set to ``True``, the sticker is sent as an actual reply to
|
||||||
|
this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
|
||||||
|
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self._quote(kwargs)
|
||||||
|
return self.bot.sendSticker(self.chat_id, *args, **kwargs)
|
||||||
|
|
||||||
|
def reply_video(self, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
Shortcut for ``bot.sendVideo(update.message.chat_id, *args, **kwargs)``
|
||||||
|
|
||||||
|
Keyword Args:
|
||||||
|
quote (Optional[bool]): If set to ``True``, the video is sent as an actual reply to
|
||||||
|
this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
|
||||||
|
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self._quote(kwargs)
|
||||||
|
return self.bot.sendVideo(self.chat_id, *args, **kwargs)
|
||||||
|
|
||||||
|
def reply_voice(self, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
Shortcut for ``bot.sendVoice(update.message.chat_id, *args, **kwargs)``
|
||||||
|
|
||||||
|
Keyword Args:
|
||||||
|
quote (Optional[bool]): If set to ``True``, the voice is sent as an actual reply to
|
||||||
|
this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
|
||||||
|
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self._quote(kwargs)
|
||||||
|
return self.bot.sendVoice(self.chat_id, *args, **kwargs)
|
||||||
|
|
||||||
|
def reply_location(self, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
Shortcut for ``bot.sendLocation(update.message.chat_id, *args, **kwargs)``
|
||||||
|
|
||||||
|
Keyword Args:
|
||||||
|
quote (Optional[bool]): If set to ``True``, the location is sent as an actual reply to
|
||||||
|
this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
|
||||||
|
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self._quote(kwargs)
|
||||||
|
return self.bot.sendLocation(self.chat_id, *args, **kwargs)
|
||||||
|
|
||||||
|
def reply_venue(self, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
Shortcut for ``bot.sendVenue(update.message.chat_id, *args, **kwargs)``
|
||||||
|
|
||||||
|
Keyword Args:
|
||||||
|
quote (Optional[bool]): If set to ``True``, the venue is sent as an actual reply to
|
||||||
|
this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
|
||||||
|
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self._quote(kwargs)
|
||||||
|
return self.bot.sendVenue(self.chat_id, *args, **kwargs)
|
||||||
|
|
||||||
|
def reply_contact(self, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
Shortcut for ``bot.sendContact(update.message.chat_id, *args, **kwargs)``
|
||||||
|
|
||||||
|
Keyword Args:
|
||||||
|
quote (Optional[bool]): If set to ``True``, the contact is sent as an actual reply to
|
||||||
|
this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
|
||||||
|
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self._quote(kwargs)
|
||||||
|
return self.bot.sendContact(self.chat_id, *args, **kwargs)
|
||||||
|
|
||||||
|
def forward(self, chat_id, disable_notification=False):
|
||||||
|
"""Shortcut for
|
||||||
|
|
||||||
|
bot.forwardMessage(chat_id=chat_id,
|
||||||
|
from_chat_id=update.message.chat_id,
|
||||||
|
disable_notification=disable_notification,
|
||||||
|
message_id=update.message.message_id)
|
||||||
|
|
||||||
|
"""
|
||||||
|
return self.bot.forwardMessage(
|
||||||
|
chat_id=chat_id,
|
||||||
|
from_chat_id=self.chat_id,
|
||||||
|
disable_notification=disable_notification,
|
||||||
|
message_id=self.message_id)
|
||||||
|
|
||||||
def parse_entity(self, entity):
|
def parse_entity(self, entity):
|
||||||
"""
|
"""
|
||||||
Returns the text from a given :class:`telegram.MessageEntity`.
|
Returns the text from a given :class:`telegram.MessageEntity`.
|
||||||
|
|
|
@ -44,15 +44,15 @@ class MessageEntity(TelegramObject):
|
||||||
self.user = kwargs.get('user')
|
self.user = kwargs.get('user')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
data = super(MessageEntity, MessageEntity).de_json(data)
|
data = super(MessageEntity, MessageEntity).de_json(data, bot)
|
||||||
|
|
||||||
data['user'] = User.de_json(data.get('user'))
|
data['user'] = User.de_json(data.get('user'), bot)
|
||||||
|
|
||||||
return MessageEntity(**data)
|
return MessageEntity(**data)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_list(data):
|
def de_list(data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (list):
|
data (list):
|
||||||
|
@ -65,7 +65,7 @@ class MessageEntity(TelegramObject):
|
||||||
|
|
||||||
entities = list()
|
entities = list()
|
||||||
for entity in data:
|
for entity in data:
|
||||||
entities.append(MessageEntity.de_json(entity))
|
entities.append(MessageEntity.de_json(entity, bot))
|
||||||
|
|
||||||
return entities
|
return entities
|
||||||
|
|
||||||
|
|
|
@ -55,10 +55,11 @@ class PhotoSize(TelegramObject):
|
||||||
and self.height == other.height and self.file_size == other.file_size)
|
and self.height == other.height and self.file_size == other.file_size)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (str):
|
data (dict):
|
||||||
|
bot (telegram.Bot):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
telegram.PhotoSize:
|
telegram.PhotoSize:
|
||||||
|
@ -69,10 +70,11 @@ class PhotoSize(TelegramObject):
|
||||||
return PhotoSize(**data)
|
return PhotoSize(**data)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_list(data):
|
def de_list(data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (list):
|
data (list):
|
||||||
|
bot (telegram.Bot):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
List<telegram.PhotoSize>:
|
List<telegram.PhotoSize>:
|
||||||
|
@ -82,6 +84,6 @@ class PhotoSize(TelegramObject):
|
||||||
|
|
||||||
photos = list()
|
photos = list()
|
||||||
for photo in data:
|
for photo in data:
|
||||||
photos.append(PhotoSize.de_json(photo))
|
photos.append(PhotoSize.de_json(photo, bot))
|
||||||
|
|
||||||
return photos
|
return photos
|
||||||
|
|
|
@ -44,10 +44,11 @@ class ReplyKeyboardHide(ReplyMarkup):
|
||||||
self.selective = bool(kwargs.get('selective', False))
|
self.selective = bool(kwargs.get('selective', False))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (str):
|
data (dict):
|
||||||
|
bot(telegram.Bot):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
telegram.ReplyKeyboardHide:
|
telegram.ReplyKeyboardHide:
|
||||||
|
|
|
@ -50,10 +50,11 @@ class ReplyKeyboardMarkup(ReplyMarkup):
|
||||||
self.selective = bool(kwargs.get('selective', False))
|
self.selective = bool(kwargs.get('selective', False))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (str):
|
data (dict):
|
||||||
|
bot (telegram.Bot):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
telegram.ReplyKeyboardMarkup:
|
telegram.ReplyKeyboardMarkup:
|
||||||
|
@ -61,7 +62,7 @@ class ReplyKeyboardMarkup(ReplyMarkup):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data['keyboard'] = [KeyboardButton.de_list(keyboard) for keyboard in data['keyboard']]
|
data['keyboard'] = [KeyboardButton.de_list(keyboard, bot) for keyboard in data['keyboard']]
|
||||||
|
|
||||||
return ReplyKeyboardMarkup(**data)
|
return ReplyKeyboardMarkup(**data)
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,8 @@ class ReplyMarkup(TelegramObject):
|
||||||
"""Base class for Telegram ReplyMarkup Objects"""
|
"""Base class for Telegram ReplyMarkup Objects"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
data = super(ReplyMarkup, ReplyMarkup).de_json(data)
|
data = super(ReplyMarkup, ReplyMarkup).de_json(data, bot)
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -55,10 +55,11 @@ class Sticker(TelegramObject):
|
||||||
self.file_size = int(kwargs.get('file_size', 0))
|
self.file_size = int(kwargs.get('file_size', 0))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (str):
|
data (dict):
|
||||||
|
bot (telegram.Bot):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
telegram.Sticker:
|
telegram.Sticker:
|
||||||
|
@ -66,6 +67,6 @@ class Sticker(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data['thumb'] = PhotoSize.de_json(data.get('thumb'))
|
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
|
||||||
|
|
||||||
return Sticker(**data)
|
return Sticker(**data)
|
||||||
|
|
|
@ -55,10 +55,11 @@ class Update(TelegramObject):
|
||||||
self.callback_query = kwargs.get('callback_query')
|
self.callback_query = kwargs.get('callback_query')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (dict):
|
data (dict):
|
||||||
|
bot (telegram.Bot):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
telegram.Update:
|
telegram.Update:
|
||||||
|
@ -66,10 +67,11 @@ class Update(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data['message'] = Message.de_json(data.get('message'))
|
data['message'] = Message.de_json(data.get('message'), bot)
|
||||||
data['edited_message'] = Message.de_json(data.get('edited_message'))
|
data['edited_message'] = Message.de_json(data.get('edited_message'), bot)
|
||||||
data['inline_query'] = InlineQuery.de_json(data.get('inline_query'))
|
data['inline_query'] = InlineQuery.de_json(data.get('inline_query'), bot)
|
||||||
data['chosen_inline_result'] = ChosenInlineResult.de_json(data.get('chosen_inline_result'))
|
data['chosen_inline_result'] = ChosenInlineResult.de_json(
|
||||||
data['callback_query'] = CallbackQuery.de_json(data.get('callback_query'))
|
data.get('chosen_inline_result'), bot)
|
||||||
|
data['callback_query'] = CallbackQuery.de_json(data.get('callback_query'), bot)
|
||||||
|
|
||||||
return Update(**data)
|
return Update(**data)
|
||||||
|
|
|
@ -41,9 +41,10 @@ class User(TelegramObject):
|
||||||
type (Optional[str]):
|
type (Optional[str]):
|
||||||
last_name (Optional[str]):
|
last_name (Optional[str]):
|
||||||
username (Optional[str]):
|
username (Optional[str]):
|
||||||
|
bot (Optional[Bot]): The Bot to use for instance methods
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, id, first_name, **kwargs):
|
def __init__(self, id, first_name, bot=None, **kwargs):
|
||||||
# Required
|
# Required
|
||||||
self.id = int(id)
|
self.id = int(id)
|
||||||
self.first_name = first_name
|
self.first_name = first_name
|
||||||
|
@ -52,6 +53,8 @@ class User(TelegramObject):
|
||||||
self.last_name = kwargs.get('last_name', '')
|
self.last_name = kwargs.get('last_name', '')
|
||||||
self.username = kwargs.get('username', '')
|
self.username = kwargs.get('username', '')
|
||||||
|
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""str: """
|
"""str: """
|
||||||
|
@ -62,10 +65,11 @@ class User(TelegramObject):
|
||||||
return self.first_name
|
return self.first_name
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (str):
|
data (dict):
|
||||||
|
bot (telegram.Bot):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
telegram.User:
|
telegram.User:
|
||||||
|
@ -73,4 +77,10 @@ class User(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return User(**data)
|
return User(bot=bot, **data)
|
||||||
|
|
||||||
|
def get_profile_photos(self, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
Shortcut for ``bot.getUserProfilePhotos(update.message.from_user.id, *args, **kwargs)``
|
||||||
|
"""
|
||||||
|
return self.bot.getUserProfilePhotos(self.id, *args, **kwargs)
|
||||||
|
|
|
@ -40,10 +40,11 @@ class UserProfilePhotos(TelegramObject):
|
||||||
self.photos = photos
|
self.photos = photos
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (str):
|
data (dict):
|
||||||
|
bot (telegram.Bot):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
telegram.UserProfilePhotos:
|
telegram.UserProfilePhotos:
|
||||||
|
@ -51,7 +52,7 @@ class UserProfilePhotos(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data['photos'] = [PhotoSize.de_list(photo) for photo in data['photos']]
|
data['photos'] = [PhotoSize.de_list(photo, bot) for photo in data['photos']]
|
||||||
|
|
||||||
return UserProfilePhotos(**data)
|
return UserProfilePhotos(**data)
|
||||||
|
|
||||||
|
|
|
@ -24,11 +24,12 @@ class _InvalidPost(Exception):
|
||||||
|
|
||||||
class WebhookServer(BaseHTTPServer.HTTPServer, object):
|
class WebhookServer(BaseHTTPServer.HTTPServer, object):
|
||||||
|
|
||||||
def __init__(self, server_address, RequestHandlerClass, update_queue, webhook_path):
|
def __init__(self, server_address, RequestHandlerClass, update_queue, webhook_path, bot):
|
||||||
super(WebhookServer, self).__init__(server_address, RequestHandlerClass)
|
super(WebhookServer, self).__init__(server_address, RequestHandlerClass)
|
||||||
self.logger = logging.getLogger(__name__)
|
self.logger = logging.getLogger(__name__)
|
||||||
self.update_queue = update_queue
|
self.update_queue = update_queue
|
||||||
self.webhook_path = webhook_path
|
self.webhook_path = webhook_path
|
||||||
|
self.bot = bot
|
||||||
self.is_running = False
|
self.is_running = False
|
||||||
self.server_lock = Lock()
|
self.server_lock = Lock()
|
||||||
self.shutdown_lock = Lock()
|
self.shutdown_lock = Lock()
|
||||||
|
@ -85,7 +86,8 @@ class WebhookHandler(BaseHTTPServer.BaseHTTPRequestHandler, object):
|
||||||
|
|
||||||
self.logger.debug('Webhook received data: ' + json_string)
|
self.logger.debug('Webhook received data: ' + json_string)
|
||||||
|
|
||||||
update = Update.de_json(json.loads(json_string))
|
update = Update.de_json(json.loads(json_string), self.server.bot)
|
||||||
|
|
||||||
self.logger.debug('Received Update with ID %d on Webhook' % update.update_id)
|
self.logger.debug('Received Update with ID %d on Webhook' % update.update_id)
|
||||||
self.server.update_queue.put(update)
|
self.server.update_queue.put(update)
|
||||||
|
|
||||||
|
|
|
@ -41,12 +41,12 @@ class Venue(TelegramObject):
|
||||||
self.foursquare_id = foursquare_id
|
self.foursquare_id = foursquare_id
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
data = super(Venue, Venue).de_json(data)
|
data = super(Venue, Venue).de_json(data, bot)
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data['location'] = Location.de_json(data.get('location'))
|
data['location'] = Location.de_json(data.get('location'), bot)
|
||||||
|
|
||||||
return Venue(**data)
|
return Venue(**data)
|
||||||
|
|
|
@ -17,4 +17,4 @@
|
||||||
# You should have received a copy of the GNU Lesser Public License
|
# You should have received a copy of the GNU Lesser Public License
|
||||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||||
|
|
||||||
__version__ = '5.0.0'
|
__version__ = '5.1.0'
|
||||||
|
|
|
@ -58,10 +58,11 @@ class Video(TelegramObject):
|
||||||
self.file_size = int(kwargs.get('file_size', 0))
|
self.file_size = int(kwargs.get('file_size', 0))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (str):
|
data (dict):
|
||||||
|
bot (telegram.Bot):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
telegram.Video:
|
telegram.Video:
|
||||||
|
@ -69,6 +70,6 @@ class Video(TelegramObject):
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data['thumb'] = PhotoSize.de_json(data.get('thumb'))
|
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
|
||||||
|
|
||||||
return Video(**data)
|
return Video(**data)
|
||||||
|
|
|
@ -49,10 +49,11 @@ class Voice(TelegramObject):
|
||||||
self.file_size = int(kwargs.get('file_size', 0))
|
self.file_size = int(kwargs.get('file_size', 0))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data, bot):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data (str):
|
data (dict):
|
||||||
|
bot (telegram.Bot)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
telegram.Voice:
|
telegram.Voice:
|
||||||
|
|
|
@ -169,7 +169,7 @@ class AudioTest(BaseTest, unittest.TestCase):
|
||||||
self.assertEqual(audio.mime_type, self.mime_type)
|
self.assertEqual(audio.mime_type, self.mime_type)
|
||||||
|
|
||||||
def test_audio_de_json(self):
|
def test_audio_de_json(self):
|
||||||
audio = telegram.Audio.de_json(self.json_dict)
|
audio = telegram.Audio.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(audio.file_id, self.audio_file_id)
|
self.assertEqual(audio.file_id, self.audio_file_id)
|
||||||
self.assertEqual(audio.duration, self.duration)
|
self.assertEqual(audio.duration, self.duration)
|
||||||
|
@ -179,12 +179,12 @@ class AudioTest(BaseTest, unittest.TestCase):
|
||||||
self.assertEqual(audio.file_size, self.file_size)
|
self.assertEqual(audio.file_size, self.file_size)
|
||||||
|
|
||||||
def test_audio_to_json(self):
|
def test_audio_to_json(self):
|
||||||
audio = telegram.Audio.de_json(self.json_dict)
|
audio = telegram.Audio.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(audio.to_json()))
|
self.assertTrue(self.is_json(audio.to_json()))
|
||||||
|
|
||||||
def test_audio_to_dict(self):
|
def test_audio_to_dict(self):
|
||||||
audio = telegram.Audio.de_json(self.json_dict)
|
audio = telegram.Audio.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_dict(audio.to_dict()))
|
self.assertTrue(self.is_dict(audio.to_dict()))
|
||||||
self.assertEqual(audio['file_id'], self.audio_file_id)
|
self.assertEqual(audio['file_id'], self.audio_file_id)
|
||||||
|
@ -230,6 +230,15 @@ class AudioTest(BaseTest, unittest.TestCase):
|
||||||
TypeError,
|
TypeError,
|
||||||
lambda: self._bot.sendAudio(chat_id=self._chat_id, **json_dict))
|
lambda: self._bot.sendAudio(chat_id=self._chat_id, **json_dict))
|
||||||
|
|
||||||
|
@flaky(3, 1)
|
||||||
|
@timeout(10)
|
||||||
|
def test_reply_audio(self):
|
||||||
|
"""Test for Message.reply_audio"""
|
||||||
|
message = self._bot.sendMessage(self._chat_id, '.')
|
||||||
|
message = message.reply_audio(self.audio_file)
|
||||||
|
|
||||||
|
self.assertNotEqual(message.audio.file_id, '')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -20,6 +20,9 @@
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from flaky import flaky
|
||||||
|
|
||||||
sys.path.append('.')
|
sys.path.append('.')
|
||||||
|
|
||||||
import telegram
|
import telegram
|
||||||
|
@ -37,30 +40,41 @@ class ChatTest(BaseTest, unittest.TestCase):
|
||||||
self.json_dict = {'id': self.id, 'title': self.title, 'type': self.type}
|
self.json_dict = {'id': self.id, 'title': self.title, 'type': self.type}
|
||||||
|
|
||||||
def test_group_chat_de_json_empty_json(self):
|
def test_group_chat_de_json_empty_json(self):
|
||||||
group_chat = telegram.Chat.de_json({})
|
group_chat = telegram.Chat.de_json({}, self._bot)
|
||||||
|
|
||||||
self.assertEqual(group_chat, None)
|
self.assertEqual(group_chat, None)
|
||||||
|
|
||||||
def test_group_chat_de_json(self):
|
def test_group_chat_de_json(self):
|
||||||
group_chat = telegram.Chat.de_json(self.json_dict)
|
group_chat = telegram.Chat.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(group_chat.id, self.id)
|
self.assertEqual(group_chat.id, self.id)
|
||||||
self.assertEqual(group_chat.title, self.title)
|
self.assertEqual(group_chat.title, self.title)
|
||||||
self.assertEqual(group_chat.type, self.type)
|
self.assertEqual(group_chat.type, self.type)
|
||||||
|
|
||||||
def test_group_chat_to_json(self):
|
def test_group_chat_to_json(self):
|
||||||
group_chat = telegram.Chat.de_json(self.json_dict)
|
group_chat = telegram.Chat.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(group_chat.to_json()))
|
self.assertTrue(self.is_json(group_chat.to_json()))
|
||||||
|
|
||||||
def test_group_chat_to_dict(self):
|
def test_group_chat_to_dict(self):
|
||||||
group_chat = telegram.Chat.de_json(self.json_dict)
|
group_chat = telegram.Chat.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_dict(group_chat.to_dict()))
|
self.assertTrue(self.is_dict(group_chat.to_dict()))
|
||||||
self.assertEqual(group_chat['id'], self.id)
|
self.assertEqual(group_chat['id'], self.id)
|
||||||
self.assertEqual(group_chat['title'], self.title)
|
self.assertEqual(group_chat['title'], self.title)
|
||||||
self.assertEqual(group_chat['type'], self.type)
|
self.assertEqual(group_chat['type'], self.type)
|
||||||
|
|
||||||
|
@flaky(3, 1)
|
||||||
|
def test_send_action(self):
|
||||||
|
"""Test for Chat.send_action"""
|
||||||
|
self.json_dict['id'] = self._chat_id
|
||||||
|
group_chat = telegram.Chat.de_json(self.json_dict, self._bot)
|
||||||
|
group_chat.bot = self._bot
|
||||||
|
|
||||||
|
result = group_chat.send_action(telegram.ChatAction.TYPING)
|
||||||
|
|
||||||
|
self.assertTrue(result)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -45,19 +45,19 @@ class ChosenInlineResultTest(BaseTest, unittest.TestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_choseninlineresult_de_json(self):
|
def test_choseninlineresult_de_json(self):
|
||||||
result = telegram.ChosenInlineResult.de_json(self.json_dict)
|
result = telegram.ChosenInlineResult.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(result.result_id, self.result_id)
|
self.assertEqual(result.result_id, self.result_id)
|
||||||
self.assertDictEqual(result.from_user.to_dict(), self.from_user.to_dict())
|
self.assertDictEqual(result.from_user.to_dict(), self.from_user.to_dict())
|
||||||
self.assertEqual(result.query, self.query)
|
self.assertEqual(result.query, self.query)
|
||||||
|
|
||||||
def test_choseninlineresult_to_json(self):
|
def test_choseninlineresult_to_json(self):
|
||||||
result = telegram.ChosenInlineResult.de_json(self.json_dict)
|
result = telegram.ChosenInlineResult.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(result.to_json()))
|
self.assertTrue(self.is_json(result.to_json()))
|
||||||
|
|
||||||
def test_choseninlineresult_to_dict(self):
|
def test_choseninlineresult_to_dict(self):
|
||||||
result = telegram.ChosenInlineResult.de_json(self.json_dict).to_dict()
|
result = telegram.ChosenInlineResult.de_json(self.json_dict, self._bot).to_dict()
|
||||||
|
|
||||||
self.assertTrue(self.is_dict(result))
|
self.assertTrue(self.is_dict(result))
|
||||||
self.assertEqual(result['result_id'], self.result_id)
|
self.assertEqual(result['result_id'], self.result_id)
|
||||||
|
|
|
@ -20,6 +20,9 @@
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from flaky import flaky
|
||||||
|
|
||||||
sys.path.append('.')
|
sys.path.append('.')
|
||||||
|
|
||||||
import telegram
|
import telegram
|
||||||
|
@ -43,7 +46,7 @@ class ContactTest(BaseTest, unittest.TestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_contact_de_json(self):
|
def test_contact_de_json(self):
|
||||||
contact = telegram.Contact.de_json(self.json_dict)
|
contact = telegram.Contact.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(contact.phone_number, self.phone_number)
|
self.assertEqual(contact.phone_number, self.phone_number)
|
||||||
self.assertEqual(contact.first_name, self.first_name)
|
self.assertEqual(contact.first_name, self.first_name)
|
||||||
|
@ -51,12 +54,12 @@ class ContactTest(BaseTest, unittest.TestCase):
|
||||||
self.assertEqual(contact.user_id, self.user_id)
|
self.assertEqual(contact.user_id, self.user_id)
|
||||||
|
|
||||||
def test_contact_to_json(self):
|
def test_contact_to_json(self):
|
||||||
contact = telegram.Contact.de_json(self.json_dict)
|
contact = telegram.Contact.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(contact.to_json()))
|
self.assertTrue(self.is_json(contact.to_json()))
|
||||||
|
|
||||||
def test_contact_to_dict(self):
|
def test_contact_to_dict(self):
|
||||||
contact = telegram.Contact.de_json(self.json_dict)
|
contact = telegram.Contact.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_dict(contact.to_dict()))
|
self.assertTrue(self.is_dict(contact.to_dict()))
|
||||||
self.assertEqual(contact['phone_number'], self.phone_number)
|
self.assertEqual(contact['phone_number'], self.phone_number)
|
||||||
|
@ -65,5 +68,16 @@ class ContactTest(BaseTest, unittest.TestCase):
|
||||||
self.assertEqual(contact['user_id'], self.user_id)
|
self.assertEqual(contact['user_id'], self.user_id)
|
||||||
|
|
||||||
|
|
||||||
|
''' Commented out, because it would cause "Too Many Requests (429)" errors.
|
||||||
|
@flaky(3, 1)
|
||||||
|
def test_reply_contact(self):
|
||||||
|
"""Test for Message.reply_contact"""
|
||||||
|
message = self._bot.sendMessage(self._chat_id, '.')
|
||||||
|
message = message.reply_contact(self.phone_number, self.first_name)
|
||||||
|
|
||||||
|
self.assertEqual(message.contact.phone_number, self.phone_number)
|
||||||
|
self.assertEqual(message.contact.first_name, self.first_name)
|
||||||
|
'''
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -36,7 +36,7 @@ except ImportError:
|
||||||
sys.path.append('.')
|
sys.path.append('.')
|
||||||
|
|
||||||
from telegram import Update, Message, TelegramError, User, Chat, Bot
|
from telegram import Update, Message, TelegramError, User, Chat, Bot
|
||||||
from telegram.ext import *
|
from telegram.ext import Updater, ConversationHandler, CommandHandler
|
||||||
from tests.base import BaseTest
|
from tests.base import BaseTest
|
||||||
from tests.test_updater import MockBot
|
from tests.test_updater import MockBot
|
||||||
|
|
||||||
|
@ -109,6 +109,9 @@ class ConversationHandlerTest(BaseTest, unittest.TestCase):
|
||||||
def start(self, bot, update):
|
def start(self, bot, update):
|
||||||
return self._set_state(update, self.THIRSTY)
|
return self._set_state(update, self.THIRSTY)
|
||||||
|
|
||||||
|
def start_end(self, bot, update):
|
||||||
|
return self._set_state(update, self.END)
|
||||||
|
|
||||||
def brew(self, bot, update):
|
def brew(self, bot, update):
|
||||||
return self._set_state(update, self.BREWING)
|
return self._set_state(update, self.BREWING)
|
||||||
|
|
||||||
|
@ -161,6 +164,48 @@ class ConversationHandlerTest(BaseTest, unittest.TestCase):
|
||||||
sleep(.1)
|
sleep(.1)
|
||||||
self.assertRaises(KeyError, self._get_state, user_id=second_user.id)
|
self.assertRaises(KeyError, self._get_state, user_id=second_user.id)
|
||||||
|
|
||||||
|
def test_endOnFirstMessage(self):
|
||||||
|
self._setup_updater('', messages=0)
|
||||||
|
d = self.updater.dispatcher
|
||||||
|
user = User(first_name="Misses Test", id=123)
|
||||||
|
|
||||||
|
handler = ConversationHandler(
|
||||||
|
entry_points=[CommandHandler('start', self.start_end)], states={}, fallbacks=[])
|
||||||
|
d.add_handler(handler)
|
||||||
|
queue = self.updater.start_polling(0.01)
|
||||||
|
|
||||||
|
# User starts the state machine and immediately ends it.
|
||||||
|
message = Message(0, user, None, None, text="/start")
|
||||||
|
queue.put(Update(update_id=0, message=message))
|
||||||
|
sleep(.1)
|
||||||
|
self.assertEquals(len(handler.conversations), 0)
|
||||||
|
|
||||||
|
def test_endOnFirstMessageAsync(self):
|
||||||
|
self._setup_updater('', messages=0)
|
||||||
|
d = self.updater.dispatcher
|
||||||
|
user = User(first_name="Misses Test", id=123)
|
||||||
|
|
||||||
|
start_end_async = (lambda bot, update: d.run_async(self.start_end, bot, update))
|
||||||
|
|
||||||
|
handler = ConversationHandler(
|
||||||
|
entry_points=[CommandHandler('start', start_end_async)], states={}, fallbacks=[])
|
||||||
|
d.add_handler(handler)
|
||||||
|
queue = self.updater.start_polling(0.01)
|
||||||
|
|
||||||
|
# User starts the state machine with an async function that immediately ends the
|
||||||
|
# conversation. Async results are resolved when the users state is queried next time.
|
||||||
|
message = Message(0, user, None, None, text="/start")
|
||||||
|
queue.put(Update(update_id=0, message=message))
|
||||||
|
sleep(.1)
|
||||||
|
# Assert that the Promise has been accepted as the new state
|
||||||
|
self.assertEquals(len(handler.conversations), 1)
|
||||||
|
|
||||||
|
message = Message(0, user, None, None, text="resolve promise pls")
|
||||||
|
queue.put(Update(update_id=0, message=message))
|
||||||
|
sleep(.1)
|
||||||
|
# Assert that the Promise has been resolved and the conversation ended.
|
||||||
|
self.assertEquals(len(handler.conversations), 0)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -109,7 +109,7 @@ class DocumentTest(BaseTest, unittest.TestCase):
|
||||||
self.assertEqual(document.mime_type, self.mime_type)
|
self.assertEqual(document.mime_type, self.mime_type)
|
||||||
|
|
||||||
def test_document_de_json(self):
|
def test_document_de_json(self):
|
||||||
document = telegram.Document.de_json(self.json_dict)
|
document = telegram.Document.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(document.file_id, self.document_file_id)
|
self.assertEqual(document.file_id, self.document_file_id)
|
||||||
self.assertTrue(isinstance(document.thumb, telegram.PhotoSize))
|
self.assertTrue(isinstance(document.thumb, telegram.PhotoSize))
|
||||||
|
@ -118,12 +118,12 @@ class DocumentTest(BaseTest, unittest.TestCase):
|
||||||
self.assertEqual(document.file_size, self.file_size)
|
self.assertEqual(document.file_size, self.file_size)
|
||||||
|
|
||||||
def test_document_to_json(self):
|
def test_document_to_json(self):
|
||||||
document = telegram.Document.de_json(self.json_dict)
|
document = telegram.Document.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(document.to_json()))
|
self.assertTrue(self.is_json(document.to_json()))
|
||||||
|
|
||||||
def test_document_to_dict(self):
|
def test_document_to_dict(self):
|
||||||
document = telegram.Document.de_json(self.json_dict)
|
document = telegram.Document.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_dict(document.to_dict()))
|
self.assertTrue(self.is_dict(document.to_dict()))
|
||||||
self.assertEqual(document['file_id'], self.document_file_id)
|
self.assertEqual(document['file_id'], self.document_file_id)
|
||||||
|
@ -167,6 +167,15 @@ class DocumentTest(BaseTest, unittest.TestCase):
|
||||||
lambda: self._bot.sendDocument(chat_id=self._chat_id,
|
lambda: self._bot.sendDocument(chat_id=self._chat_id,
|
||||||
**json_dict))
|
**json_dict))
|
||||||
|
|
||||||
|
@flaky(3, 1)
|
||||||
|
@timeout(10)
|
||||||
|
def test_reply_document(self):
|
||||||
|
"""Test for Message.reply_document"""
|
||||||
|
message = self._bot.sendMessage(self._chat_id, '.')
|
||||||
|
message = message.reply_document(self.document_file)
|
||||||
|
|
||||||
|
self.assertNotEqual(message.document.file_id, '')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -101,19 +101,19 @@ class FileTest(BaseTest, unittest.TestCase):
|
||||||
self.assertTrue(os.path.isfile('telegram.ogg'))
|
self.assertTrue(os.path.isfile('telegram.ogg'))
|
||||||
|
|
||||||
def test_file_de_json(self):
|
def test_file_de_json(self):
|
||||||
newFile = telegram.File.de_json(self.json_dict, None)
|
newFile = telegram.File.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(newFile.file_id, self.json_dict['file_id'])
|
self.assertEqual(newFile.file_id, self.json_dict['file_id'])
|
||||||
self.assertEqual(newFile.file_path, self.json_dict['file_path'])
|
self.assertEqual(newFile.file_path, self.json_dict['file_path'])
|
||||||
self.assertEqual(newFile.file_size, self.json_dict['file_size'])
|
self.assertEqual(newFile.file_size, self.json_dict['file_size'])
|
||||||
|
|
||||||
def test_file_to_json(self):
|
def test_file_to_json(self):
|
||||||
newFile = telegram.File.de_json(self.json_dict, None)
|
newFile = telegram.File.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(newFile.to_json()))
|
self.assertTrue(self.is_json(newFile.to_json()))
|
||||||
|
|
||||||
def test_file_to_dict(self):
|
def test_file_to_dict(self):
|
||||||
newFile = telegram.File.de_json(self.json_dict, None)
|
newFile = telegram.File.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_dict(newFile.to_dict()))
|
self.assertTrue(self.is_dict(newFile.to_dict()))
|
||||||
self.assertEqual(newFile['file_id'], self.json_dict['file_id'])
|
self.assertEqual(newFile['file_id'], self.json_dict['file_id'])
|
||||||
|
|
|
@ -24,6 +24,10 @@ import sys
|
||||||
import unittest
|
import unittest
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
import functools
|
||||||
|
|
||||||
|
from telegram import MessageEntity
|
||||||
|
|
||||||
sys.path.append('.')
|
sys.path.append('.')
|
||||||
|
|
||||||
from telegram import Message, User, Chat
|
from telegram import Message, User, Chat
|
||||||
|
@ -150,6 +154,21 @@ class FiltersTest(BaseTest, unittest.TestCase):
|
||||||
self.assertTrue(Filters.status_update(self.message))
|
self.assertTrue(Filters.status_update(self.message))
|
||||||
self.message.pinned_message = None
|
self.message.pinned_message = None
|
||||||
|
|
||||||
|
def test_entities_filter(self):
|
||||||
|
e = functools.partial(MessageEntity, offset=0, length=0)
|
||||||
|
|
||||||
|
self.message.entities = [e(MessageEntity.MENTION)]
|
||||||
|
self.assertTrue(Filters.entity(MessageEntity.MENTION)(self.message))
|
||||||
|
|
||||||
|
self.message.entities = []
|
||||||
|
self.assertFalse(Filters.entity(MessageEntity.MENTION)(self.message))
|
||||||
|
|
||||||
|
self.message.entities = [e(MessageEntity.BOLD)]
|
||||||
|
self.assertFalse(Filters.entity(MessageEntity.MENTION)(self.message))
|
||||||
|
|
||||||
|
self.message.entities = [e(MessageEntity.BOLD), e(MessageEntity.MENTION)]
|
||||||
|
self.assertTrue(Filters.entity(MessageEntity.MENTION)(self.message))
|
||||||
|
|
||||||
def test_and_filters(self):
|
def test_and_filters(self):
|
||||||
# For now just test with forwarded as that's the only one that makes sense
|
# For now just test with forwarded as that's the only one that makes sense
|
||||||
# That'll change when we get a entities filter
|
# That'll change when we get a entities filter
|
||||||
|
|
|
@ -42,29 +42,29 @@ class ForceReplyTest(BaseTest, unittest.TestCase):
|
||||||
message = self._bot.sendMessage(
|
message = self._bot.sendMessage(
|
||||||
self._chat_id,
|
self._chat_id,
|
||||||
'Моё судно на воздушной подушке полно угрей',
|
'Моё судно на воздушной подушке полно угрей',
|
||||||
reply_markup=telegram.ForceReply.de_json(self.json_dict))
|
reply_markup=telegram.ForceReply.de_json(self.json_dict, self._bot))
|
||||||
|
|
||||||
self.assertTrue(self.is_json(message.to_json()))
|
self.assertTrue(self.is_json(message.to_json()))
|
||||||
self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей')
|
self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей')
|
||||||
|
|
||||||
def test_force_reply_de_json(self):
|
def test_force_reply_de_json(self):
|
||||||
force_reply = telegram.ForceReply.de_json(self.json_dict)
|
force_reply = telegram.ForceReply.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(force_reply.force_reply, self.force_reply)
|
self.assertEqual(force_reply.force_reply, self.force_reply)
|
||||||
self.assertEqual(force_reply.selective, self.selective)
|
self.assertEqual(force_reply.selective, self.selective)
|
||||||
|
|
||||||
def test_force_reply_de_json_empty(self):
|
def test_force_reply_de_json_empty(self):
|
||||||
force_reply = telegram.ForceReply.de_json(None)
|
force_reply = telegram.ForceReply.de_json(None, self._bot)
|
||||||
|
|
||||||
self.assertFalse(force_reply)
|
self.assertFalse(force_reply)
|
||||||
|
|
||||||
def test_force_reply_to_json(self):
|
def test_force_reply_to_json(self):
|
||||||
force_reply = telegram.ForceReply.de_json(self.json_dict)
|
force_reply = telegram.ForceReply.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(force_reply.to_json()))
|
self.assertTrue(self.is_json(force_reply.to_json()))
|
||||||
|
|
||||||
def test_force_reply_to_dict(self):
|
def test_force_reply_to_dict(self):
|
||||||
force_reply = telegram.ForceReply.de_json(self.json_dict)
|
force_reply = telegram.ForceReply.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(force_reply['force_reply'], self.force_reply)
|
self.assertEqual(force_reply['force_reply'], self.force_reply)
|
||||||
self.assertEqual(force_reply['selective'], self.selective)
|
self.assertEqual(force_reply['selective'], self.selective)
|
||||||
|
|
|
@ -45,7 +45,7 @@ class InlineKeyboardButtonTest(BaseTest, unittest.TestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_inline_keyboard_button_de_json(self):
|
def test_inline_keyboard_button_de_json(self):
|
||||||
inline_keyboard_button = telegram.InlineKeyboardButton.de_json(self.json_dict)
|
inline_keyboard_button = telegram.InlineKeyboardButton.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(inline_keyboard_button.text, self.text)
|
self.assertEqual(inline_keyboard_button.text, self.text)
|
||||||
self.assertEqual(inline_keyboard_button.url, self.url)
|
self.assertEqual(inline_keyboard_button.url, self.url)
|
||||||
|
@ -53,22 +53,23 @@ class InlineKeyboardButtonTest(BaseTest, unittest.TestCase):
|
||||||
self.assertEqual(inline_keyboard_button.switch_inline_query, self.switch_inline_query)
|
self.assertEqual(inline_keyboard_button.switch_inline_query, self.switch_inline_query)
|
||||||
|
|
||||||
def test_inline_keyboard_button_de_json_empty(self):
|
def test_inline_keyboard_button_de_json_empty(self):
|
||||||
inline_keyboard_button = telegram.InlineKeyboardButton.de_json(None)
|
inline_keyboard_button = telegram.InlineKeyboardButton.de_json(None, self._bot)
|
||||||
|
|
||||||
self.assertFalse(inline_keyboard_button)
|
self.assertFalse(inline_keyboard_button)
|
||||||
|
|
||||||
def test_inline_keyboard_button_de_list_empty(self):
|
def test_inline_keyboard_button_de_list_empty(self):
|
||||||
inline_keyboard_button = telegram.InlineKeyboardButton.de_list(None)
|
inline_keyboard_button = telegram.InlineKeyboardButton.de_list(None, self._bot)
|
||||||
|
|
||||||
self.assertFalse(inline_keyboard_button)
|
self.assertFalse(inline_keyboard_button)
|
||||||
|
|
||||||
def test_inline_keyboard_button_to_json(self):
|
def test_inline_keyboard_button_to_json(self):
|
||||||
inline_keyboard_button = telegram.InlineKeyboardButton.de_json(self.json_dict)
|
inline_keyboard_button = telegram.InlineKeyboardButton.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(inline_keyboard_button.to_json()))
|
self.assertTrue(self.is_json(inline_keyboard_button.to_json()))
|
||||||
|
|
||||||
def test_inline_keyboard_button_to_dict(self):
|
def test_inline_keyboard_button_to_dict(self):
|
||||||
inline_keyboard_button = telegram.InlineKeyboardButton.de_json(self.json_dict).to_dict()
|
inline_keyboard_button = telegram.InlineKeyboardButton.de_json(self.json_dict,
|
||||||
|
self._bot).to_dict()
|
||||||
|
|
||||||
self.assertTrue(self.is_dict(inline_keyboard_button))
|
self.assertTrue(self.is_dict(inline_keyboard_button))
|
||||||
self.assertDictEqual(self.json_dict, inline_keyboard_button)
|
self.assertDictEqual(self.json_dict, inline_keyboard_button)
|
||||||
|
|
|
@ -51,12 +51,12 @@ class InlineKeyboardMarkupTest(BaseTest, unittest.TestCase):
|
||||||
self.assertEqual(message.text, 'Testing InlineKeyboardMarkup')
|
self.assertEqual(message.text, 'Testing InlineKeyboardMarkup')
|
||||||
|
|
||||||
def test_inline_keyboard_markup_de_json_empty(self):
|
def test_inline_keyboard_markup_de_json_empty(self):
|
||||||
inline_keyboard_markup = telegram.InlineKeyboardMarkup.de_json(None)
|
inline_keyboard_markup = telegram.InlineKeyboardMarkup.de_json(None, self._bot)
|
||||||
|
|
||||||
self.assertFalse(inline_keyboard_markup)
|
self.assertFalse(inline_keyboard_markup)
|
||||||
|
|
||||||
def test_inline_keyboard_markup_de_json(self):
|
def test_inline_keyboard_markup_de_json(self):
|
||||||
inline_keyboard_markup = telegram.InlineKeyboardMarkup.de_json(self.json_dict)
|
inline_keyboard_markup = telegram.InlineKeyboardMarkup.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(isinstance(inline_keyboard_markup.inline_keyboard, list))
|
self.assertTrue(isinstance(inline_keyboard_markup.inline_keyboard, list))
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
|
@ -64,12 +64,12 @@ class InlineKeyboardMarkupTest(BaseTest, unittest.TestCase):
|
||||||
telegram.InlineKeyboardButton))
|
telegram.InlineKeyboardButton))
|
||||||
|
|
||||||
def test_inline_keyboard_markup_to_json(self):
|
def test_inline_keyboard_markup_to_json(self):
|
||||||
inline_keyboard_markup = telegram.InlineKeyboardMarkup.de_json(self.json_dict)
|
inline_keyboard_markup = telegram.InlineKeyboardMarkup.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(inline_keyboard_markup.to_json()))
|
self.assertTrue(self.is_json(inline_keyboard_markup.to_json()))
|
||||||
|
|
||||||
def test_inline_keyboard_markup_to_dict(self):
|
def test_inline_keyboard_markup_to_dict(self):
|
||||||
inline_keyboard_markup = telegram.InlineKeyboardMarkup.de_json(self.json_dict)
|
inline_keyboard_markup = telegram.InlineKeyboardMarkup.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(isinstance(inline_keyboard_markup.inline_keyboard, list))
|
self.assertTrue(isinstance(inline_keyboard_markup.inline_keyboard, list))
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
|
|
|
@ -50,7 +50,7 @@ class InlineQueryTest(BaseTest, unittest.TestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_inlinequery_de_json(self):
|
def test_inlinequery_de_json(self):
|
||||||
inlinequery = telegram.InlineQuery.de_json(self.json_dict)
|
inlinequery = telegram.InlineQuery.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(inlinequery.id, self.id)
|
self.assertEqual(inlinequery.id, self.id)
|
||||||
self.assertDictEqual(inlinequery.from_user.to_dict(), self.from_user.to_dict())
|
self.assertDictEqual(inlinequery.from_user.to_dict(), self.from_user.to_dict())
|
||||||
|
@ -59,12 +59,12 @@ class InlineQueryTest(BaseTest, unittest.TestCase):
|
||||||
self.assertEqual(inlinequery.offset, self.offset)
|
self.assertEqual(inlinequery.offset, self.offset)
|
||||||
|
|
||||||
def test_inlinequery_to_json(self):
|
def test_inlinequery_to_json(self):
|
||||||
inlinequery = telegram.InlineQuery.de_json(self.json_dict)
|
inlinequery = telegram.InlineQuery.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(inlinequery.to_json()))
|
self.assertTrue(self.is_json(inlinequery.to_json()))
|
||||||
|
|
||||||
def test_inlinequery_to_dict(self):
|
def test_inlinequery_to_dict(self):
|
||||||
inlinequery = telegram.InlineQuery.de_json(self.json_dict).to_dict()
|
inlinequery = telegram.InlineQuery.de_json(self.json_dict, self._bot).to_dict()
|
||||||
|
|
||||||
self.assertTrue(self.is_dict(inlinequery))
|
self.assertTrue(self.is_dict(inlinequery))
|
||||||
self.assertDictEqual(inlinequery, self.json_dict)
|
self.assertDictEqual(inlinequery, self.json_dict)
|
||||||
|
|
|
@ -61,7 +61,7 @@ class InlineQueryResultArticleTest(BaseTest, unittest.TestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_article_de_json(self):
|
def test_article_de_json(self):
|
||||||
article = telegram.InlineQueryResultArticle.de_json(self.json_dict)
|
article = telegram.InlineQueryResultArticle.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(article.type, self.type)
|
self.assertEqual(article.type, self.type)
|
||||||
self.assertEqual(article.id, self.id)
|
self.assertEqual(article.id, self.id)
|
||||||
|
@ -77,12 +77,12 @@ class InlineQueryResultArticleTest(BaseTest, unittest.TestCase):
|
||||||
self.assertEqual(article.thumb_width, self.thumb_width)
|
self.assertEqual(article.thumb_width, self.thumb_width)
|
||||||
|
|
||||||
def test_article_to_json(self):
|
def test_article_to_json(self):
|
||||||
article = telegram.InlineQueryResultArticle.de_json(self.json_dict)
|
article = telegram.InlineQueryResultArticle.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(article.to_json()))
|
self.assertTrue(self.is_json(article.to_json()))
|
||||||
|
|
||||||
def test_article_to_dict(self):
|
def test_article_to_dict(self):
|
||||||
article = telegram.InlineQueryResultArticle.de_json(self.json_dict).to_dict()
|
article = telegram.InlineQueryResultArticle.de_json(self.json_dict, self._bot).to_dict()
|
||||||
|
|
||||||
self.assertTrue(self.is_dict(article))
|
self.assertTrue(self.is_dict(article))
|
||||||
self.assertDictEqual(self.json_dict, article)
|
self.assertDictEqual(self.json_dict, article)
|
||||||
|
|
|
@ -55,7 +55,7 @@ class InlineQueryResultAudioTest(BaseTest, unittest.TestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_audio_de_json(self):
|
def test_audio_de_json(self):
|
||||||
audio = telegram.InlineQueryResultAudio.de_json(self.json_dict)
|
audio = telegram.InlineQueryResultAudio.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(audio.type, self.type)
|
self.assertEqual(audio.type, self.type)
|
||||||
self.assertEqual(audio.id, self.id)
|
self.assertEqual(audio.id, self.id)
|
||||||
|
@ -68,12 +68,12 @@ class InlineQueryResultAudioTest(BaseTest, unittest.TestCase):
|
||||||
self.assertDictEqual(audio.reply_markup.to_dict(), self.reply_markup.to_dict())
|
self.assertDictEqual(audio.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||||
|
|
||||||
def test_audio_to_json(self):
|
def test_audio_to_json(self):
|
||||||
audio = telegram.InlineQueryResultAudio.de_json(self.json_dict)
|
audio = telegram.InlineQueryResultAudio.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(audio.to_json()))
|
self.assertTrue(self.is_json(audio.to_json()))
|
||||||
|
|
||||||
def test_audio_to_dict(self):
|
def test_audio_to_dict(self):
|
||||||
audio = telegram.InlineQueryResultAudio.de_json(self.json_dict).to_dict()
|
audio = telegram.InlineQueryResultAudio.de_json(self.json_dict, self._bot).to_dict()
|
||||||
|
|
||||||
self.assertTrue(self.is_dict(audio))
|
self.assertTrue(self.is_dict(audio))
|
||||||
self.assertDictEqual(self.json_dict, audio)
|
self.assertDictEqual(self.json_dict, audio)
|
||||||
|
|
|
@ -50,7 +50,7 @@ class InlineQueryResultCachedAudioTest(BaseTest, unittest.TestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_audio_de_json(self):
|
def test_audio_de_json(self):
|
||||||
audio = telegram.InlineQueryResultCachedAudio.de_json(self.json_dict)
|
audio = telegram.InlineQueryResultCachedAudio.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(audio.type, self.type)
|
self.assertEqual(audio.type, self.type)
|
||||||
self.assertEqual(audio.id, self.id)
|
self.assertEqual(audio.id, self.id)
|
||||||
|
@ -60,12 +60,12 @@ class InlineQueryResultCachedAudioTest(BaseTest, unittest.TestCase):
|
||||||
self.assertDictEqual(audio.reply_markup.to_dict(), self.reply_markup.to_dict())
|
self.assertDictEqual(audio.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||||
|
|
||||||
def test_audio_to_json(self):
|
def test_audio_to_json(self):
|
||||||
audio = telegram.InlineQueryResultCachedAudio.de_json(self.json_dict)
|
audio = telegram.InlineQueryResultCachedAudio.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(audio.to_json()))
|
self.assertTrue(self.is_json(audio.to_json()))
|
||||||
|
|
||||||
def test_audio_to_dict(self):
|
def test_audio_to_dict(self):
|
||||||
audio = telegram.InlineQueryResultCachedAudio.de_json(self.json_dict).to_dict()
|
audio = telegram.InlineQueryResultCachedAudio.de_json(self.json_dict, self._bot).to_dict()
|
||||||
|
|
||||||
self.assertTrue(self.is_dict(audio))
|
self.assertTrue(self.is_dict(audio))
|
||||||
self.assertDictEqual(self.json_dict, audio)
|
self.assertDictEqual(self.json_dict, audio)
|
||||||
|
|
|
@ -55,7 +55,7 @@ class InlineQueryResultCachedDocumentTest(BaseTest, unittest.TestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_document_de_json(self):
|
def test_document_de_json(self):
|
||||||
document = telegram.InlineQueryResultCachedDocument.de_json(self.json_dict)
|
document = telegram.InlineQueryResultCachedDocument.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(document.id, self.id)
|
self.assertEqual(document.id, self.id)
|
||||||
self.assertEqual(document.type, self.type)
|
self.assertEqual(document.type, self.type)
|
||||||
|
@ -68,12 +68,13 @@ class InlineQueryResultCachedDocumentTest(BaseTest, unittest.TestCase):
|
||||||
self.assertDictEqual(document.reply_markup.to_dict(), self.reply_markup.to_dict())
|
self.assertDictEqual(document.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||||
|
|
||||||
def test_document_to_json(self):
|
def test_document_to_json(self):
|
||||||
document = telegram.InlineQueryResultCachedDocument.de_json(self.json_dict)
|
document = telegram.InlineQueryResultCachedDocument.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(document.to_json()))
|
self.assertTrue(self.is_json(document.to_json()))
|
||||||
|
|
||||||
def test_document_to_dict(self):
|
def test_document_to_dict(self):
|
||||||
document = telegram.InlineQueryResultCachedDocument.de_json(self.json_dict).to_dict()
|
document = telegram.InlineQueryResultCachedDocument.de_json(self.json_dict,
|
||||||
|
self._bot).to_dict()
|
||||||
|
|
||||||
self.assertTrue(self.is_dict(document))
|
self.assertTrue(self.is_dict(document))
|
||||||
self.assertDictEqual(self.json_dict, document)
|
self.assertDictEqual(self.json_dict, document)
|
||||||
|
|
|
@ -53,7 +53,7 @@ class InlineQueryResultCachedGifTest(BaseTest, unittest.TestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_gif_de_json(self):
|
def test_gif_de_json(self):
|
||||||
gif = telegram.InlineQueryResultCachedGif.de_json(self.json_dict)
|
gif = telegram.InlineQueryResultCachedGif.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(gif.type, self.type)
|
self.assertEqual(gif.type, self.type)
|
||||||
self.assertEqual(gif.id, self.id)
|
self.assertEqual(gif.id, self.id)
|
||||||
|
@ -65,12 +65,12 @@ class InlineQueryResultCachedGifTest(BaseTest, unittest.TestCase):
|
||||||
self.assertDictEqual(gif.reply_markup.to_dict(), self.reply_markup.to_dict())
|
self.assertDictEqual(gif.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||||
|
|
||||||
def test_gif_to_json(self):
|
def test_gif_to_json(self):
|
||||||
gif = telegram.InlineQueryResultCachedGif.de_json(self.json_dict)
|
gif = telegram.InlineQueryResultCachedGif.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(gif.to_json()))
|
self.assertTrue(self.is_json(gif.to_json()))
|
||||||
|
|
||||||
def test_gif_to_dict(self):
|
def test_gif_to_dict(self):
|
||||||
gif = telegram.InlineQueryResultCachedGif.de_json(self.json_dict).to_dict()
|
gif = telegram.InlineQueryResultCachedGif.de_json(self.json_dict, self._bot).to_dict()
|
||||||
|
|
||||||
self.assertTrue(self.is_dict(gif))
|
self.assertTrue(self.is_dict(gif))
|
||||||
self.assertDictEqual(self.json_dict, gif)
|
self.assertDictEqual(self.json_dict, gif)
|
||||||
|
|
|
@ -54,7 +54,7 @@ class InlineQueryResultCachedMpeg4GifTest(BaseTest, unittest.TestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_mpeg4_de_json(self):
|
def test_mpeg4_de_json(self):
|
||||||
mpeg4 = telegram.InlineQueryResultCachedMpeg4Gif.de_json(self.json_dict)
|
mpeg4 = telegram.InlineQueryResultCachedMpeg4Gif.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(mpeg4.type, self.type)
|
self.assertEqual(mpeg4.type, self.type)
|
||||||
self.assertEqual(mpeg4.id, self.id)
|
self.assertEqual(mpeg4.id, self.id)
|
||||||
|
@ -66,12 +66,13 @@ class InlineQueryResultCachedMpeg4GifTest(BaseTest, unittest.TestCase):
|
||||||
self.assertDictEqual(mpeg4.reply_markup.to_dict(), self.reply_markup.to_dict())
|
self.assertDictEqual(mpeg4.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||||
|
|
||||||
def test_mpeg4_to_json(self):
|
def test_mpeg4_to_json(self):
|
||||||
mpeg4 = telegram.InlineQueryResultCachedMpeg4Gif.de_json(self.json_dict)
|
mpeg4 = telegram.InlineQueryResultCachedMpeg4Gif.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(mpeg4.to_json()))
|
self.assertTrue(self.is_json(mpeg4.to_json()))
|
||||||
|
|
||||||
def test_mpeg4_to_dict(self):
|
def test_mpeg4_to_dict(self):
|
||||||
mpeg4 = telegram.InlineQueryResultCachedMpeg4Gif.de_json(self.json_dict).to_dict()
|
mpeg4 = telegram.InlineQueryResultCachedMpeg4Gif.de_json(self.json_dict,
|
||||||
|
self._bot).to_dict()
|
||||||
|
|
||||||
self.assertTrue(self.is_dict(mpeg4))
|
self.assertTrue(self.is_dict(mpeg4))
|
||||||
self.assertDictEqual(self.json_dict, mpeg4)
|
self.assertDictEqual(self.json_dict, mpeg4)
|
||||||
|
|
|
@ -56,7 +56,7 @@ class InlineQueryResultCachedPhotoTest(BaseTest, unittest.TestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_photo_de_json(self):
|
def test_photo_de_json(self):
|
||||||
photo = telegram.InlineQueryResultCachedPhoto.de_json(self.json_dict)
|
photo = telegram.InlineQueryResultCachedPhoto.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(photo.type, self.type)
|
self.assertEqual(photo.type, self.type)
|
||||||
self.assertEqual(photo.id, self.id)
|
self.assertEqual(photo.id, self.id)
|
||||||
|
@ -69,12 +69,12 @@ class InlineQueryResultCachedPhotoTest(BaseTest, unittest.TestCase):
|
||||||
self.assertDictEqual(photo.reply_markup.to_dict(), self.reply_markup.to_dict())
|
self.assertDictEqual(photo.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||||
|
|
||||||
def test_photo_to_json(self):
|
def test_photo_to_json(self):
|
||||||
photo = telegram.InlineQueryResultCachedPhoto.de_json(self.json_dict)
|
photo = telegram.InlineQueryResultCachedPhoto.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(photo.to_json()))
|
self.assertTrue(self.is_json(photo.to_json()))
|
||||||
|
|
||||||
def test_photo_to_dict(self):
|
def test_photo_to_dict(self):
|
||||||
photo = telegram.InlineQueryResultCachedPhoto.de_json(self.json_dict).to_dict()
|
photo = telegram.InlineQueryResultCachedPhoto.de_json(self.json_dict, self._bot).to_dict()
|
||||||
|
|
||||||
self.assertTrue(self.is_dict(photo))
|
self.assertTrue(self.is_dict(photo))
|
||||||
self.assertDictEqual(self.json_dict, photo)
|
self.assertDictEqual(self.json_dict, photo)
|
||||||
|
|
|
@ -50,7 +50,7 @@ class InlineQueryResultCachedStickerTest(BaseTest, unittest.TestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_sticker_de_json(self):
|
def test_sticker_de_json(self):
|
||||||
sticker = telegram.InlineQueryResultCachedSticker.de_json(self.json_dict)
|
sticker = telegram.InlineQueryResultCachedSticker.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(sticker.type, self.type)
|
self.assertEqual(sticker.type, self.type)
|
||||||
self.assertEqual(sticker.id, self.id)
|
self.assertEqual(sticker.id, self.id)
|
||||||
|
@ -60,12 +60,13 @@ class InlineQueryResultCachedStickerTest(BaseTest, unittest.TestCase):
|
||||||
self.assertDictEqual(sticker.reply_markup.to_dict(), self.reply_markup.to_dict())
|
self.assertDictEqual(sticker.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||||
|
|
||||||
def test_sticker_to_json(self):
|
def test_sticker_to_json(self):
|
||||||
sticker = telegram.InlineQueryResultCachedSticker.de_json(self.json_dict)
|
sticker = telegram.InlineQueryResultCachedSticker.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(sticker.to_json()))
|
self.assertTrue(self.is_json(sticker.to_json()))
|
||||||
|
|
||||||
def test_sticker_to_dict(self):
|
def test_sticker_to_dict(self):
|
||||||
sticker = telegram.InlineQueryResultCachedSticker.de_json(self.json_dict).to_dict()
|
sticker = telegram.InlineQueryResultCachedSticker.de_json(self.json_dict,
|
||||||
|
self._bot).to_dict()
|
||||||
|
|
||||||
self.assertTrue(self.is_dict(sticker))
|
self.assertTrue(self.is_dict(sticker))
|
||||||
self.assertDictEqual(self.json_dict, sticker)
|
self.assertDictEqual(self.json_dict, sticker)
|
||||||
|
|
|
@ -56,7 +56,7 @@ class InlineQueryResultCachedVideoTest(BaseTest, unittest.TestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_video_de_json(self):
|
def test_video_de_json(self):
|
||||||
video = telegram.InlineQueryResultCachedVideo.de_json(self.json_dict)
|
video = telegram.InlineQueryResultCachedVideo.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(video.type, self.type)
|
self.assertEqual(video.type, self.type)
|
||||||
self.assertEqual(video.id, self.id)
|
self.assertEqual(video.id, self.id)
|
||||||
|
@ -69,12 +69,12 @@ class InlineQueryResultCachedVideoTest(BaseTest, unittest.TestCase):
|
||||||
self.assertDictEqual(video.reply_markup.to_dict(), self.reply_markup.to_dict())
|
self.assertDictEqual(video.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||||
|
|
||||||
def test_video_to_json(self):
|
def test_video_to_json(self):
|
||||||
video = telegram.InlineQueryResultCachedVideo.de_json(self.json_dict)
|
video = telegram.InlineQueryResultCachedVideo.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(video.to_json()))
|
self.assertTrue(self.is_json(video.to_json()))
|
||||||
|
|
||||||
def test_video_to_dict(self):
|
def test_video_to_dict(self):
|
||||||
video = telegram.InlineQueryResultCachedVideo.de_json(self.json_dict).to_dict()
|
video = telegram.InlineQueryResultCachedVideo.de_json(self.json_dict, self._bot).to_dict()
|
||||||
|
|
||||||
self.assertTrue(self.is_dict(video))
|
self.assertTrue(self.is_dict(video))
|
||||||
self.assertDictEqual(self.json_dict, video)
|
self.assertDictEqual(self.json_dict, video)
|
||||||
|
|
|
@ -54,7 +54,7 @@ class InlineQueryResultCachedVoiceTest(BaseTest, unittest.TestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_voice_de_json(self):
|
def test_voice_de_json(self):
|
||||||
voice = telegram.InlineQueryResultCachedVoice.de_json(self.json_dict)
|
voice = telegram.InlineQueryResultCachedVoice.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(voice.type, self.type)
|
self.assertEqual(voice.type, self.type)
|
||||||
self.assertEqual(voice.id, self.id)
|
self.assertEqual(voice.id, self.id)
|
||||||
|
@ -66,12 +66,12 @@ class InlineQueryResultCachedVoiceTest(BaseTest, unittest.TestCase):
|
||||||
self.assertDictEqual(voice.reply_markup.to_dict(), self.reply_markup.to_dict())
|
self.assertDictEqual(voice.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||||
|
|
||||||
def test_voice_to_json(self):
|
def test_voice_to_json(self):
|
||||||
voice = telegram.InlineQueryResultCachedVoice.de_json(self.json_dict)
|
voice = telegram.InlineQueryResultCachedVoice.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(voice.to_json()))
|
self.assertTrue(self.is_json(voice.to_json()))
|
||||||
|
|
||||||
def test_voice_to_dict(self):
|
def test_voice_to_dict(self):
|
||||||
voice = telegram.InlineQueryResultCachedVoice.de_json(self.json_dict).to_dict()
|
voice = telegram.InlineQueryResultCachedVoice.de_json(self.json_dict, self._bot).to_dict()
|
||||||
|
|
||||||
self.assertTrue(self.is_dict(voice))
|
self.assertTrue(self.is_dict(voice))
|
||||||
self.assertDictEqual(self.json_dict, voice)
|
self.assertDictEqual(self.json_dict, voice)
|
||||||
|
|
|
@ -58,7 +58,7 @@ class InlineQueryResultContactTest(BaseTest, unittest.TestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_contact_de_json(self):
|
def test_contact_de_json(self):
|
||||||
contact = telegram.InlineQueryResultContact.de_json(self.json_dict)
|
contact = telegram.InlineQueryResultContact.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(contact.id, self.id)
|
self.assertEqual(contact.id, self.id)
|
||||||
self.assertEqual(contact.type, self.type)
|
self.assertEqual(contact.type, self.type)
|
||||||
|
@ -73,12 +73,12 @@ class InlineQueryResultContactTest(BaseTest, unittest.TestCase):
|
||||||
self.assertDictEqual(contact.reply_markup.to_dict(), self.reply_markup.to_dict())
|
self.assertDictEqual(contact.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||||
|
|
||||||
def test_contact_to_json(self):
|
def test_contact_to_json(self):
|
||||||
contact = telegram.InlineQueryResultContact.de_json(self.json_dict)
|
contact = telegram.InlineQueryResultContact.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(contact.to_json()))
|
self.assertTrue(self.is_json(contact.to_json()))
|
||||||
|
|
||||||
def test_contact_to_dict(self):
|
def test_contact_to_dict(self):
|
||||||
contact = telegram.InlineQueryResultContact.de_json(self.json_dict).to_dict()
|
contact = telegram.InlineQueryResultContact.de_json(self.json_dict, self._bot).to_dict()
|
||||||
|
|
||||||
self.assertTrue(self.is_dict(contact))
|
self.assertTrue(self.is_dict(contact))
|
||||||
self.assertDictEqual(self.json_dict, contact)
|
self.assertDictEqual(self.json_dict, contact)
|
||||||
|
|
|
@ -62,7 +62,7 @@ class InlineQueryResultDocumentTest(BaseTest, unittest.TestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_document_de_json(self):
|
def test_document_de_json(self):
|
||||||
document = telegram.InlineQueryResultDocument.de_json(self.json_dict)
|
document = telegram.InlineQueryResultDocument.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(document.id, self.id)
|
self.assertEqual(document.id, self.id)
|
||||||
self.assertEqual(document.type, self.type)
|
self.assertEqual(document.type, self.type)
|
||||||
|
@ -79,12 +79,12 @@ class InlineQueryResultDocumentTest(BaseTest, unittest.TestCase):
|
||||||
self.assertDictEqual(document.reply_markup.to_dict(), self.reply_markup.to_dict())
|
self.assertDictEqual(document.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||||
|
|
||||||
def test_document_to_json(self):
|
def test_document_to_json(self):
|
||||||
document = telegram.InlineQueryResultDocument.de_json(self.json_dict)
|
document = telegram.InlineQueryResultDocument.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(document.to_json()))
|
self.assertTrue(self.is_json(document.to_json()))
|
||||||
|
|
||||||
def test_document_to_dict(self):
|
def test_document_to_dict(self):
|
||||||
document = telegram.InlineQueryResultDocument.de_json(self.json_dict).to_dict()
|
document = telegram.InlineQueryResultDocument.de_json(self.json_dict, self._bot).to_dict()
|
||||||
|
|
||||||
self.assertTrue(self.is_dict(document))
|
self.assertTrue(self.is_dict(document))
|
||||||
self.assertDictEqual(self.json_dict, document)
|
self.assertDictEqual(self.json_dict, document)
|
||||||
|
|
|
@ -59,7 +59,7 @@ class InlineQueryResultGifTest(BaseTest, unittest.TestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_gif_de_json(self):
|
def test_gif_de_json(self):
|
||||||
gif = telegram.InlineQueryResultGif.de_json(self.json_dict)
|
gif = telegram.InlineQueryResultGif.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(gif.type, self.type)
|
self.assertEqual(gif.type, self.type)
|
||||||
self.assertEqual(gif.id, self.id)
|
self.assertEqual(gif.id, self.id)
|
||||||
|
@ -74,12 +74,12 @@ class InlineQueryResultGifTest(BaseTest, unittest.TestCase):
|
||||||
self.assertDictEqual(gif.reply_markup.to_dict(), self.reply_markup.to_dict())
|
self.assertDictEqual(gif.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||||
|
|
||||||
def test_gif_to_json(self):
|
def test_gif_to_json(self):
|
||||||
gif = telegram.InlineQueryResultGif.de_json(self.json_dict)
|
gif = telegram.InlineQueryResultGif.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(gif.to_json()))
|
self.assertTrue(self.is_json(gif.to_json()))
|
||||||
|
|
||||||
def test_gif_to_dict(self):
|
def test_gif_to_dict(self):
|
||||||
gif = telegram.InlineQueryResultGif.de_json(self.json_dict).to_dict()
|
gif = telegram.InlineQueryResultGif.de_json(self.json_dict, self._bot).to_dict()
|
||||||
|
|
||||||
self.assertTrue(self.is_dict(gif))
|
self.assertTrue(self.is_dict(gif))
|
||||||
self.assertDictEqual(self.json_dict, gif)
|
self.assertDictEqual(self.json_dict, gif)
|
||||||
|
|
|
@ -58,7 +58,7 @@ class InlineQueryResultLocationTest(BaseTest, unittest.TestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_location_de_json(self):
|
def test_location_de_json(self):
|
||||||
location = telegram.InlineQueryResultLocation.de_json(self.json_dict)
|
location = telegram.InlineQueryResultLocation.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(location.id, self.id)
|
self.assertEqual(location.id, self.id)
|
||||||
self.assertEqual(location.type, self.type)
|
self.assertEqual(location.type, self.type)
|
||||||
|
@ -73,12 +73,12 @@ class InlineQueryResultLocationTest(BaseTest, unittest.TestCase):
|
||||||
self.assertDictEqual(location.reply_markup.to_dict(), self.reply_markup.to_dict())
|
self.assertDictEqual(location.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||||
|
|
||||||
def test_location_to_json(self):
|
def test_location_to_json(self):
|
||||||
location = telegram.InlineQueryResultLocation.de_json(self.json_dict)
|
location = telegram.InlineQueryResultLocation.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(location.to_json()))
|
self.assertTrue(self.is_json(location.to_json()))
|
||||||
|
|
||||||
def test_location_to_dict(self):
|
def test_location_to_dict(self):
|
||||||
location = telegram.InlineQueryResultLocation.de_json(self.json_dict).to_dict()
|
location = telegram.InlineQueryResultLocation.de_json(self.json_dict, self._bot).to_dict()
|
||||||
|
|
||||||
self.assertTrue(self.is_dict(location))
|
self.assertTrue(self.is_dict(location))
|
||||||
self.assertDictEqual(self.json_dict, location)
|
self.assertDictEqual(self.json_dict, location)
|
||||||
|
|
|
@ -59,7 +59,7 @@ class InlineQueryResultMpeg4GifTest(BaseTest, unittest.TestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_mpeg4_de_json(self):
|
def test_mpeg4_de_json(self):
|
||||||
mpeg4 = telegram.InlineQueryResultMpeg4Gif.de_json(self.json_dict)
|
mpeg4 = telegram.InlineQueryResultMpeg4Gif.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(mpeg4.type, self.type)
|
self.assertEqual(mpeg4.type, self.type)
|
||||||
self.assertEqual(mpeg4.id, self.id)
|
self.assertEqual(mpeg4.id, self.id)
|
||||||
|
@ -74,12 +74,12 @@ class InlineQueryResultMpeg4GifTest(BaseTest, unittest.TestCase):
|
||||||
self.assertDictEqual(mpeg4.reply_markup.to_dict(), self.reply_markup.to_dict())
|
self.assertDictEqual(mpeg4.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||||
|
|
||||||
def test_mpeg4_to_json(self):
|
def test_mpeg4_to_json(self):
|
||||||
mpeg4 = telegram.InlineQueryResultMpeg4Gif.de_json(self.json_dict)
|
mpeg4 = telegram.InlineQueryResultMpeg4Gif.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(mpeg4.to_json()))
|
self.assertTrue(self.is_json(mpeg4.to_json()))
|
||||||
|
|
||||||
def test_mpeg4_to_dict(self):
|
def test_mpeg4_to_dict(self):
|
||||||
mpeg4 = telegram.InlineQueryResultMpeg4Gif.de_json(self.json_dict).to_dict()
|
mpeg4 = telegram.InlineQueryResultMpeg4Gif.de_json(self.json_dict, self._bot).to_dict()
|
||||||
|
|
||||||
self.assertTrue(self.is_dict(mpeg4))
|
self.assertTrue(self.is_dict(mpeg4))
|
||||||
self.assertDictEqual(self.json_dict, mpeg4)
|
self.assertDictEqual(self.json_dict, mpeg4)
|
||||||
|
|
|
@ -61,7 +61,7 @@ class InlineQueryResultPhotoTest(BaseTest, unittest.TestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_photo_de_json(self):
|
def test_photo_de_json(self):
|
||||||
photo = telegram.InlineQueryResultPhoto.de_json(self.json_dict)
|
photo = telegram.InlineQueryResultPhoto.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(photo.type, self.type)
|
self.assertEqual(photo.type, self.type)
|
||||||
self.assertEqual(photo.id, self.id)
|
self.assertEqual(photo.id, self.id)
|
||||||
|
@ -77,12 +77,12 @@ class InlineQueryResultPhotoTest(BaseTest, unittest.TestCase):
|
||||||
self.assertDictEqual(photo.reply_markup.to_dict(), self.reply_markup.to_dict())
|
self.assertDictEqual(photo.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||||
|
|
||||||
def test_photo_to_json(self):
|
def test_photo_to_json(self):
|
||||||
photo = telegram.InlineQueryResultPhoto.de_json(self.json_dict)
|
photo = telegram.InlineQueryResultPhoto.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(photo.to_json()))
|
self.assertTrue(self.is_json(photo.to_json()))
|
||||||
|
|
||||||
def test_photo_to_dict(self):
|
def test_photo_to_dict(self):
|
||||||
photo = telegram.InlineQueryResultPhoto.de_json(self.json_dict).to_dict()
|
photo = telegram.InlineQueryResultPhoto.de_json(self.json_dict, self._bot).to_dict()
|
||||||
|
|
||||||
self.assertTrue(self.is_dict(photo))
|
self.assertTrue(self.is_dict(photo))
|
||||||
self.assertDictEqual(self.json_dict, photo)
|
self.assertDictEqual(self.json_dict, photo)
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue