1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00
pyTelegramBotAPI/telebot/types.py
2015-06-26 15:15:30 +08:00

134 lines
3.2 KiB
Python

# -*- coding: utf-8 -*-
"""
Available types
User
GroupChat
Message
PhotoSize
Audio
Document
Sticker
Video
Contact
Location
Update
InputFile
UserProfilePhotos
ReplyKeyboardMarkup
ReplyKeyboardHide
ForceReply
"""
import json
class User:
@classmethod
def de_json(cls, json_string):
obj = json.loads(json_string)
id = obj['id']
first_name = obj['first_name']
last_name = None
username = None
if 'last_name' in obj:
last_name = obj['last_name']
if 'username' in obj:
username = obj['username']
return User(id, first_name, last_name, username)
def __init__(self, id, first_name, last_name=None, username=None):
self.id = id
self.first_name = first_name
self.username = username
self.last_name = last_name
class GroupChat:
def __init__(self, id, title):
self.id = id
self.title = title
class Message:
def __init__(self, message_id, fromUser, date, chat, **options):
# TODO Add options.
self.chat = chat
self.date = date
self.fromUser = fromUser
self.message_id = message_id
class PhotoSize:
def __init__(self, file_id, width, height, file_size):
self.file_size = file_size
self.height = height
self.width = width
self.file_id = file_id
class Audio:
def __init__(self, file_id, duration, mime_type=None, file_size=None):
self.file_id = file_id
self.duration = duration
self.mime_type = mime_type
self.file_size = file_size
class Document:
def __init__(self, file_id, thumb, file_name=None, mime_type=None, file_size=None):
self.file_id = file_id
self.thumb = thumb
self.file_name = file_name
self.mime_type = mime_type
self.file_size = file_size
class Sticker:
def __init__(self, file_id, width, height, thumb, file_size=None):
self.file_id = file_id
self.width = width
self.height = height
self.thumb = thumb
self.file_size = file_size
class Video:
def __init__(self, file_id, width, height, duration, thumb, mime_type=None, file_size=None, caption=None):
self.file_id = file_id
self.width = width
self.height = height
self.duration = duration
self.thumb = thumb
self.mime_type = mime_type
self.file_size = file_size
self.caption = caption
class Contact:
def __init__(self, phone_number, first_name, last_name=None, user_id=None):
self.phone_number = phone_number
self.first_name = first_name
self.last_name = last_name
self.user_id = user_id
class Location:
def __init__(self, longitude, latitude):
self.longitude = longitude
self.latitude = latitude
class UserProfilePhotos:
def __init__(self, total_count, photos):
self.total_count = total_count
self.photos = photos
class ReplyKeyboardMarkup:
def __init__(self, keyboard, resize_keyboard=None, one_time_keyboard=None, selective=None):
self.keyboard = keyboard
self.resize_keyboard = resize_keyboard
self.one_time_keyboard = one_time_keyboard
self.selective = selective