mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-09 09:22:03 +00:00
Refactoring. AIOGramBot -> Bot and allow to use 'from aiogram import Bot'
This commit is contained in:
parent
16cda7af67
commit
92b3e027db
6 changed files with 23 additions and 15 deletions
|
|
@ -1,8 +1,3 @@
|
||||||
import logging
|
from .bot import Bot
|
||||||
|
|
||||||
__version__ = '0.1b'
|
__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}"
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
from . import API_URL, log
|
|
||||||
from .exceptions import ValidationError, TelegramAPIError
|
from .exceptions import ValidationError, TelegramAPIError
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def check_token(token):
|
def check_token(token):
|
||||||
if any(x.isspace() for x in token):
|
if any(x.isspace() for x in token):
|
||||||
|
|
@ -117,3 +119,7 @@ class ApiMethods:
|
||||||
EDIT_MESSAGE_CAPTION = 'editMessageCaption'
|
EDIT_MESSAGE_CAPTION = 'editMessageCaption'
|
||||||
EDIT_MESSAGE_REPLY_MARKUP = 'editMessageReplyMarkup'
|
EDIT_MESSAGE_REPLY_MARKUP = 'editMessageReplyMarkup'
|
||||||
DELETE_MESSAGE = 'deleteMessage'
|
DELETE_MESSAGE = 'deleteMessage'
|
||||||
|
|
||||||
|
|
||||||
|
API_URL = "https://api.telegram.org/bot{token}/{method}"
|
||||||
|
FILE_URL = "https://api.telegram.org/file/bot{token}/{file_id}"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
|
|
@ -7,8 +8,10 @@ from . import api
|
||||||
from . import types
|
from . import types
|
||||||
from .utils.payload import generate_payload
|
from .utils.payload import generate_payload
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
class AIOGramBot:
|
|
||||||
|
class Bot:
|
||||||
def __init__(self, token, loop=None, connections_limit=10):
|
def __init__(self, token, loop=None, connections_limit=10):
|
||||||
"""
|
"""
|
||||||
:param token:
|
:param token:
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import logging
|
||||||
|
|
||||||
from .filters import CommandsFilter, RegexpFilter, ContentTypeFilter
|
from .filters import CommandsFilter, RegexpFilter, ContentTypeFilter
|
||||||
from .handler import Handler
|
from .handler import Handler
|
||||||
from ..bot import AIOGramBot
|
from ..bot import Bot
|
||||||
from ..types.message import ContentType
|
from ..types.message import ContentType
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
@ -11,7 +11,7 @@ log = logging.getLogger(__name__)
|
||||||
|
|
||||||
class Dispatcher:
|
class Dispatcher:
|
||||||
def __init__(self, bot, loop=None):
|
def __init__(self, bot, loop=None):
|
||||||
self.bot: AIOGramBot = bot
|
self.bot: Bot = bot
|
||||||
if loop is None:
|
if loop is None:
|
||||||
loop = self.bot.loop
|
loop = self.bot.loop
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,13 @@
|
||||||
|
"""
|
||||||
|
Babel is required.
|
||||||
|
"""
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from aiogram.bot import AIOGramBot
|
from aiogram import Bot
|
||||||
from aiogram.dispatcher import Dispatcher
|
from aiogram.dispatcher import Dispatcher
|
||||||
from aiogram.types.message import ParseMode
|
from aiogram.types import ParseMode
|
||||||
from aiogram.utils.markdown import *
|
from aiogram.utils.markdown import *
|
||||||
|
|
||||||
API_TOKEN = 'BOT TOKEN HERE'
|
API_TOKEN = 'BOT TOKEN HERE'
|
||||||
|
|
@ -11,7 +15,7 @@ API_TOKEN = 'BOT TOKEN HERE'
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
bot = AIOGramBot(token=API_TOKEN, loop=loop)
|
bot = Bot(token=API_TOKEN, loop=loop)
|
||||||
dp = Dispatcher(bot)
|
dp = Dispatcher(bot)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from aiogram.bot import AIOGramBot
|
from aiogram import Bot
|
||||||
from aiogram.dispatcher import Dispatcher
|
from aiogram.dispatcher import Dispatcher
|
||||||
|
|
||||||
API_TOKEN = 'BOT TOKEN HERE'
|
API_TOKEN = 'BOT TOKEN HERE'
|
||||||
|
|
@ -9,7 +9,7 @@ API_TOKEN = 'BOT TOKEN HERE'
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
bot = AIOGramBot(token=API_TOKEN, loop=loop)
|
bot = Bot(token=API_TOKEN, loop=loop)
|
||||||
dp = Dispatcher(bot)
|
dp = Dispatcher(bot)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue