mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
First Init.
This commit is contained in:
commit
9c3886f332
61
.gitignore
vendored
Normal file
61
.gitignore
vendored
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
env/
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
|
||||||
|
.idea/
|
||||||
|
venv/
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
# Usually these files are written by a python script from a template
|
||||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*,cover
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
target/
|
||||||
|
testMain.py
|
39
telebot/__init__.py
Normal file
39
telebot/__init__.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import apihelper
|
||||||
|
|
||||||
|
"""
|
||||||
|
Module : telebot
|
||||||
|
"""
|
||||||
|
|
||||||
|
API_URL = r"https://api.telegram.org/"
|
||||||
|
|
||||||
|
|
||||||
|
class TeleBot:
|
||||||
|
""" This is TeleBot Class
|
||||||
|
Methods:
|
||||||
|
getMe
|
||||||
|
sendMessage
|
||||||
|
forwardMessage
|
||||||
|
sendPhoto
|
||||||
|
sendAudio
|
||||||
|
sendDocument
|
||||||
|
sendSticker
|
||||||
|
sendVideo
|
||||||
|
sendLocation
|
||||||
|
sendChatAction
|
||||||
|
getUserProfilePhotos
|
||||||
|
getUpdates
|
||||||
|
setWebhook
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, token):
|
||||||
|
self.token = token
|
||||||
|
|
||||||
|
def get_me(self):
|
||||||
|
# TODO
|
||||||
|
return None
|
||||||
|
|
||||||
|
def send_message(self, chat_id, text, disable_web_page_preview=None, reply_to_message_id=None, reply_markup=None):
|
||||||
|
return apihelper.send_message(self.token, chat_id, text, disable_web_page_preview, reply_to_message_id,
|
||||||
|
reply_markup)
|
20
telebot/apihelper.py
Normal file
20
telebot/apihelper.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import telebot
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
def send_message(token, chat_id, text, disable_web_page_preview=None, reply_to_message_id=None, reply_markup=None):
|
||||||
|
api_url = telebot.API_URL
|
||||||
|
method_url = r'sendMessage'
|
||||||
|
request_url = api_url + 'bot' + token + '/' + method_url
|
||||||
|
paras = 'chat_id=' + str(chat_id) + '&text=' + text
|
||||||
|
if disable_web_page_preview:
|
||||||
|
paras = paras + '&disable_web_page_preview=' + disable_web_page_preview
|
||||||
|
if reply_to_message_id:
|
||||||
|
paras = paras + '&reply_to_message_id=' + reply_to_message_id
|
||||||
|
if reply_markup:
|
||||||
|
paras = paras + '&reply_markup=' + reply_markup
|
||||||
|
request_url = request_url + '?' + paras
|
||||||
|
req = requests.get(request_url)
|
||||||
|
return req.json()
|
117
telebot/types.py
Normal file
117
telebot/types.py
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
Available types
|
||||||
|
|
||||||
|
User
|
||||||
|
GroupChat
|
||||||
|
Message
|
||||||
|
PhotoSize
|
||||||
|
Audio
|
||||||
|
Document
|
||||||
|
Sticker
|
||||||
|
Video
|
||||||
|
Contact
|
||||||
|
Location
|
||||||
|
Update
|
||||||
|
InputFile
|
||||||
|
UserProfilePhotos
|
||||||
|
ReplyKeyboardMarkup
|
||||||
|
ReplyKeyboardHide
|
||||||
|
ForceReply
|
||||||
|
"""
|
||||||
|
|
||||||
|
class User:
|
||||||
|
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
|
Loading…
Reference in New Issue
Block a user