Refactoring. AIOGramBot -> Bot and allow to use 'from aiogram import Bot'

This commit is contained in:
Alex Root Junior 2017-06-02 05:09:09 +03:00
parent 16cda7af67
commit 92b3e027db
6 changed files with 23 additions and 15 deletions

View file

@ -1,8 +1,3 @@
import logging
from .bot import Bot
__version__ = '0.1b'
log = logging.getLogger(__name__)
API_URL = "https://api.telegram.org/bot{token}/{method}"
FILE_URL = "https://api.telegram.org/file/bot{token}/{file_id}"

View file

@ -1,10 +1,12 @@
import logging
import os
import aiohttp
from . import API_URL, log
from .exceptions import ValidationError, TelegramAPIError
log = logging.getLogger(__name__)
def check_token(token):
if any(x.isspace() for x in token):
@ -117,3 +119,7 @@ class ApiMethods:
EDIT_MESSAGE_CAPTION = 'editMessageCaption'
EDIT_MESSAGE_REPLY_MARKUP = 'editMessageReplyMarkup'
DELETE_MESSAGE = 'deleteMessage'
API_URL = "https://api.telegram.org/bot{token}/{method}"
FILE_URL = "https://api.telegram.org/file/bot{token}/{file_id}"

View file

@ -1,5 +1,6 @@
import asyncio
import json
import logging
import aiohttp
@ -7,8 +8,10 @@ from . import api
from . import types
from .utils.payload import generate_payload
log = logging.getLogger(__name__)
class AIOGramBot:
class Bot:
def __init__(self, token, loop=None, connections_limit=10):
"""
:param token:

View file

@ -3,7 +3,7 @@ import logging
from .filters import CommandsFilter, RegexpFilter, ContentTypeFilter
from .handler import Handler
from ..bot import AIOGramBot
from ..bot import Bot
from ..types.message import ContentType
log = logging.getLogger(__name__)
@ -11,7 +11,7 @@ log = logging.getLogger(__name__)
class Dispatcher:
def __init__(self, bot, loop=None):
self.bot: AIOGramBot = bot
self.bot: Bot = bot
if loop is None:
loop = self.bot.loop

View file

@ -1,9 +1,13 @@
"""
Babel is required.
"""
import asyncio
import logging
from aiogram.bot import AIOGramBot
from aiogram import Bot
from aiogram.dispatcher import Dispatcher
from aiogram.types.message import ParseMode
from aiogram.types import ParseMode
from aiogram.utils.markdown import *
API_TOKEN = 'BOT TOKEN HERE'
@ -11,7 +15,7 @@ API_TOKEN = 'BOT TOKEN HERE'
logging.basicConfig(level=logging.INFO)
loop = asyncio.get_event_loop()
bot = AIOGramBot(token=API_TOKEN, loop=loop)
bot = Bot(token=API_TOKEN, loop=loop)
dp = Dispatcher(bot)

View file

@ -1,7 +1,7 @@
import asyncio
import logging
from aiogram.bot import AIOGramBot
from aiogram import Bot
from aiogram.dispatcher import Dispatcher
API_TOKEN = 'BOT TOKEN HERE'
@ -9,7 +9,7 @@ API_TOKEN = 'BOT TOKEN HERE'
logging.basicConfig(level=logging.INFO)
loop = asyncio.get_event_loop()
bot = AIOGramBot(token=API_TOKEN, loop=loop)
bot = Bot(token=API_TOKEN, loop=loop)
dp = Dispatcher(bot)