Обновление структуры
This commit is contained in:
parent
b1a872a060
commit
529b5aeb69
12
.gitignore
vendored
12
.gitignore
vendored
|
@ -127,14 +127,4 @@ dmypy.json
|
||||||
|
|
||||||
# Pyre type checker
|
# Pyre type checker
|
||||||
.pyre/
|
.pyre/
|
||||||
.idea/$CACHE_FILE$
|
.idea/
|
||||||
.idea/.gitignore
|
|
||||||
.idea/aiogram-bot-template.iml
|
|
||||||
.idea/codeStyles/
|
|
||||||
.idea/deployment.xml
|
|
||||||
.idea/dictionaries
|
|
||||||
.idea/inspectionProfiles/
|
|
||||||
.idea/misc.xml
|
|
||||||
.idea/modules.xml
|
|
||||||
.idea/vagrant.xml
|
|
||||||
.idea/vcs.xml
|
|
||||||
|
|
5
app.py
5
app.py
|
@ -1,4 +1,5 @@
|
||||||
from loader import bot, storage
|
from loader import bot, storage
|
||||||
|
from data.config import SKIP_UPDATES
|
||||||
|
|
||||||
|
|
||||||
async def on_startup(dp):
|
async def on_startup(dp):
|
||||||
|
@ -8,7 +9,9 @@ async def on_startup(dp):
|
||||||
middlewares.setup(dp)
|
middlewares.setup(dp)
|
||||||
|
|
||||||
from utils.notify_admins import on_startup_notify
|
from utils.notify_admins import on_startup_notify
|
||||||
|
from utils.set_bot_commands import set_default_commands
|
||||||
await on_startup_notify(dp)
|
await on_startup_notify(dp)
|
||||||
|
await set_default_commands(dp)
|
||||||
|
|
||||||
|
|
||||||
async def on_shutdown(dp):
|
async def on_shutdown(dp):
|
||||||
|
@ -20,4 +23,4 @@ if __name__ == '__main__':
|
||||||
from aiogram import executor
|
from aiogram import executor
|
||||||
from handlers import dp
|
from handlers import dp
|
||||||
|
|
||||||
executor.start_polling(dp, on_startup=on_startup, on_shutdown=on_shutdown)
|
executor.start_polling(dp, on_startup=on_startup, on_shutdown=on_shutdown, skip_updates=SKIP_UPDATES)
|
||||||
|
|
|
@ -1,20 +1,22 @@
|
||||||
import os
|
from environs import Env
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
env = Env()
|
||||||
|
env.read_env()
|
||||||
|
|
||||||
load_dotenv()
|
BOT_TOKEN = env("BOT_TOKEN")
|
||||||
|
|
||||||
BOT_TOKEN = str(os.getenv("BOT_TOKEN"))
|
SKIP_UPDATES = env.bool("SKIP_UPDATES", False)
|
||||||
admins = [
|
JOIN_NO_MEDIA_TIME = env.int("JOIN_NO_MEDIA_TIME", 10)
|
||||||
]
|
ADMINS_ID = env.list("ADMINS_ID")
|
||||||
|
|
||||||
ip = os.getenv("ip")
|
REDIS_HOST = env("REDIS_HOST", "127.0.0.1")
|
||||||
|
REDIS_PORT = env("REDIS_PORT", 6379)
|
||||||
|
|
||||||
aiogram_redis = {
|
aiogram_redis = {
|
||||||
'host': ip,
|
'host': REDIS_HOST,
|
||||||
}
|
}
|
||||||
|
|
||||||
redis = {
|
redis = {
|
||||||
'address': (ip, 6379),
|
'address': (REDIS_HOST, REDIS_PORT),
|
||||||
'encoding': 'utf8'
|
'encoding': 'utf8'
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
from aiogram import Dispatcher
|
from aiogram import Dispatcher
|
||||||
|
|
||||||
|
from .user_filters import IsContributor
|
||||||
# from .is_admin import AdminFilter
|
from .chat_filters import IsGroup, IsPrivate
|
||||||
|
|
||||||
|
|
||||||
def setup(dp: Dispatcher):
|
def setup(dp: Dispatcher):
|
||||||
# dp.filters_factory.bind(AdminFilter)
|
dp.filters_factory.bind(IsContributor)
|
||||||
pass
|
dp.filters_factory.bind(IsGroup)
|
||||||
|
dp.filters_factory.bind(IsPrivate)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from .errors import dp
|
# from .channels import dp
|
||||||
from .users import dp
|
from .essential import dp
|
||||||
from .groups import dp
|
# from .groups import dp
|
||||||
from .channels import dp
|
# from .private import dp
|
||||||
|
# from .users import dp
|
||||||
|
|
||||||
__all__ = ["dp"]
|
__all__ = ["dp"]
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
# __all__ = ["dp"]
|
|
@ -1,3 +0,0 @@
|
||||||
from .error_handler import dp
|
|
||||||
|
|
||||||
__all__ = ["dp"]
|
|
|
@ -1,56 +0,0 @@
|
||||||
import logging
|
|
||||||
|
|
||||||
from loader import dp
|
|
||||||
|
|
||||||
|
|
||||||
@dp.errors_handler()
|
|
||||||
async def errors_handler(update, exception):
|
|
||||||
"""
|
|
||||||
Exceptions handler. Catches all exceptions within task factory tasks.
|
|
||||||
:param dispatcher:
|
|
||||||
:param update:
|
|
||||||
:param exception:
|
|
||||||
:return: stdout logging
|
|
||||||
"""
|
|
||||||
from aiogram.utils.exceptions import (Unauthorized, InvalidQueryID, TelegramAPIError,
|
|
||||||
CantDemoteChatCreator, MessageNotModified, MessageToDeleteNotFound,
|
|
||||||
MessageTextIsEmpty, RetryAfter,
|
|
||||||
CantParseEntities, MessageCantBeDeleted)
|
|
||||||
|
|
||||||
if isinstance(exception, CantDemoteChatCreator):
|
|
||||||
logging.debug("Can't demote chat creator")
|
|
||||||
return True
|
|
||||||
|
|
||||||
if isinstance(exception, MessageNotModified):
|
|
||||||
logging.debug('Message is not modified')
|
|
||||||
return True
|
|
||||||
if isinstance(exception, MessageCantBeDeleted):
|
|
||||||
logging.debug('Message cant be deleted')
|
|
||||||
return True
|
|
||||||
|
|
||||||
if isinstance(exception, MessageToDeleteNotFound):
|
|
||||||
logging.debug('Message to delete not found')
|
|
||||||
return True
|
|
||||||
|
|
||||||
if isinstance(exception, MessageTextIsEmpty):
|
|
||||||
logging.debug('MessageTextIsEmpty')
|
|
||||||
return True
|
|
||||||
|
|
||||||
if isinstance(exception, Unauthorized):
|
|
||||||
logging.info(f'Unauthorized: {exception}')
|
|
||||||
return True
|
|
||||||
|
|
||||||
if isinstance(exception, InvalidQueryID):
|
|
||||||
logging.exception(f'InvalidQueryID: {exception} \nUpdate: {update}')
|
|
||||||
return True
|
|
||||||
|
|
||||||
if isinstance(exception, TelegramAPIError):
|
|
||||||
logging.exception(f'TelegramAPIError: {exception} \nUpdate: {update}')
|
|
||||||
return True
|
|
||||||
if isinstance(exception, RetryAfter):
|
|
||||||
logging.exception(f'RetryAfter: {exception} \nUpdate: {update}')
|
|
||||||
return True
|
|
||||||
if isinstance(exception, CantParseEntities):
|
|
||||||
logging.exception(f'CantParseEntities: {exception} \nUpdate: {update}')
|
|
||||||
return True
|
|
||||||
logging.exception(f'Update: {update} \n{exception}')
|
|
|
@ -0,0 +1 @@
|
||||||
|
# __all__ = ["dp"]
|
|
@ -1,5 +0,0 @@
|
||||||
from .help import dp
|
|
||||||
from .start import dp
|
|
||||||
from .echo import dp
|
|
||||||
|
|
||||||
__all__ = ["dp"]
|
|
|
@ -1,7 +0,0 @@
|
||||||
from aiogram import types
|
|
||||||
from loader import dp
|
|
||||||
|
|
||||||
|
|
||||||
@dp.message_handler()
|
|
||||||
async def bot_echo(message: types.Message):
|
|
||||||
await message.answer(message.text)
|
|
|
@ -1,16 +0,0 @@
|
||||||
from aiogram import types
|
|
||||||
from aiogram.dispatcher.filters.builtin import CommandHelp
|
|
||||||
|
|
||||||
from loader import dp
|
|
||||||
from utils.misc import rate_limit
|
|
||||||
|
|
||||||
|
|
||||||
@rate_limit(5, 'help')
|
|
||||||
@dp.message_handler(CommandHelp())
|
|
||||||
async def bot_help(message: types.Message):
|
|
||||||
text = [
|
|
||||||
'Список команд: ',
|
|
||||||
'/start - Начать диалог',
|
|
||||||
'/help - Получить справку'
|
|
||||||
]
|
|
||||||
await message.answer('\n'.join(text))
|
|
|
@ -1,9 +0,0 @@
|
||||||
from aiogram import types
|
|
||||||
from aiogram.dispatcher.filters.builtin import CommandStart
|
|
||||||
|
|
||||||
from loader import dp
|
|
||||||
|
|
||||||
|
|
||||||
@dp.message_handler(CommandStart())
|
|
||||||
async def bot_start(message: types.Message):
|
|
||||||
await message.answer(f'Привет, {message.from_user.full_name}!')
|
|
|
@ -1,3 +1,44 @@
|
||||||
aiogram==2.7
|
|
||||||
|
# Autocreated by
|
||||||
|
# pip freeze > requirements.txt
|
||||||
|
|
||||||
|
aiogram==2.8
|
||||||
aiohttp==3.6.2
|
aiohttp==3.6.2
|
||||||
aioredis==1.3.1
|
aioredis==1.3.1
|
||||||
|
appdirs==1.4.3
|
||||||
|
APScheduler==3.6.3
|
||||||
|
async-timeout==3.0.1
|
||||||
|
asyncio==3.4.3
|
||||||
|
attrs==19.3.0
|
||||||
|
Babel==2.8.0
|
||||||
|
CacheControl==0.12.6
|
||||||
|
certifi==2020.4.5.1
|
||||||
|
chardet==3.0.4
|
||||||
|
colorama==0.4.3
|
||||||
|
contextlib2==0.6.0
|
||||||
|
distlib==0.3.0
|
||||||
|
distro==1.4.0
|
||||||
|
environs==7.4.0
|
||||||
|
hiredis==1.0.1
|
||||||
|
html5lib==1.0.1
|
||||||
|
idna==2.9
|
||||||
|
ipaddr==2.2.0
|
||||||
|
lockfile==0.12.2
|
||||||
|
loguru==0.4.1
|
||||||
|
marshmallow==3.6.0
|
||||||
|
msgpack==0.6.2
|
||||||
|
multidict==4.7.5
|
||||||
|
packaging==20.3
|
||||||
|
pep517==0.8.2
|
||||||
|
progress==1.5
|
||||||
|
pyparsing==2.4.6
|
||||||
|
pytoml==0.1.21
|
||||||
|
pytz==2020.1
|
||||||
|
redis==3.5.1
|
||||||
|
requests==2.22.0
|
||||||
|
retrying==1.3.3
|
||||||
|
six==1.14.0
|
||||||
|
tzlocal==2.1
|
||||||
|
urllib3==1.25.8
|
||||||
|
webencodings==0.5.1
|
||||||
|
yarl==1.4.2
|
||||||
|
|
|
@ -1,2 +1 @@
|
||||||
from .throttling import rate_limit
|
from .throttling import rate_limit
|
||||||
from . import logging
|
|
||||||
|
|
|
@ -1,14 +1,20 @@
|
||||||
import logging
|
from loguru import logger
|
||||||
|
|
||||||
from aiogram import Dispatcher
|
from aiogram import Dispatcher
|
||||||
|
from aiogram.utils.exceptions import ChatNotFound
|
||||||
|
|
||||||
from data.config import admins
|
from data.config import ADMINS_ID
|
||||||
|
|
||||||
|
|
||||||
|
async def mail_to_admins(dp):
|
||||||
|
for admin in ADMINS_ID:
|
||||||
|
try:
|
||||||
|
await dp.bot.send_message(admin, "Бот Запущен и готов к работе с группами!")
|
||||||
|
except ChatNotFound:
|
||||||
|
logger.error("Чат с админом не найден")
|
||||||
|
except Exception as err:
|
||||||
|
logger.exception(err)
|
||||||
|
|
||||||
|
|
||||||
async def on_startup_notify(dp: Dispatcher):
|
async def on_startup_notify(dp: Dispatcher):
|
||||||
for admin in admins:
|
await mail_to_admins(dp)
|
||||||
try:
|
|
||||||
await dp.bot.send_message(admin, "Бот Запущен")
|
|
||||||
|
|
||||||
except Exception as err:
|
|
||||||
logging.exception(err)
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user