mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-11 01:59:12 +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 .base import TelegramObject
|
||||||
from .user import User
|
from .user import User
|
||||||
from .chat import Chat
|
from .chat import Chat
|
||||||
|
from .chatmember import ChatMember
|
||||||
from .photosize import PhotoSize
|
from .photosize import PhotoSize
|
||||||
from .audio import Audio
|
from .audio import Audio
|
||||||
from .voice import Voice
|
from .voice import Voice
|
||||||
|
@ -82,22 +83,23 @@ from .bot import Bot
|
||||||
|
|
||||||
__author__ = 'devs@python-telegram-bot.org'
|
__author__ = 'devs@python-telegram-bot.org'
|
||||||
__version__ = '4.1.2'
|
__version__ = '4.1.2'
|
||||||
__all__ = ['Audio', 'Bot', 'Chat', 'ChatAction', 'ChosenInlineResult', 'CallbackQuery', 'Contact',
|
__all__ = ['Audio', 'Bot', 'Chat', 'ChatMember', 'ChatAction', 'ChosenInlineResult',
|
||||||
'Document', 'Emoji', 'File', 'ForceReply', 'InlineKeyboardButton',
|
'CallbackQuery', 'Contact', 'Document', 'Emoji', 'File', 'ForceReply',
|
||||||
'InlineKeyboardMarkup', 'InlineQuery', 'InlineQueryResult', 'InlineQueryResult',
|
'InlineKeyboardButton', 'InlineKeyboardMarkup', 'InlineQuery', 'InlineQueryResult',
|
||||||
'InlineQueryResultArticle', 'InlineQueryResultAudio', 'InlineQueryResultCachedAudio',
|
'InlineQueryResult', 'InlineQueryResultArticle', 'InlineQueryResultAudio',
|
||||||
'InlineQueryResultCachedDocument', 'InlineQueryResultCachedGif',
|
'InlineQueryResultCachedAudio', 'InlineQueryResultCachedDocument',
|
||||||
'InlineQueryResultCachedMpeg4Gif', 'InlineQueryResultCachedPhoto',
|
'InlineQueryResultCachedGif', 'InlineQueryResultCachedMpeg4Gif',
|
||||||
'InlineQueryResultCachedSticker', 'InlineQueryResultCachedVideo',
|
'InlineQueryResultCachedPhoto', 'InlineQueryResultCachedSticker',
|
||||||
'InlineQueryResultCachedVoice', 'InlineQueryResultContact', 'InlineQueryResultDocument',
|
'InlineQueryResultCachedVideo', 'InlineQueryResultCachedVoice',
|
||||||
'InlineQueryResultGif', 'InlineQueryResultLocation', 'InlineQueryResultMpeg4Gif',
|
'InlineQueryResultContact', 'InlineQueryResultDocument', 'InlineQueryResultGif',
|
||||||
'InlineQueryResultPhoto', 'InlineQueryResultVenue', 'InlineQueryResultVideo',
|
'InlineQueryResultLocation', 'InlineQueryResultMpeg4Gif', 'InlineQueryResultPhoto',
|
||||||
'InlineQueryResultVoice', 'InputContactMessageContent', 'InputFile',
|
'InlineQueryResultVenue', 'InlineQueryResultVideo', 'InlineQueryResultVoice',
|
||||||
'InputLocationMessageContent', 'InputMessageContent', 'InputTextMessageContent',
|
'InputContactMessageContent', 'InputFile', 'InputLocationMessageContent',
|
||||||
'InputVenueMessageContent', 'KeyboardButton', 'Location', 'Message', 'MessageEntity',
|
'InputMessageContent', 'InputTextMessageContent', 'InputVenueMessageContent',
|
||||||
'NullHandler', 'ParseMode', 'PhotoSize', 'ReplyKeyboardHide', 'ReplyKeyboardMarkup',
|
'KeyboardButton', 'Location', 'Message', 'MessageEntity', 'NullHandler', 'ParseMode',
|
||||||
'ReplyMarkup', 'Sticker', 'TelegramError', 'TelegramObject', 'Update', 'User',
|
'PhotoSize', 'ReplyKeyboardHide', 'ReplyKeyboardMarkup', 'ReplyMarkup', 'Sticker',
|
||||||
'UserProfilePhotos', 'Venue', 'Video', 'Voice']
|
'TelegramError', 'TelegramObject', 'Update', 'User', 'UserProfilePhotos', 'Venue',
|
||||||
|
'Video', 'Voice']
|
||||||
|
|
||||||
if version_info < (2, 7):
|
if version_info < (2, 7):
|
||||||
from warnings import warn
|
from warnings import warn
|
||||||
|
|
|
@ -19,11 +19,11 @@
|
||||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||||
"""This module contains a object that represents a Telegram Bot."""
|
"""This module contains a object that represents a Telegram Bot."""
|
||||||
|
|
||||||
import logging
|
|
||||||
import functools
|
import functools
|
||||||
|
import logging
|
||||||
|
|
||||||
from telegram import (User, Message, Update, UserProfilePhotos, File, ReplyMarkup, TelegramObject,
|
from telegram import (User, Message, Update, Chat, ChatMember, UserProfilePhotos, File,
|
||||||
NullHandler)
|
ReplyMarkup, TelegramObject, NullHandler)
|
||||||
from telegram.utils import request
|
from telegram.utils import request
|
||||||
from telegram.utils.validate import validate_token
|
from telegram.utils.validate import validate_token
|
||||||
|
|
||||||
|
@ -1259,6 +1259,56 @@ class Bot(TelegramObject):
|
||||||
|
|
||||||
return result
|
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
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data):
|
||||||
data = super(Bot, Bot).de_json(data)
|
data = super(Bot, Bot).de_json(data)
|
||||||
|
@ -1302,3 +1352,8 @@ class Bot(TelegramObject):
|
||||||
edit_message_reply_markup = editMessageReplyMarkup
|
edit_message_reply_markup = editMessageReplyMarkup
|
||||||
get_updates = getUpdates
|
get_updates = getUpdates
|
||||||
set_webhook = setWebhook
|
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…
Add table
Reference in a new issue