Убрал бардак из разных скобок. Изменил импорты в app.py
This commit is contained in:
parent
1bbe12e9c1
commit
3f4b06933a
12
app.py
12
app.py
|
@ -1,19 +1,13 @@
|
||||||
from aiogram import executor
|
from aiogram import executor
|
||||||
|
|
||||||
|
from loader import dp
|
||||||
|
import middlewares, filters, handlers
|
||||||
from utils.notify_admins import on_startup_notify
|
from utils.notify_admins import on_startup_notify
|
||||||
|
|
||||||
|
|
||||||
async def on_startup(dispatcher):
|
async def on_startup(dispatcher):
|
||||||
import filters
|
# Уведомляет про запуск
|
||||||
import middlewares
|
|
||||||
|
|
||||||
filters.setup(dispatcher)
|
|
||||||
middlewares.setup(dispatcher)
|
|
||||||
|
|
||||||
await on_startup_notify(dispatcher)
|
await on_startup_notify(dispatcher)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from handlers import dp
|
|
||||||
|
|
||||||
executor.start_polling(dp, on_startup=on_startup)
|
executor.start_polling(dp, on_startup=on_startup)
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
from aiogram import Dispatcher
|
from aiogram import Dispatcher
|
||||||
|
|
||||||
|
from loader import dp
|
||||||
# from .is_admin import AdminFilter
|
# from .is_admin import AdminFilter
|
||||||
|
|
||||||
|
|
||||||
def setup(dp: Dispatcher):
|
if __name__ == "filters":
|
||||||
# dp.filters_factory.bind(AdminFilter)
|
#dp.filters_factory.bind(is_admin)
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
import logging
|
import logging
|
||||||
|
from aiogram.utils.exceptions import (Unauthorized, InvalidQueryID, TelegramAPIError,
|
||||||
|
CantDemoteChatCreator, MessageNotModified, MessageToDeleteNotFound,
|
||||||
|
MessageTextIsEmpty, RetryAfter,
|
||||||
|
CantParseEntities, MessageCantBeDeleted)
|
||||||
|
|
||||||
|
|
||||||
from loader import dp
|
from loader import dp
|
||||||
|
|
||||||
|
@ -12,10 +17,6 @@ async def errors_handler(update, exception):
|
||||||
:param exception:
|
:param exception:
|
||||||
:return: stdout logging
|
:return: stdout logging
|
||||||
"""
|
"""
|
||||||
from aiogram.utils.exceptions import (Unauthorized, InvalidQueryID, TelegramAPIError,
|
|
||||||
CantDemoteChatCreator, MessageNotModified, MessageToDeleteNotFound,
|
|
||||||
MessageTextIsEmpty, RetryAfter,
|
|
||||||
CantParseEntities, MessageCantBeDeleted)
|
|
||||||
|
|
||||||
if isinstance(exception, CantDemoteChatCreator):
|
if isinstance(exception, CantDemoteChatCreator):
|
||||||
logging.debug("Can't demote chat creator")
|
logging.debug("Can't demote chat creator")
|
||||||
|
@ -53,4 +54,5 @@ async def errors_handler(update, exception):
|
||||||
if isinstance(exception, CantParseEntities):
|
if isinstance(exception, CantParseEntities):
|
||||||
logging.exception(f'CantParseEntities: {exception} \nUpdate: {update}')
|
logging.exception(f'CantParseEntities: {exception} \nUpdate: {update}')
|
||||||
return True
|
return True
|
||||||
|
|
||||||
logging.exception(f'Update: {update} \n{exception}')
|
logging.exception(f'Update: {update} \n{exception}')
|
||||||
|
|
|
@ -15,7 +15,7 @@ async def bot_echo(message: types.Message):
|
||||||
# Эхо хендлер, куда летят ВСЕ сообщения с указанным состоянием
|
# Эхо хендлер, куда летят ВСЕ сообщения с указанным состоянием
|
||||||
@dp.message_handler(state="*", content_types=types.ContentTypes.ANY)
|
@dp.message_handler(state="*", content_types=types.ContentTypes.ANY)
|
||||||
async def bot_echo_all(message: types.Message, state: FSMContext):
|
async def bot_echo_all(message: types.Message, state: FSMContext):
|
||||||
s = await state.get_state()
|
state = await state.get_state()
|
||||||
await message.answer(f"Эхо в состоянии <code>{s}</code>.\n"
|
await message.answer(f"Эхо в состоянии <code>{state}</code>.\n"
|
||||||
f"\nСодержание сообщения:\n"
|
f"\nСодержание сообщения:\n"
|
||||||
f"<code>{message}</code>")
|
f"<code>{message}</code>")
|
||||||
|
|
|
@ -6,9 +6,8 @@ from loader import dp
|
||||||
|
|
||||||
@dp.message_handler(CommandHelp())
|
@dp.message_handler(CommandHelp())
|
||||||
async def bot_help(message: types.Message):
|
async def bot_help(message: types.Message):
|
||||||
text = [
|
text = ("Список команд: ",
|
||||||
'Список команд: ',
|
"/start - Начать диалог",
|
||||||
'/start - Начать диалог',
|
"/help - Получить справку")
|
||||||
'/help - Получить справку'
|
|
||||||
]
|
await message.answer("\n".join(text))
|
||||||
await message.answer('\n'.join(text))
|
|
||||||
|
|
|
@ -6,4 +6,4 @@ from loader import dp
|
||||||
|
|
||||||
@dp.message_handler(CommandStart())
|
@dp.message_handler(CommandStart())
|
||||||
async def bot_start(message: types.Message):
|
async def bot_start(message: types.Message):
|
||||||
await message.answer(f'Привет, {message.from_user.full_name}!')
|
await message.answer(f"Привет, {message.from_user.full_name}!")
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
from aiogram import Dispatcher
|
from aiogram import Dispatcher
|
||||||
|
|
||||||
|
from loader import dp
|
||||||
from .throttling import ThrottlingMiddleware
|
from .throttling import ThrottlingMiddleware
|
||||||
|
|
||||||
|
|
||||||
def setup(dp: Dispatcher):
|
if __name__ == "a.middlewares":
|
||||||
dp.middleware.setup(ThrottlingMiddleware())
|
dp.middleware.setup(ThrottlingMiddleware())
|
||||||
|
|
|
@ -21,8 +21,8 @@ class ThrottlingMiddleware(BaseMiddleware):
|
||||||
handler = current_handler.get()
|
handler = current_handler.get()
|
||||||
dispatcher = Dispatcher.get_current()
|
dispatcher = Dispatcher.get_current()
|
||||||
if handler:
|
if handler:
|
||||||
limit = getattr(handler, 'throttling_rate_limit', self.rate_limit)
|
limit = getattr(handler, "throttling_rate_limit", self.rate_limit)
|
||||||
key = getattr(handler, 'throttling_key', f"{self.prefix}_{handler.__name__}")
|
key = getattr(handler, "throttling_key", f"{self.prefix}_{handler.__name__}")
|
||||||
else:
|
else:
|
||||||
limit = self.rate_limit
|
limit = self.rate_limit
|
||||||
key = f"{self.prefix}_message"
|
key = f"{self.prefix}_message"
|
||||||
|
@ -34,4 +34,4 @@ class ThrottlingMiddleware(BaseMiddleware):
|
||||||
|
|
||||||
async def message_throttled(self, message: types.Message, throttled: Throttled):
|
async def message_throttled(self, message: types.Message, throttled: Throttled):
|
||||||
if throttled.exceeded_count <= 2:
|
if throttled.exceeded_count <= 2:
|
||||||
await message.reply('Too many requests! ')
|
await message.reply("Too many requests!")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user