mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-31 16:40:53 +01:00
Add new Bot methods and ChatMember class #302
This commit is contained in:
parent
7c84516d2b
commit
d7e226ec0f
3 changed files with 132 additions and 19 deletions
|
@ -23,6 +23,7 @@ from sys import version_info
|
|||
from .base import TelegramObject
|
||||
from .user import User
|
||||
from .chat import Chat
|
||||
from .chatmember import ChatMember
|
||||
from .photosize import PhotoSize
|
||||
from .audio import Audio
|
||||
from .voice import Voice
|
||||
|
@ -82,22 +83,23 @@ from .bot import Bot
|
|||
|
||||
__author__ = 'devs@python-telegram-bot.org'
|
||||
__version__ = '4.1.2'
|
||||
__all__ = ['Audio', 'Bot', 'Chat', 'ChatAction', 'ChosenInlineResult', 'CallbackQuery', 'Contact',
|
||||
'Document', 'Emoji', 'File', 'ForceReply', 'InlineKeyboardButton',
|
||||
'InlineKeyboardMarkup', 'InlineQuery', 'InlineQueryResult', 'InlineQueryResult',
|
||||
'InlineQueryResultArticle', 'InlineQueryResultAudio', 'InlineQueryResultCachedAudio',
|
||||
'InlineQueryResultCachedDocument', 'InlineQueryResultCachedGif',
|
||||
'InlineQueryResultCachedMpeg4Gif', 'InlineQueryResultCachedPhoto',
|
||||
'InlineQueryResultCachedSticker', 'InlineQueryResultCachedVideo',
|
||||
'InlineQueryResultCachedVoice', 'InlineQueryResultContact', 'InlineQueryResultDocument',
|
||||
'InlineQueryResultGif', 'InlineQueryResultLocation', 'InlineQueryResultMpeg4Gif',
|
||||
'InlineQueryResultPhoto', 'InlineQueryResultVenue', 'InlineQueryResultVideo',
|
||||
'InlineQueryResultVoice', 'InputContactMessageContent', 'InputFile',
|
||||
'InputLocationMessageContent', 'InputMessageContent', 'InputTextMessageContent',
|
||||
'InputVenueMessageContent', 'KeyboardButton', 'Location', 'Message', 'MessageEntity',
|
||||
'NullHandler', 'ParseMode', 'PhotoSize', 'ReplyKeyboardHide', 'ReplyKeyboardMarkup',
|
||||
'ReplyMarkup', 'Sticker', 'TelegramError', 'TelegramObject', 'Update', 'User',
|
||||
'UserProfilePhotos', 'Venue', 'Video', 'Voice']
|
||||
__all__ = ['Audio', 'Bot', 'Chat', 'ChatMember', 'ChatAction', 'ChosenInlineResult',
|
||||
'CallbackQuery', 'Contact', 'Document', 'Emoji', 'File', 'ForceReply',
|
||||
'InlineKeyboardButton', 'InlineKeyboardMarkup', 'InlineQuery', 'InlineQueryResult',
|
||||
'InlineQueryResult', 'InlineQueryResultArticle', 'InlineQueryResultAudio',
|
||||
'InlineQueryResultCachedAudio', 'InlineQueryResultCachedDocument',
|
||||
'InlineQueryResultCachedGif', 'InlineQueryResultCachedMpeg4Gif',
|
||||
'InlineQueryResultCachedPhoto', 'InlineQueryResultCachedSticker',
|
||||
'InlineQueryResultCachedVideo', 'InlineQueryResultCachedVoice',
|
||||
'InlineQueryResultContact', 'InlineQueryResultDocument', 'InlineQueryResultGif',
|
||||
'InlineQueryResultLocation', 'InlineQueryResultMpeg4Gif', 'InlineQueryResultPhoto',
|
||||
'InlineQueryResultVenue', 'InlineQueryResultVideo', 'InlineQueryResultVoice',
|
||||
'InputContactMessageContent', 'InputFile', 'InputLocationMessageContent',
|
||||
'InputMessageContent', 'InputTextMessageContent', 'InputVenueMessageContent',
|
||||
'KeyboardButton', 'Location', 'Message', 'MessageEntity', 'NullHandler', 'ParseMode',
|
||||
'PhotoSize', 'ReplyKeyboardHide', 'ReplyKeyboardMarkup', 'ReplyMarkup', 'Sticker',
|
||||
'TelegramError', 'TelegramObject', 'Update', 'User', 'UserProfilePhotos', 'Venue',
|
||||
'Video', 'Voice']
|
||||
|
||||
if version_info < (2, 7):
|
||||
from warnings import warn
|
||||
|
|
|
@ -19,11 +19,11 @@
|
|||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents a Telegram Bot."""
|
||||
|
||||
import logging
|
||||
import functools
|
||||
import logging
|
||||
|
||||
from telegram import (User, Message, Update, UserProfilePhotos, File, ReplyMarkup, TelegramObject,
|
||||
NullHandler)
|
||||
from telegram import (User, Message, Update, Chat, ChatMember, UserProfilePhotos, File,
|
||||
ReplyMarkup, TelegramObject, NullHandler)
|
||||
from telegram.utils import request
|
||||
from telegram.utils.validate import validate_token
|
||||
|
||||
|
@ -1259,6 +1259,56 @@ class Bot(TelegramObject):
|
|||
|
||||
return result
|
||||
|
||||
@log
|
||||
def leaveChat(self, chat_id, **kwargs):
|
||||
url = '{0}/leaveChat'.format(self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id}
|
||||
|
||||
result = request.post(url, data, timeout=kwargs.get('timeout'))
|
||||
|
||||
return result
|
||||
|
||||
@log
|
||||
def getChat(self, chat_id, **kwargs):
|
||||
url = '{0}/getChat'.format(self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id}
|
||||
|
||||
result = request.post(url, data, timeout=kwargs.get('timeout'))
|
||||
|
||||
return Chat.de_json(result)
|
||||
|
||||
@log
|
||||
def getChatAdministrators(self, chat_id, **kwargs):
|
||||
url = '{0}/getChatAdministrators'.format(self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id}
|
||||
|
||||
result = request.post(url, data, timeout=kwargs.get('timeout'))
|
||||
|
||||
return [ChatMember.de_json(x) for x in result]
|
||||
|
||||
@log
|
||||
def getChatMembersCount(self, chat_id, **kwargs):
|
||||
url = '{0}/getChatMembersCount'.format(self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id}
|
||||
|
||||
result = request.post(url, data, timeout=kwargs.get('timeout'))
|
||||
|
||||
return result
|
||||
|
||||
@log
|
||||
def getChatMember(self, chat_id, user_id, **kwargs):
|
||||
url = '{0}/getChatMember'.format(self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id, 'user_id': user_id}
|
||||
|
||||
result = request.post(url, data, timeout=kwargs.get('timeout'))
|
||||
|
||||
return ChatMember.de_json(result)
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(Bot, Bot).de_json(data)
|
||||
|
@ -1302,3 +1352,8 @@ class Bot(TelegramObject):
|
|||
edit_message_reply_markup = editMessageReplyMarkup
|
||||
get_updates = getUpdates
|
||||
set_webhook = setWebhook
|
||||
leave_chat = leaveChat
|
||||
get_chat = getChat
|
||||
get_chat_administrators = getChatAdministrators
|
||||
get_chat_member = getChatMember
|
||||
get_chat_member_count = getChatMembersCount
|
||||
|
|
56
telegram/chatmember.py
Normal file
56
telegram/chatmember.py
Normal file
|
@ -0,0 +1,56 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents a Telegram ChatMember."""
|
||||
|
||||
from telegram import User, TelegramObject
|
||||
|
||||
|
||||
class ChatMember(TelegramObject):
|
||||
"""This object represents a Telegram ChatMember.
|
||||
|
||||
Attributes:
|
||||
user (:class:`telegram.User`): Information about the user.
|
||||
status (str): The member's status in the chat. Can be 'creator', 'administrator', 'member',
|
||||
'left' or 'kicked'.
|
||||
|
||||
Args:
|
||||
user (:class:`telegram.User`):
|
||||
status (str):
|
||||
"""
|
||||
|
||||
def __init__(self, user, status, **kwargs):
|
||||
# Required
|
||||
self.user = user
|
||||
self.status = status
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
"""
|
||||
Args:
|
||||
data (dict):
|
||||
|
||||
Returns:
|
||||
telegram.ChatMember:
|
||||
"""
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['user'] = User.de_json(data.get('user'))
|
||||
|
||||
return ChatMember(**data)
|
Loading…
Reference in a new issue