From 9c3886f332f7fbc79a40759b8cac3add7946fd1e Mon Sep 17 00:00:00 2001 From: eternnoir Date: Fri, 26 Jun 2015 14:55:13 +0800 Subject: [PATCH] First Init. --- .gitignore | 61 ++++++++++++++++++++++ telebot/__init__.py | 39 +++++++++++++++ telebot/apihelper.py | 20 ++++++++ telebot/types.py | 117 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 237 insertions(+) create mode 100644 .gitignore create mode 100644 telebot/__init__.py create mode 100644 telebot/apihelper.py create mode 100644 telebot/types.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e821e9e --- /dev/null +++ b/.gitignore @@ -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 \ No newline at end of file diff --git a/telebot/__init__.py b/telebot/__init__.py new file mode 100644 index 0000000..db6bcf5 --- /dev/null +++ b/telebot/__init__.py @@ -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) diff --git a/telebot/apihelper.py b/telebot/apihelper.py new file mode 100644 index 0000000..d3a8dd0 --- /dev/null +++ b/telebot/apihelper.py @@ -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() diff --git a/telebot/types.py b/telebot/types.py new file mode 100644 index 0000000..e331b1e --- /dev/null +++ b/telebot/types.py @@ -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